mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Move terms lock from Core::App to Session.
This commit is contained in:
@@ -16,9 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/window_lock_widgets.h"
|
||||
#include "window/window_outdated_bar.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "main/main_account.h" // Account::sessionValue.
|
||||
#include "core/click_handler_types.h"
|
||||
#include "core/application.h"
|
||||
#include "core/sandbox.h"
|
||||
#include "lang/lang_keys.h"
|
||||
@@ -34,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "facades.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
#include <QtCore/QMimeData>
|
||||
@@ -144,11 +141,6 @@ MainWindow::MainWindow(not_null<Controller*> controller)
|
||||
workmodeUpdated(mode);
|
||||
});
|
||||
|
||||
Core::App().termsLockValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
checkLockByTerms();
|
||||
}, lifetime());
|
||||
|
||||
Ui::Toast::SetDefaultParent(_body.data());
|
||||
|
||||
if (_outdated) {
|
||||
@@ -172,92 +164,6 @@ Window::SessionController *MainWindow::sessionController() const {
|
||||
return _controller->sessionController();
|
||||
}
|
||||
|
||||
void MainWindow::checkLockByTerms() {
|
||||
const auto data = Core::App().termsLocked();
|
||||
if (!data || !account().sessionExists()) {
|
||||
if (_termsBox) {
|
||||
_termsBox->closeBox();
|
||||
}
|
||||
return;
|
||||
}
|
||||
Ui::hideSettingsAndLayer(anim::type::instant);
|
||||
const auto box = Ui::show(Box<TermsBox>(
|
||||
*data,
|
||||
tr::lng_terms_agree(),
|
||||
tr::lng_terms_decline()));
|
||||
|
||||
box->setCloseByEscape(false);
|
||||
box->setCloseByOutsideClick(false);
|
||||
|
||||
const auto id = data->id;
|
||||
box->agreeClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto mention = box ? box->lastClickedMention() : QString();
|
||||
if (const auto session = account().maybeSession()) {
|
||||
session->api().acceptTerms(id);
|
||||
if (!mention.isEmpty()) {
|
||||
MentionClickHandler(mention).onClick({});
|
||||
}
|
||||
}
|
||||
Core::App().unlockTerms();
|
||||
}, box->lifetime());
|
||||
|
||||
box->cancelClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
showTermsDecline();
|
||||
}, box->lifetime());
|
||||
|
||||
connect(box, &QObject::destroyed, [=] {
|
||||
crl::on_main(this, [=] { checkLockByTerms(); });
|
||||
});
|
||||
|
||||
_termsBox = box;
|
||||
}
|
||||
|
||||
void MainWindow::showTermsDecline() {
|
||||
const auto box = Ui::show(
|
||||
Box<Window::TermsBox>(
|
||||
TextWithEntities{ tr::lng_terms_update_sorry(tr::now) },
|
||||
tr::lng_terms_decline_and_delete(),
|
||||
tr::lng_terms_back(),
|
||||
true),
|
||||
Ui::LayerOption::KeepOther);
|
||||
|
||||
box->agreeClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (box) {
|
||||
box->closeBox();
|
||||
}
|
||||
showTermsDelete();
|
||||
}, box->lifetime());
|
||||
|
||||
box->cancelClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (box) {
|
||||
box->closeBox();
|
||||
}
|
||||
}, box->lifetime());
|
||||
}
|
||||
|
||||
void MainWindow::showTermsDelete() {
|
||||
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||
const auto deleteByTerms = [=] {
|
||||
if (const auto session = account().maybeSession()) {
|
||||
session->termsDeleteNow();
|
||||
} else {
|
||||
Ui::hideLayer();
|
||||
}
|
||||
};
|
||||
*box = Ui::show(
|
||||
Box<ConfirmBox>(
|
||||
tr::lng_terms_delete_warning(tr::now),
|
||||
tr::lng_terms_delete_now(tr::now),
|
||||
st::attentionBoxButton,
|
||||
deleteByTerms,
|
||||
[=] { if (*box) (*box)->closeBox(); }),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
bool MainWindow::hideNoQuit() {
|
||||
if (App::quitting()) {
|
||||
return false;
|
||||
|
@@ -177,9 +177,6 @@ private:
|
||||
void initSize();
|
||||
|
||||
bool computeIsActive() const;
|
||||
void checkLockByTerms();
|
||||
void showTermsDecline();
|
||||
void showTermsDelete();
|
||||
|
||||
not_null<Window::Controller*> _controller;
|
||||
|
||||
@@ -190,7 +187,6 @@ private:
|
||||
object_ptr<Ui::RpWidget> _outdated;
|
||||
object_ptr<Ui::RpWidget> _body;
|
||||
object_ptr<TWidget> _rightColumn = { nullptr };
|
||||
QPointer<Ui::BoxContent> _termsBox;
|
||||
|
||||
QIcon _icon;
|
||||
bool _usingSupportIcon = false;
|
||||
|
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/window_controller.h"
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
@@ -23,9 +24,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/window_session_controller.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "window/themes/window_theme_editor.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "mainwindow.h"
|
||||
#include "apiwrap.h" // ApiWrap::acceptTerms.
|
||||
#include "facades.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtGui/QScreen>
|
||||
@@ -67,20 +71,124 @@ void Controller::showAccount(not_null<Main::Account*> account) {
|
||||
sideBarChanged();
|
||||
}
|
||||
_widget.updateWindowIcon();
|
||||
_widget.updateGlobalMenu();
|
||||
if (session) {
|
||||
setupMain();
|
||||
|
||||
session->termsLockValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
checkLockByTerms();
|
||||
_widget.updateGlobalMenu();
|
||||
}, _lifetime);
|
||||
} else {
|
||||
setupIntro();
|
||||
_widget.updateGlobalMenu();
|
||||
}
|
||||
}, _accountLifetime);
|
||||
}
|
||||
|
||||
void Controller::checkLockByTerms() {
|
||||
const auto data = account().sessionExists()
|
||||
? account().session().termsLocked()
|
||||
: std::nullopt;
|
||||
if (!data) {
|
||||
if (_termsBox) {
|
||||
_termsBox->closeBox();
|
||||
}
|
||||
return;
|
||||
}
|
||||
Ui::hideSettingsAndLayer(anim::type::instant);
|
||||
const auto box = Ui::show(Box<TermsBox>(
|
||||
*data,
|
||||
tr::lng_terms_agree(),
|
||||
tr::lng_terms_decline()));
|
||||
|
||||
box->setCloseByEscape(false);
|
||||
box->setCloseByOutsideClick(false);
|
||||
|
||||
const auto id = data->id;
|
||||
box->agreeClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto mention = box ? box->lastClickedMention() : QString();
|
||||
box->closeBox();
|
||||
if (const auto session = account().maybeSession()) {
|
||||
session->api().acceptTerms(id);
|
||||
session->unlockTerms();
|
||||
if (!mention.isEmpty()) {
|
||||
MentionClickHandler(mention).onClick({});
|
||||
}
|
||||
}
|
||||
}, box->lifetime());
|
||||
|
||||
box->cancelClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
showTermsDecline();
|
||||
}, box->lifetime());
|
||||
|
||||
QObject::connect(box, &QObject::destroyed, [=] {
|
||||
crl::on_main(widget(), [=] { checkLockByTerms(); });
|
||||
});
|
||||
|
||||
_termsBox = box;
|
||||
}
|
||||
|
||||
void Controller::showTermsDecline() {
|
||||
const auto box = Ui::show(
|
||||
Box<Window::TermsBox>(
|
||||
TextWithEntities{ tr::lng_terms_update_sorry(tr::now) },
|
||||
tr::lng_terms_decline_and_delete(),
|
||||
tr::lng_terms_back(),
|
||||
true),
|
||||
Ui::LayerOption::KeepOther);
|
||||
|
||||
box->agreeClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (box) {
|
||||
box->closeBox();
|
||||
}
|
||||
showTermsDelete();
|
||||
}, box->lifetime());
|
||||
|
||||
box->cancelClicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (box) {
|
||||
box->closeBox();
|
||||
}
|
||||
}, box->lifetime());
|
||||
}
|
||||
|
||||
void Controller::showTermsDelete() {
|
||||
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||
const auto deleteByTerms = [=] {
|
||||
if (const auto session = account().maybeSession()) {
|
||||
session->termsDeleteNow();
|
||||
} else {
|
||||
Ui::hideLayer();
|
||||
}
|
||||
};
|
||||
*box = Ui::show(
|
||||
Box<ConfirmBox>(
|
||||
tr::lng_terms_delete_warning(tr::now),
|
||||
tr::lng_terms_delete_now(tr::now),
|
||||
st::attentionBoxButton,
|
||||
deleteByTerms,
|
||||
[=] { if (*box) (*box)->closeBox(); }),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void Controller::finishFirstShow() {
|
||||
_widget.finishFirstShow();
|
||||
checkThemeEditor();
|
||||
}
|
||||
|
||||
bool Controller::locked() const {
|
||||
if (Core::App().passcodeLocked()) {
|
||||
return true;
|
||||
} else if (const auto controller = sessionController()) {
|
||||
return controller->session().termsLocked().has_value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controller::checkThemeEditor() {
|
||||
using namespace Window::Theme;
|
||||
|
||||
|
@@ -26,17 +26,18 @@ public:
|
||||
|
||||
void showAccount(not_null<Main::Account*> account);
|
||||
|
||||
not_null<::MainWindow*> widget() {
|
||||
[[nodiscard]] not_null<::MainWindow*> widget() {
|
||||
return &_widget;
|
||||
}
|
||||
Main::Account &account() const {
|
||||
[[nodiscard]] Main::Account &account() const {
|
||||
Expects(_account != nullptr);
|
||||
|
||||
return *_account;
|
||||
}
|
||||
SessionController *sessionController() const {
|
||||
[[nodiscard]] SessionController *sessionController() const {
|
||||
return _sessionController.get();
|
||||
}
|
||||
[[nodiscard]] bool locked() const;
|
||||
|
||||
void finishFirstShow();
|
||||
|
||||
@@ -77,11 +78,15 @@ private:
|
||||
Ui::LayerOptions options,
|
||||
anim::type animated);
|
||||
void checkThemeEditor();
|
||||
void checkLockByTerms();
|
||||
void showTermsDecline();
|
||||
void showTermsDelete();
|
||||
|
||||
Main::Account *_account = nullptr;
|
||||
::MainWindow _widget;
|
||||
std::unique_ptr<SessionController> _sessionController;
|
||||
base::Timer _isActiveTimer;
|
||||
QPointer<Ui::BoxContent> _termsBox;
|
||||
|
||||
rpl::lifetime _accountLifetime;
|
||||
rpl::lifetime _lifetime;
|
||||
|
Reference in New Issue
Block a user