diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index f4a2efc60..8f308319b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -420,7 +420,7 @@ void ApiWrap::requestTermsUpdate() { const auto &data = result.c_help_termsOfServiceUpdate(); const auto &terms = data.vterms_of_service(); const auto &fields = terms.c_help_termsOfService(); - Core::App().lockByTerms( + session().lockByTerms( Window::TermsLock::FromMTP(_session, fields)); requestNext(data); } break; diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 0e9e81a04..cd129d88d 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -153,8 +153,6 @@ Application::~Application() { _mediaView->clearData(); _mediaView = nullptr; } - - unlockTerms(); _domain->finish(); Local::finish(); @@ -268,7 +266,7 @@ void Application::run() { DEBUG_LOG(("Application Info: showing.")); _window->finishFirstShow(); - if (!locked() && cStartToSettings()) { + if (!_window->locked() && cStartToSettings()) { _window->showSettings(); } @@ -657,7 +655,7 @@ bool Application::canApplyLangPackWithoutRestart() const { } void Application::checkStartUrl() { - if (!cStartUrl().isEmpty() && !locked()) { + if (!cStartUrl().isEmpty() && _window && !_window->locked()) { const auto url = cStartUrl(); cSetStartUrl(QString()); if (!openLocalUrl(url, {})) { @@ -680,18 +678,19 @@ bool Application::openCustomUrl( const QString &url, const QVariant &context) { const auto urlTrimmed = url.trimmed(); - if (!urlTrimmed.startsWith(protocol, Qt::CaseInsensitive) || locked()) { + if (!urlTrimmed.startsWith(protocol, Qt::CaseInsensitive) + || passcodeLocked()) { return false; } const auto command = urlTrimmed.midRef(protocol.size(), 8192); - const auto session = maybeActiveSession(); + const auto controller = _window ? _window->sessionController() : nullptr; using namespace qthelp; const auto options = RegExOption::CaseInsensitive; for (const auto &[expression, handler] : handlers) { const auto match = regex_match(expression, command, options); if (match) { - return handler(session, match, context); + return handler(controller, match, context); } } return false; @@ -740,13 +739,6 @@ rpl::producer Application::passcodeLockValue() const { return _passcodeLock.value(); } -void Application::lockByTerms(const Window::TermsLock &data) { - if (!_termsLock || *_termsLock != data) { - _termsLock = std::make_unique(data); - _termsLockChanges.fire(true); - } -} - bool Application::someSessionExists() const { for (const auto &[index, account] : _domain->accounts()) { if (account->sessionExists()) { @@ -793,43 +785,6 @@ void Application::localPasscodeChanged() { checkAutoLock(); } -void Application::unlockTerms() { - if (_termsLock) { - _termsLock = nullptr; - _termsLockChanges.fire(false); - } -} - -std::optional Application::termsLocked() const { - return _termsLock ? base::make_optional(*_termsLock) : std::nullopt; -} - -rpl::producer Application::termsLockChanges() const { - return _termsLockChanges.events(); -} - -rpl::producer Application::termsLockValue() const { - return rpl::single( - _termsLock != nullptr - ) | rpl::then(termsLockChanges()); -} - -bool Application::locked() const { - return passcodeLocked() || termsLocked(); -} - -rpl::producer Application::lockChanges() const { - return lockValue() | rpl::skip(1); -} - -rpl::producer Application::lockValue() const { - using namespace rpl::mappers; - return rpl::combine( - passcodeLockValue(), - termsLockValue(), - _1 || _2); -} - bool Application::hasActiveWindow(not_null session) const { if (App::quitting() || !_window) { return false; @@ -889,7 +844,7 @@ void Application::notifyFileDialogShown(bool shown) { QWidget *Application::getModalParent() { return (Platform::IsWayland() && activeWindow()) - ? activeWindow()->widget() + ? activeWindow()->widget().get() : nullptr; } diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 71896d9a3..f352b1a48 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -23,7 +23,6 @@ class Databases; } // namespace Storage namespace Window { -struct TermsLock; class Controller; } // namespace Window @@ -223,16 +222,6 @@ public: rpl::producer passcodeLockChanges() const; rpl::producer passcodeLockValue() const; - void lockByTerms(const Window::TermsLock &data); - void unlockTerms(); - [[nodiscard]] std::optional termsLocked() const; - rpl::producer termsLockChanges() const; - rpl::producer termsLockValue() const; - - [[nodiscard]] bool locked() const; - rpl::producer lockChanges() const; - rpl::producer lockValue() const; - void checkAutoLock(); void checkAutoLockIn(crl::time time); void localPasscodeChanged(); @@ -331,8 +320,6 @@ private: const QImage _logoNoMargin; rpl::variable _passcodeLock; - rpl::event_stream _termsLockChanges; - std::unique_ptr _termsLock; crl::time _shouldLockAt = 0; base::Timer _autoLockTimer; diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 2b5e5c494..e1d2f4ac0 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -30,8 +30,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "media/player/media_player_instance.h" #include "window/window_session_controller.h" +#include "window/window_controller.h" #include "settings/settings_common.h" -#include "mainwindow.h" #include "mainwidget.h" #include "main/main_session.h" #include "main/main_session_settings.h" @@ -44,13 +44,15 @@ namespace { using Match = qthelp::RegularExpressionMatch; bool JoinGroupByHash( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto hash = match->captured(1); + const auto session = &controller->session(); + const auto weak = base::make_weak(controller); session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) { Core::App().hideMediaView(); result.match([=](const MTPDchatInvite &data) { @@ -59,11 +61,10 @@ bool JoinGroupByHash( })); }, [=](const MTPDchatInviteAlready &data) { if (const auto chat = session->data().processChat(data.vchat())) { - for (const auto controller : session->windows()) { - controller->showPeerHistory( + if (const auto strong = weak.get()) { + strong->showPeerHistory( chat, Window::SectionShow::Way::Forward); - break; } } }); @@ -78,10 +79,10 @@ bool JoinGroupByHash( } bool ShowStickerSet( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } Core::App().hideMediaView(); @@ -92,15 +93,15 @@ bool ShowStickerSet( } bool ShowTheme( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto clickFromMessageId = context.value(); Core::App().hideMediaView(); - session->data().cloudThemes().resolve( + controller->session().data().cloudThemes().resolve( match->captured(1), clickFromMessageId); return true; @@ -112,7 +113,7 @@ void ShowLanguagesBox() { } bool SetLanguage( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { if (match->capturedRef(1).isEmpty()) { @@ -125,10 +126,10 @@ bool SetLanguage( } bool ShareUrl( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } auto params = url_parse_params( @@ -145,10 +146,10 @@ bool ShareUrl( } bool ConfirmPhone( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } auto params = url_parse_params( @@ -159,26 +160,26 @@ bool ConfirmPhone( if (phone.isEmpty() || hash.isEmpty()) { return false; } - ConfirmPhoneBox::Start(session, phone, hash); + ConfirmPhoneBox::Start(&controller->session(), phone, hash); return true; } bool ShareGameScore( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto params = url_parse_params( match->captured(1), qthelp::UrlParamNameTransform::ToLower); - ShareGameScoreByHash(session, params.value(qsl("hash"))); + ShareGameScoreByHash(&controller->session(), params.value(qsl("hash"))); return true; } bool ApplySocksProxy( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { auto params = url_parse_params( @@ -191,7 +192,7 @@ bool ApplySocksProxy( } bool ApplyMtprotoProxy( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { auto params = url_parse_params( @@ -228,7 +229,7 @@ bool ShowPassportForm(const QMap ¶ms) { } bool ShowPassport( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { return ShowPassportForm(url_parse_params( @@ -237,10 +238,10 @@ bool ShowPassport( } bool ShowWallPaper( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto params = url_parse_params( @@ -253,10 +254,10 @@ bool ShowWallPaper( } bool ResolveUsername( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto params = url_parse_params( @@ -309,10 +310,10 @@ bool ResolveUsername( } bool ResolvePrivatePost( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto params = url_parse_params( @@ -332,6 +333,7 @@ bool ResolvePrivatePost( const auto fail = [=] { Ui::show(Box(tr::lng_error_post_link_invalid(tr::now))); }; + const auto session = &controller->session(); if (const auto channel = session->data().channelLoaded(channelId)) { done(channel); return true; @@ -356,19 +358,19 @@ bool ResolvePrivatePost( } bool ResolveSettings( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { const auto section = match->captured(1).mid(1).toLower(); - if (!session) { + if (!controller) { if (section.isEmpty()) { - App::wnd()->showSettings(); + controller->window().showSettings(); return true; } return false; } if (section == qstr("devices")) { - Ui::show(Box(session)); + Ui::show(Box(&controller->session())); return true; } else if (section == qstr("language")) { ShowLanguagesBox(); @@ -382,10 +384,10 @@ bool ResolveSettings( } bool HandleUnknown( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto request = match->captured(1); @@ -393,7 +395,7 @@ bool HandleUnknown( const auto text = TextWithEntities{ qs(result.vmessage()), Api::EntitiesFromMTP( - session, + &controller->session(), result.ventities().value_or_empty()) }; if (result.is_update_app()) { @@ -410,15 +412,15 @@ bool HandleUnknown( Ui::show(Box(text)); } }; - session->api().requestDeepLinkInfo(request, callback); + controller->session().api().requestDeepLinkInfo(request, callback); return true; } bool OpenMediaTimestamp( - Main::Session *session, + Window::SessionController *controller, const Match &match, const QVariant &context) { - if (!session) { + if (!controller) { return false; } const auto time = match->captured(2).toInt(); @@ -432,6 +434,7 @@ bool OpenMediaTimestamp( const auto itemId = FullMsgId( parts.value(1).toInt(), parts.value(2).toInt()); + const auto session = &controller->session(); const auto document = session->data().document(documentId); session->settings().setMediaLastPlaybackPosition( documentId, @@ -607,7 +610,7 @@ bool InternalPassportLink(const QString &url) { } bool StartUrlRequiresActivate(const QString &url) { - return Core::App().locked() + return Core::App().passcodeLocked() ? true : !InternalPassportLink(url); } diff --git a/Telegram/SourceFiles/core/local_url_handlers.h b/Telegram/SourceFiles/core/local_url_handlers.h index 98e1893c9..9a5cc6a55 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.h +++ b/Telegram/SourceFiles/core/local_url_handlers.h @@ -11,16 +11,16 @@ namespace qthelp { class RegularExpressionMatch; } // namespace qthelp -namespace Main { -class Session; -} // namespace Main +namespace Window { +class SessionController; +} // namespace Window namespace Core { struct LocalUrlHandler { QString expression; Fn handler; }; diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index c148b286a..5f05926e8 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -153,10 +153,7 @@ bool UiIntegration::handleUrlClick( } rpl::producer<> UiIntegration::forcePopupMenuHideRequests() { - return rpl::merge( - Core::App().passcodeLockChanges(), - Core::App().termsLockChanges() - ) | rpl::to_empty; + return Core::App().passcodeLockChanges() | rpl::to_empty; } QString UiIntegration::convertTagToMimeTag(const QString &tagId) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 925d08a9c..11dc83b5b 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6464,7 +6464,7 @@ void HistoryWidget::updateTopBarSelection() { _topBar->showSelected(selectedState); updateControlsVisibility(); updateHistoryGeometry(); - if (!Ui::isLayerShown() && !Core::App().locked()) { + if (!Ui::isLayerShown() && !Core::App().passcodeLocked()) { if (_nonEmptySelection || (_list && _list->wasSelectedText()) || _recording diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index c125f3e68..988fa8cfa 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -503,7 +503,6 @@ void Account::loggedOut() { _loggingOut = false; Media::Player::mixer()->stopAndClear(); destroySession(); - Core::App().unlockTerms(); local().reset(); cSetOtherOnline(0); } diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 7e3e0cf17..0ec2f632e 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_changes.h" #include "data/data_user.h" #include "window/window_session_controller.h" +#include "window/window_lock_widgets.h" #include "window/themes/window_theme.h" //#include "platform/platform_specific.h" #include "calls/calls_instance.h" @@ -138,6 +139,7 @@ Session::Session( } Session::~Session() { + unlockTerms(); data().clear(); ClickHandler::clearActive(); ClickHandler::unpressed(); @@ -210,12 +212,40 @@ const MTP::ConfigFields &Session::serverConfig() const { return _account->mtp().configValues(); } +void Session::lockByTerms(const Window::TermsLock &data) { + if (!_termsLock || *_termsLock != data) { + _termsLock = std::make_unique(data); + _termsLockChanges.fire(true); + } +} + +void Session::unlockTerms() { + if (_termsLock) { + _termsLock = nullptr; + _termsLockChanges.fire(false); + } +} + void Session::termsDeleteNow() { api().request(MTPaccount_DeleteAccount( MTP_string("Decline ToS update") )).send(); } +std::optional Session::termsLocked() const { + return _termsLock ? base::make_optional(*_termsLock) : std::nullopt; +} + +rpl::producer Session::termsLockChanges() const { + return _termsLockChanges.events(); +} + +rpl::producer Session::termsLockValue() const { + return rpl::single( + _termsLock != nullptr + ) | rpl::then(termsLockChanges()); +} + QString Session::createInternalLink(const QString &query) const { auto result = createInternalLinkFull(query); auto prefixes = { diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index 9039dbf27..f1edc4e07 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -44,6 +44,7 @@ class Domain; namespace Window { class SessionController; +struct TermsLock; } // namespace Window namespace Calls { @@ -135,7 +136,13 @@ public: return *_calls; } + // Terms lock. + void lockByTerms(const Window::TermsLock &data); + void unlockTerms(); void termsDeleteNow(); + [[nodiscard]] std::optional termsLocked() const; + rpl::producer termsLockChanges() const; + rpl::producer termsLockValue() const; [[nodiscard]] QString createInternalLink(const QString &query) const; [[nodiscard]] QString createInternalLinkFull(const QString &query) const; @@ -177,6 +184,9 @@ private: std::shared_ptr _selfUserpicView; + rpl::event_stream _termsLockChanges; + std::unique_ptr _termsLock; + base::flat_set> _windows; base::Timer _saveSettingsTimer; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 9a8e796a2..b6881ca6b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -44,6 +44,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/section_memento.h" #include "window/section_widget.h" #include "window/window_connecting_widget.h" +#include "window/window_top_bar_wrap.h" +#include "window/notifications_manager.h" +#include "window/window_slide_animation.h" +#include "window/window_session_controller.h" +#include "window/window_history_hider.h" +#include "window/window_controller.h" +#include "window/themes/window_theme.h" #include "chat_helpers/tabbed_selector.h" // TabbedSelector::refreshStickers #include "chat_helpers/message_field.h" #include "info/info_memento.h" @@ -79,12 +86,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_regex.h" #include "base/qthelp_url.h" #include "base/flat_set.h" -#include "window/window_top_bar_wrap.h" -#include "window/notifications_manager.h" -#include "window/window_slide_animation.h" -#include "window/window_session_controller.h" -#include "window/themes/window_theme.h" -#include "window/window_history_hider.h" #include "mtproto/mtproto_dc_options.h" #include "core/file_utilities.h" #include "core/update_checker.h" @@ -649,7 +650,7 @@ void MainWidget::clearHider(not_null instance) { } void MainWidget::hiderLayer(base::unique_qptr hider) { - if (Core::App().locked()) { + if (controller()->window().locked()) { return; } @@ -1425,7 +1426,7 @@ void MainWidget::ui_showPeerHistory( auto animatedShow = [&] { if (_a_show.animating() - || Core::App().locked() + || Core::App().passcodeLocked() || (params.animated == anim::type::instant)) { return false; } @@ -1720,7 +1721,7 @@ void MainWidget::showNewSection( auto animatedShow = [&] { if (_a_show.animating() - || Core::App().locked() + || Core::App().passcodeLocked() || (params.animated == anim::type::instant) || memento.instant()) { return false; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index f0a5feec2..2f046daff 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -97,7 +97,7 @@ MainWindow::MainWindow(not_null controller) subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { themeUpdated(data); }); - Core::App().lockChanges( + Core::App().passcodeLockChanges( ) | rpl::start_with_next([=] { updateGlobalMenu(); }, lifetime()); @@ -766,7 +766,7 @@ bool MainWindow::skipTrayClick() const { } void MainWindow::toggleDisplayNotifyFromTray() { - if (Core::App().locked()) { + if (controller().locked()) { if (!isActive()) showFromTray(); Ui::show(Box(tr::lng_passcode_need_unblock(tr::now))); return; @@ -973,7 +973,7 @@ QImage MainWindow::iconWithCounter(int size, int count, style::color bg, style:: } void MainWindow::sendPaths() { - if (Core::App().locked()) { + if (controller().locked()) { return; } Core::App().hideMediaView(); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index fc5b3f140..de3344fe2 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/about_box.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" +#include "window/window_controller.h" #include "window/window_session_controller.h" #include "ui/widgets/input_fields.h" #include "facades.h" @@ -1027,10 +1028,9 @@ void MainWindow::updateGlobalMenuHook() { } App::wnd()->updateIsActive(); const auto logged = account().sessionExists(); - const auto locked = Core::App().locked(); - const auto inactive = !logged || locked; + const auto inactive = !logged || controller().locked(); const auto support = logged && account().session().supportMode(); - ForceDisabled(psLogout, !logged && !locked); + ForceDisabled(psLogout, !logged && !Core::App().passcodeLocked()); ForceDisabled(psUndo, !canUndo); ForceDisabled(psRedo, !canRedo); ForceDisabled(psCut, !canCut); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 311d8d3df..186ed848c 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "window/notifications_manager_default.h" #include "window/window_session_controller.h" +#include "window/window_controller.h" #include "window/themes/window_theme.h" #include "platform/mac/mac_touchbar.h" #include "platform/platform_notifications_manager.h" @@ -835,10 +836,9 @@ void MainWindow::updateGlobalMenuHook() { } App::wnd()->updateIsActive(); const auto logged = account().sessionExists(); - const auto locked = Core::App().locked(); - const auto inactive = !logged || locked; + const auto inactive = !logged || controller().locked(); const auto support = logged && account().session().supportMode(); - ForceDisabled(psLogout, !logged && !locked); + ForceDisabled(psLogout, !logged && !Core::App().passcodeLocked()); ForceDisabled(psUndo, !canUndo); ForceDisabled(psRedo, !canRedo); ForceDisabled(psCut, !canCut); diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index dda0d5999..eea48db35 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -121,42 +121,6 @@ auto GenerateCodes() { } }); - codes.emplace(qsl("accadd"), [](SessionController *window) { - crl::on_main(&Core::App(), [=] { - if (window - && !Core::App().locked() - && Core::App().domain().started() - && Core::App().domain().accounts().size() < 3) { - Core::App().domain().activate( - Core::App().domain().add(MTP::Environment::Production)); - } - }); - }); - - codes.emplace(qsl("acctest"), [](SessionController *window) { - crl::on_main(&Core::App(), [=] { - if (window - && !Core::App().locked() - && Core::App().domain().started() - && Core::App().domain().accounts().size() < 3) { - Core::App().domain().activate( - Core::App().domain().add(MTP::Environment::Test)); - } - }); - }); - - for (auto i = 0; i != 3; ++i) { - codes.emplace(qsl("account%1").arg(i + 1), [=]( - SessionController *window) { - crl::on_main(&Core::App(), [=] { - const auto &list = Core::App().domain().accounts(); - if (i < list.size()) { - Core::App().domain().activate(list[i].account.get()); - } - }); - }); - } - #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME codes.emplace(qsl("registertg"), [](SessionController *window) { Platform::RegisterCustomScheme(true); diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index e27c69b71..7249f8f77 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -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 #include @@ -144,11 +141,6 @@ MainWindow::MainWindow(not_null 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( - *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( - 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>(); - const auto deleteByTerms = [=] { - if (const auto session = account().maybeSession()) { - session->termsDeleteNow(); - } else { - Ui::hideLayer(); - } - }; - *box = Ui::show( - Box( - 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; diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index ad95a91a3..52f5d5865 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -177,9 +177,6 @@ private: void initSize(); bool computeIsActive() const; - void checkLockByTerms(); - void showTermsDecline(); - void showTermsDelete(); not_null _controller; @@ -190,7 +187,6 @@ private: object_ptr _outdated; object_ptr _body; object_ptr _rightColumn = { nullptr }; - QPointer _termsBox; QIcon _icon; bool _usingSupportIcon = false; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 962558fb1..71abb7082 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -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 #include @@ -67,20 +71,124 @@ void Controller::showAccount(not_null 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( + *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( + 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>(); + const auto deleteByTerms = [=] { + if (const auto session = account().maybeSession()) { + session->termsDeleteNow(); + } else { + Ui::hideLayer(); + } + }; + *box = Ui::show( + Box( + 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; diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 32c4445f6..e5f14096f 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -26,17 +26,18 @@ public: void showAccount(not_null 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; base::Timer _isActiveTimer; + QPointer _termsBox; rpl::lifetime _accountLifetime; rpl::lifetime _lifetime;