Move terms lock from Core::App to Session.

This commit is contained in:
John Preston 2020-06-24 11:56:16 +04:00
parent 30c82bb2e0
commit e7b8a52278
19 changed files with 233 additions and 272 deletions

View File

@ -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;

View File

@ -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<bool> Application::passcodeLockValue() const {
return _passcodeLock.value();
}
void Application::lockByTerms(const Window::TermsLock &data) {
if (!_termsLock || *_termsLock != data) {
_termsLock = std::make_unique<Window::TermsLock>(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<Window::TermsLock> Application::termsLocked() const {
return _termsLock ? base::make_optional(*_termsLock) : std::nullopt;
}
rpl::producer<bool> Application::termsLockChanges() const {
return _termsLockChanges.events();
}
rpl::producer<bool> Application::termsLockValue() const {
return rpl::single(
_termsLock != nullptr
) | rpl::then(termsLockChanges());
}
bool Application::locked() const {
return passcodeLocked() || termsLocked();
}
rpl::producer<bool> Application::lockChanges() const {
return lockValue() | rpl::skip(1);
}
rpl::producer<bool> Application::lockValue() const {
using namespace rpl::mappers;
return rpl::combine(
passcodeLockValue(),
termsLockValue(),
_1 || _2);
}
bool Application::hasActiveWindow(not_null<Main::Session*> 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;
}

View File

@ -23,7 +23,6 @@ class Databases;
} // namespace Storage
namespace Window {
struct TermsLock;
class Controller;
} // namespace Window
@ -223,16 +222,6 @@ public:
rpl::producer<bool> passcodeLockChanges() const;
rpl::producer<bool> passcodeLockValue() const;
void lockByTerms(const Window::TermsLock &data);
void unlockTerms();
[[nodiscard]] std::optional<Window::TermsLock> termsLocked() const;
rpl::producer<bool> termsLockChanges() const;
rpl::producer<bool> termsLockValue() const;
[[nodiscard]] bool locked() const;
rpl::producer<bool> lockChanges() const;
rpl::producer<bool> lockValue() const;
void checkAutoLock();
void checkAutoLockIn(crl::time time);
void localPasscodeChanged();
@ -331,8 +320,6 @@ private:
const QImage _logoNoMargin;
rpl::variable<bool> _passcodeLock;
rpl::event_stream<bool> _termsLockChanges;
std::unique_ptr<Window::TermsLock> _termsLock;
crl::time _shouldLockAt = 0;
base::Timer _autoLockTimer;

View File

@ -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<FullMsgId>();
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<QString, QString> &params) {
}
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<InformBox>(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<SessionsBox>(session));
Ui::show(Box<SessionsBox>(&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<InformBox>(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);
}

View File

@ -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<bool(
Main::Session *session,
Window::SessionController *controller,
const qthelp::RegularExpressionMatch &match,
const QVariant &context)> handler;
};

View File

@ -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) {

View File

@ -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

View File

@ -503,7 +503,6 @@ void Account::loggedOut() {
_loggingOut = false;
Media::Player::mixer()->stopAndClear();
destroySession();
Core::App().unlockTerms();
local().reset();
cSetOtherOnline(0);
}

View File

@ -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<Window::TermsLock>(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<Window::TermsLock> Session::termsLocked() const {
return _termsLock ? base::make_optional(*_termsLock) : std::nullopt;
}
rpl::producer<bool> Session::termsLockChanges() const {
return _termsLockChanges.events();
}
rpl::producer<bool> Session::termsLockValue() const {
return rpl::single(
_termsLock != nullptr
) | rpl::then(termsLockChanges());
}
QString Session::createInternalLink(const QString &query) const {
auto result = createInternalLinkFull(query);
auto prefixes = {

View File

@ -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<Window::TermsLock> termsLocked() const;
rpl::producer<bool> termsLockChanges() const;
rpl::producer<bool> termsLockValue() const;
[[nodiscard]] QString createInternalLink(const QString &query) const;
[[nodiscard]] QString createInternalLinkFull(const QString &query) const;
@ -177,6 +184,9 @@ private:
std::shared_ptr<Data::CloudImageView> _selfUserpicView;
rpl::event_stream<bool> _termsLockChanges;
std::unique_ptr<Window::TermsLock> _termsLock;
base::flat_set<not_null<Window::SessionController*>> _windows;
base::Timer _saveSettingsTimer;

View File

@ -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<Window::HistoryHider*> instance) {
}
void MainWidget::hiderLayer(base::unique_qptr<Window::HistoryHider> 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;

View File

@ -97,7 +97,7 @@ MainWindow::MainWindow(not_null<Window::Controller*> 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<InformBox>(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();

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;