diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 8b5e0cbd9..eef367e92 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -314,9 +314,8 @@ namespace App { void quit() { if (quitting()) { return; - } else if (Main::Session::Exists() - && Auth().data().exportInProgress()) { - Auth().data().stopExportWithConfirmation([] { App::quit(); }); + } else if (Core::IsAppLaunched() + && Core::App().exportPreventsQuit()) { return; } setLaunchState(QuitRequested); diff --git a/Telegram/SourceFiles/boxes/auto_download_box.cpp b/Telegram/SourceFiles/boxes/auto_download_box.cpp index 34d00a982..7ba178507 100644 --- a/Telegram/SourceFiles/boxes/auto_download_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_download_box.cpp @@ -29,8 +29,10 @@ constexpr auto kDefaultLimit = 10 * kMegabyte; AutoDownloadBox::AutoDownloadBox( QWidget*, + not_null session, Data::AutoDownload::Source source) -: _source(source) { +: _session(session) +, _source(source) { } void AutoDownloadBox::prepare() { @@ -45,7 +47,7 @@ void AutoDownloadBox::setupContent() { setTitle(tr::lng_media_auto_title()); - const auto settings = &Auth().settings().autoDownload(); + const auto settings = &_session->settings().autoDownload(); const auto checked = [=](Source source, Type type) { return (settings->bytesLimit(source, type) > 0); }; @@ -166,11 +168,11 @@ void AutoDownloadBox::setupContent() { Local::writeUserSettings(); } if (allowMoreTypes.contains(Type::Photo)) { - Auth().data().photoLoadSettingsChanged(); + _session->data().photoLoadSettingsChanged(); } if (ranges::find_if(allowMoreTypes, _1 != Type::Photo) != allowMoreTypes.end()) { - Auth().data().documentLoadSettingsChanged(); + _session->data().documentLoadSettingsChanged(); } closeBox(); }); diff --git a/Telegram/SourceFiles/boxes/auto_download_box.h b/Telegram/SourceFiles/boxes/auto_download_box.h index a3485ef4e..50fefad68 100644 --- a/Telegram/SourceFiles/boxes/auto_download_box.h +++ b/Telegram/SourceFiles/boxes/auto_download_box.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" +namespace Main { +class Session; +} // namespace Main + namespace Data { namespace AutoDownload { enum class Source; @@ -17,7 +21,10 @@ enum class Source; class AutoDownloadBox : public BoxContent { public: - AutoDownloadBox(QWidget*, Data::AutoDownload::Source source); + AutoDownloadBox( + QWidget*, + not_null session, + Data::AutoDownload::Source source); protected: void prepare() override; @@ -25,6 +32,8 @@ protected: private: void setupContent(); + const not_null _session; + Data::AutoDownload::Source _source; }; diff --git a/Telegram/SourceFiles/boxes/auto_lock_box.cpp b/Telegram/SourceFiles/boxes/auto_lock_box.cpp index ab4a1ccf2..61db8eb88 100644 --- a/Telegram/SourceFiles/boxes/auto_lock_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_lock_box.cpp @@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/checkbox.h" #include "styles/style_boxes.h" +AutoLockBox::AutoLockBox(QWidget*, not_null session) +: _session(session) { +} + void AutoLockBox::prepare() { setTitle(tr::lng_passcode_autolock()); @@ -39,6 +43,6 @@ void AutoLockBox::durationChanged(int seconds) { Local::writeUserSettings(); Global::RefLocalPasscodeChanged().notify(); - Auth().checkAutoLock(); + _session->checkAutoLock(); closeBox(); } diff --git a/Telegram/SourceFiles/boxes/auto_lock_box.h b/Telegram/SourceFiles/boxes/auto_lock_box.h index c0bbd8e0f..903510236 100644 --- a/Telegram/SourceFiles/boxes/auto_lock_box.h +++ b/Telegram/SourceFiles/boxes/auto_lock_box.h @@ -9,14 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" +namespace Main { +class Session; +} // namespace Main + namespace Ui { class Radiobutton; } // namespace Ui class AutoLockBox : public BoxContent { public: - AutoLockBox(QWidget*) { - } + AutoLockBox(QWidget*, not_null session); protected: void prepare() override; @@ -24,6 +27,8 @@ protected: private: void durationChanged(int seconds); + const not_null _session; + std::vector> _options; }; diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index c58b0404d..20c245e96 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -54,7 +54,9 @@ class BackgroundBox::Inner , private MTP::Sender , private base::Subscriber { public: - Inner(QWidget *parent); + Inner( + QWidget *parent, + not_null session); rpl::producer chooseEvents() const; rpl::producer removeRequests() const; @@ -107,6 +109,8 @@ private: int row) const; void validatePaperThumbnail(const Paper &paper) const; + const not_null _session; + std::vector _papers; Selection _over; @@ -118,7 +122,8 @@ private: }; -BackgroundBox::BackgroundBox(QWidget*) { +BackgroundBox::BackgroundBox(QWidget*, not_null session) +: _session(session) { } void BackgroundBox::prepare() { @@ -128,11 +133,15 @@ void BackgroundBox::prepare() { setDimensions(st::boxWideWidth, st::boxMaxListHeight); - _inner = setInnerWidget(object_ptr(this), st::backgroundScroll); + _inner = setInnerWidget( + object_ptr(this, _session), + st::backgroundScroll); _inner->chooseEvents( - ) | rpl::start_with_next([](const Data::WallPaper &paper) { - Ui::show(Box(paper), LayerOption::KeepOther); + ) | rpl::start_with_next([=](const Data::WallPaper &paper) { + Ui::show( + Box(_session, paper), + LayerOption::KeepOther); }, _inner->lifetime()); _inner->removeRequests( @@ -143,6 +152,7 @@ void BackgroundBox::prepare() { void BackgroundBox::removePaper(const Data::WallPaper &paper) { const auto box = std::make_shared>(); + const auto session = _session; const auto remove = [=, weak = make_weak(this)]{ if (*box) { (*box)->closeBox(); @@ -150,8 +160,8 @@ void BackgroundBox::removePaper(const Data::WallPaper &paper) { if (weak) { weak->_inner->removePaper(paper); } - Auth().data().removeWallpaper(paper); - Auth().api().request(MTPaccount_SaveWallPaper( + session->data().removeWallpaper(paper); + session->api().request(MTPaccount_SaveWallPaper( paper.mtpInput(), MTP_bool(true), paper.mtpSettings() @@ -166,17 +176,21 @@ void BackgroundBox::removePaper(const Data::WallPaper &paper) { LayerOption::KeepOther); } -BackgroundBox::Inner::Inner(QWidget *parent) : RpWidget(parent) +BackgroundBox::Inner::Inner( + QWidget *parent, + not_null session) +: RpWidget(parent) +, _session(session) , _check(std::make_unique(st::overviewCheck, [=] { update(); })) { _check->setChecked(true, Ui::RoundCheckbox::SetStyle::Fast); - if (Auth().data().wallpapers().empty()) { + if (_session->data().wallpapers().empty()) { resize(st::boxWideWidth, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding); } else { updatePapers(); } requestPapers(); - subscribe(Auth().downloaderTaskFinished(), [=] { update(); }); + subscribe(_session->downloaderTaskFinished(), [=] { update(); }); using Update = Window::Theme::BackgroundUpdate; subscribe(Window::Theme::Background(), [=](const Update &update) { if (update.paletteChanged()) { @@ -192,9 +206,9 @@ BackgroundBox::Inner::Inner(QWidget *parent) : RpWidget(parent) void BackgroundBox::Inner::requestPapers() { request(MTPaccount_GetWallPapers( - MTP_int(Auth().data().wallpapersHash()) + MTP_int(_session->data().wallpapersHash()) )).done([=](const MTPaccount_WallPapers &result) { - if (Auth().data().updateWallpapers(result)) { + if (_session->data().updateWallpapers(result)) { updatePapers(); } }).send(); @@ -220,7 +234,7 @@ void BackgroundBox::Inner::sortPapers() { void BackgroundBox::Inner::updatePapers() { _over = _overDown = Selection(); - _papers = Auth().data().wallpapers( + _papers = _session->data().wallpapers( ) | ranges::view::filter([](const Data::WallPaper &paper) { return !paper.isPattern() || paper.backgroundColor().has_value(); }) | ranges::view::transform([](const Data::WallPaper &paper) { diff --git a/Telegram/SourceFiles/boxes/background_box.h b/Telegram/SourceFiles/boxes/background_box.h index 6cc597168..4dbfae467 100644 --- a/Telegram/SourceFiles/boxes/background_box.h +++ b/Telegram/SourceFiles/boxes/background_box.h @@ -9,13 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" +namespace Main { +class Session; +} // namespace Main + namespace Data { class WallPaper; } // namespace Data class BackgroundBox : public BoxContent { public: - BackgroundBox(QWidget*); + BackgroundBox(QWidget*, not_null session); protected: void prepare() override; @@ -25,6 +29,8 @@ private: void removePaper(const Data::WallPaper &paper); + const not_null _session; + QPointer _inner; }; diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index eaebe3c29..a389af557 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -387,20 +387,24 @@ QImage PrepareScaledFromFull( BackgroundPreviewBox::BackgroundPreviewBox( QWidget*, + not_null session, const Data::WallPaper &paper) -: _text1(GenerateTextItem( +: _session(session) +, _text1(GenerateTextItem( delegate(), - Auth().data().history(peerFromUser(PeerData::kServiceNotificationsId)), + _session->data().history( + peerFromUser(PeerData::kServiceNotificationsId)), tr::lng_background_text1(tr::now), false)) , _text2(GenerateTextItem( delegate(), - Auth().data().history(peerFromUser(PeerData::kServiceNotificationsId)), + _session->data().history( + peerFromUser(PeerData::kServiceNotificationsId)), tr::lng_background_text2(tr::now), true)) , _paper(paper) , _radial([=](crl::time now) { radialAnimationCallback(now); }) { - subscribe(Auth().downloaderTaskFinished(), [=] { update(); }); + subscribe(_session->downloaderTaskFinished(), [=] { update(); }); } not_null BackgroundPreviewBox::delegate() { @@ -483,7 +487,7 @@ void BackgroundPreviewBox::apply() { && Data::IsCloudWallPaper(_paper); App::main()->setChatBackground(_paper, std::move(_full)); if (install) { - Auth().api().request(MTPaccount_InstallWallPaper( + _session->api().request(MTPaccount_InstallWallPaper( _paper.mtpInput(), _paper.mtpSettings() )).send(); @@ -736,18 +740,23 @@ void BackgroundPreviewBox::checkLoadedDocument() { } bool BackgroundPreviewBox::Start( + not_null session, const QString &slug, const QMap ¶ms) { if (const auto paper = Data::WallPaper::FromColorSlug(slug)) { - Ui::show(Box(paper->withUrlParams(params))); + Ui::show(Box( + session, + paper->withUrlParams(params))); return true; } if (!IsValidWallPaperSlug(slug)) { Ui::show(Box(tr::lng_background_bad_link(tr::now))); return false; } - Auth().api().requestWallPaper(slug, [=](const Data::WallPaper &result) { - Ui::show(Box(result.withUrlParams(params))); + session->api().requestWallPaper(slug, [=](const Data::WallPaper &result) { + Ui::show(Box( + session, + result.withUrlParams(params))); }, [](const RPCError &error) { Ui::show(Box(tr::lng_background_bad_link(tr::now))); }); diff --git a/Telegram/SourceFiles/boxes/background_preview_box.h b/Telegram/SourceFiles/boxes/background_preview_box.h index 3d7cbb2df..6d97e2f18 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" +namespace Main { +class Session; +} // namespace Main + namespace Ui { class Checkbox; } // namespace Ui @@ -23,9 +27,13 @@ class BackgroundPreviewBox : public BoxContent , private HistoryView::SimpleElementDelegate { public: - BackgroundPreviewBox(QWidget*, const Data::WallPaper &paper); + BackgroundPreviewBox( + QWidget*, + not_null session, + const Data::WallPaper &paper); static bool Start( + not_null session, const QString &slug, const QMap ¶ms); @@ -58,6 +66,7 @@ private: void startFadeInFrom(QPixmap previous); void checkBlurAnimationStart(); + const not_null _session; AdminLog::OwnedItem _text1; AdminLog::OwnedItem _text2; Data::WallPaper _paper; diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index 919b54f46..8b30c7b19 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -60,8 +60,7 @@ void createErrorLabel( class ChangePhoneBox::EnterPhone : public BoxContent { public: - EnterPhone(QWidget*) { - } + EnterPhone(QWidget*, not_null session); void setInnerFocus() override { _phone->setFocusFast(); @@ -79,6 +78,7 @@ private: showError(QString()); } + const not_null _session; object_ptr _phone = { nullptr }; object_ptr> _error = { nullptr }; mtpRequestId _requestId = 0; @@ -87,7 +87,13 @@ private: class ChangePhoneBox::EnterCode : public BoxContent { public: - EnterCode(QWidget*, const QString &phone, const QString &hash, int codeLength, int callTimeout); + EnterCode( + QWidget*, + not_null session, + const QString &phone, + const QString &hash, + int codeLength, + int callTimeout); void setInnerFocus() override { _code->setFocusFast(); @@ -107,6 +113,8 @@ private: } int countHeight(); + const not_null _session; + QString _phone; QString _hash; int _codeLength = 0; @@ -119,6 +127,12 @@ private: }; +ChangePhoneBox::EnterPhone::EnterPhone( + QWidget*, + not_null session) +: _session(session) { +} + void ChangePhoneBox::EnterPhone::prepare() { setTitle(tr::lng_change_phone_title()); @@ -188,6 +202,7 @@ void ChangePhoneBox::EnterPhone::sendPhoneDone(const QString &phoneNumber, const } Ui::show( Box( + _session, phoneNumber, phoneCodeHash, codeLength, @@ -229,8 +244,15 @@ void ChangePhoneBox::EnterPhone::showError(const QString &text) { } } -ChangePhoneBox::EnterCode::EnterCode(QWidget*, const QString &phone, const QString &hash, int codeLength, int callTimeout) -: _phone(phone) +ChangePhoneBox::EnterCode::EnterCode( + QWidget*, + not_null session, + const QString &phone, + const QString &hash, + int codeLength, + int callTimeout) +: _session(session) +, _phone(phone) , _hash(hash) , _codeLength(codeLength) , _callTimeout(callTimeout) @@ -279,13 +301,15 @@ void ChangePhoneBox::EnterCode::submit() { } hideError(); + const auto session = _session; const auto code = _code->getDigitsOnly(); + const auto weak = make_weak(this); _requestId = MTP::send(MTPaccount_ChangePhone( MTP_string(_phone), MTP_string(_hash), MTP_string(code) - ), rpcDone([weak = make_weak(this)](const MTPUser &result) { - Auth().data().processUser(result); + ), rpcDone([=](const MTPUser &result) { + session->data().processUser(result); if (weak) { Ui::hideLayer(); } @@ -342,11 +366,17 @@ bool ChangePhoneBox::EnterCode::sendCodeFail(const RPCError &error) { return true; } +ChangePhoneBox::ChangePhoneBox(QWidget*, not_null session) +: _session(session) { +} + void ChangePhoneBox::prepare() { + const auto session = _session; + setTitle(tr::lng_change_phone_title()); - addButton(tr::lng_change_phone_button(), [] { - Ui::show(Box(tr::lng_change_phone_warning(tr::now), [] { - Ui::show(Box()); + addButton(tr::lng_change_phone_button(), [=] { + Ui::show(Box(tr::lng_change_phone_warning(tr::now), [=] { + Ui::show(Box(session)); })); }); addButton(tr::lng_cancel(), [this] { diff --git a/Telegram/SourceFiles/boxes/change_phone_box.h b/Telegram/SourceFiles/boxes/change_phone_box.h index ee9383c97..9eb6a8479 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.h +++ b/Telegram/SourceFiles/boxes/change_phone_box.h @@ -9,10 +9,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" +namespace Main { +class Session; +} // namespace Main + class ChangePhoneBox : public BoxContent { public: - ChangePhoneBox(QWidget*) { - } + ChangePhoneBox(QWidget*, not_null session); protected: void prepare() override; @@ -23,5 +26,7 @@ private: class EnterPhone; class EnterCode; + const not_null _session; + }; diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 4f2b6942d..3d79848cb 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -459,7 +459,8 @@ DeleteMessagesBox::DeleteMessagesBox( QWidget*, not_null item, bool suggestModerateActions) -: _ids(1, item->fullId()) { +: _session(&item->history()->session()) +, _ids(1, item->fullId()) { if (suggestModerateActions) { _moderateBan = item->suggestBanReport(); _moderateDeleteAll = item->suggestDeleteAllReport(); @@ -472,8 +473,10 @@ DeleteMessagesBox::DeleteMessagesBox( DeleteMessagesBox::DeleteMessagesBox( QWidget*, + not_null session, MessageIdsList &&selected) -: _ids(std::move(selected)) { +: _session(session) +, _ids(std::move(selected)) { Expects(!_ids.empty()); } @@ -481,7 +484,8 @@ DeleteMessagesBox::DeleteMessagesBox( QWidget*, not_null peer, bool justClear) -: _wipeHistoryPeer(peer) +: _session(&peer->session()) +, _wipeHistoryPeer(peer) , _wipeHistoryJustClear(justClear) { } @@ -579,7 +583,7 @@ void DeleteMessagesBox::prepare() { PeerData *DeleteMessagesBox::checkFromSinglePeer() const { auto result = (PeerData*)nullptr; for (const auto fullId : std::as_const(_ids)) { - if (const auto item = Auth().data().message(fullId)) { + if (const auto item = _session->data().message(fullId)) { const auto peer = item->history()->peer; if (!result) { result = peer; @@ -762,7 +766,7 @@ void DeleteMessagesBox::deleteAndClear() { base::flat_map, QVector> idsByPeer; for (const auto itemId : _ids) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = _session->data().message(itemId)) { const auto history = item->history(); const auto wasOnServer = IsServerMsgId(item->id); const auto wasLast = (history->lastMessage() == item); @@ -780,18 +784,21 @@ void DeleteMessagesBox::deleteAndClear() { for (const auto &[peer, ids] : idsByPeer) { peer->session().api().deleteMessages(peer, ids, revoke); } + const auto session = _session; Ui::hideLayer(); - Auth().data().sendHistoryChangeNotifications(); + session->data().sendHistoryChangeNotifications(); } ConfirmInviteBox::ConfirmInviteBox( QWidget*, + not_null session, const MTPDchatInvite &data, Fn submit) -: _submit(std::move(submit)) +: _session(session) +, _submit(std::move(submit)) , _title(this, st::confirmInviteTitle) , _status(this, st::confirmInviteStatus) -, _participants(GetParticipants(data)) +, _participants(GetParticipants(_session, data)) , _isChannel(data.is_channel() && !data.is_megagroup()) { const auto title = qs(data.vtitle()); const auto count = data.vparticipants_count().v; @@ -807,11 +814,11 @@ ConfirmInviteBox::ConfirmInviteBox( _title->setText(title); _status->setText(status); - const auto photo = Auth().data().processPhoto(data.vphoto()); + const auto photo = _session->data().processPhoto(data.vphoto()); if (!photo->isNull()) { _photo = photo->thumbnail(); if (!_photo->loaded()) { - subscribe(Auth().downloaderTaskFinished(), [=] { + subscribe(_session->downloaderTaskFinished(), [=] { update(); }); _photo->load(Data::FileOrigin()); @@ -824,6 +831,7 @@ ConfirmInviteBox::ConfirmInviteBox( } std::vector> ConfirmInviteBox::GetParticipants( + not_null session, const MTPDchatInvite &data) { const auto participants = data.vparticipants(); if (!participants) { @@ -833,7 +841,7 @@ std::vector> ConfirmInviteBox::GetParticipants( auto result = std::vector>(); result.reserve(v.size()); for (const auto &participant : v) { - if (const auto user = Auth().data().processUser(participant)) { + if (const auto user = session->data().processUser(participant)) { result.push_back(user); } } diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index afaa94037..e1fe14314 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" +namespace Main { +class Session; +} // namespace Main + namespace Ui { class Checkbox; class FlatLabel; @@ -150,7 +154,10 @@ public: QWidget*, not_null item, bool suggestModerateActions); - DeleteMessagesBox(QWidget*, MessageIdsList &&selected); + DeleteMessagesBox( + QWidget*, + not_null session, + MessageIdsList &&selected); DeleteMessagesBox(QWidget*, not_null peer, bool justClear); void setDeleteConfirmedCallback(Fn callback) { @@ -172,6 +179,8 @@ private: PeerData *checkFromSinglePeer() const; std::optional revokeText(not_null peer) const; + const not_null _session; + PeerData * const _wipeHistoryPeer = nullptr; const bool _wipeHistoryJustClear = false; const MessageIdsList _ids; @@ -194,6 +203,7 @@ class ConfirmInviteBox : public BoxContent, public RPCSender { public: ConfirmInviteBox( QWidget*, + not_null session, const MTPDchatInvite &data, Fn submit); ~ConfirmInviteBox(); @@ -206,8 +216,11 @@ protected: private: static std::vector> GetParticipants( + not_null session, const MTPDchatInvite &data); + const not_null _session; + Fn _submit; object_ptr _title; object_ptr _status; diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 8839d86bf..3a4086721 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -232,7 +232,7 @@ EditCaptionBox::EditCaptionBox( _thumbnailImageLoaded = _thumbnailImage ? _thumbnailImage->loaded() : true; - subscribe(Auth().downloaderTaskFinished(), [=] { + subscribe(_controller->session().downloaderTaskFinished(), [=] { if (!_thumbnailImageLoaded && _thumbnailImage && _thumbnailImage->loaded()) { @@ -876,7 +876,7 @@ void EditCaptionBox::setInnerFocus() { void EditCaptionBox::save() { if (_saveRequestId) return; - const auto item = Auth().data().message(_msgId); + const auto item = _controller->session().data().message(_msgId); if (!item) { _error = tr::lng_edit_deleted(tr::now); update(); @@ -894,7 +894,7 @@ void EditCaptionBox::save() { }; const auto prepareFlags = Ui::ItemTextOptions( item->history(), - Auth().user()).flags; + _controller->session().user()).flags; TextUtilities::PrepareForSending(sending, prepareFlags); TextUtilities::Trim(sending); @@ -913,7 +913,7 @@ void EditCaptionBox::save() { }; item->setText(sending); - Auth().api().editMedia( + _controller->session().api().editMedia( std::move(_preparedList), (!_asFile && _photo) ? SendMediaType::Photo : SendMediaType::File, _field->getTextWithAppliedMarkdown(), @@ -938,21 +938,24 @@ void EditCaptionBox::save() { void EditCaptionBox::saveDone(const MTPUpdates &updates) { _saveRequestId = 0; + const auto controller = _controller; closeBox(); - Auth().api().applyUpdates(updates); + controller->session().api().applyUpdates(updates); } bool EditCaptionBox::saveFail(const RPCError &error) { if (MTP::isDefaultHandledError(error)) return false; _saveRequestId = 0; - QString err = error.type(); - if (err == qstr("MESSAGE_ID_INVALID") || err == qstr("CHAT_ADMIN_REQUIRED") || err == qstr("MESSAGE_EDIT_TIME_EXPIRED")) { + const auto &type = error.type(); + if (type == qstr("MESSAGE_ID_INVALID") + || type == qstr("CHAT_ADMIN_REQUIRED") + || type == qstr("MESSAGE_EDIT_TIME_EXPIRED")) { _error = tr::lng_edit_error(tr::now); - } else if (err == qstr("MESSAGE_NOT_MODIFIED")) { + } else if (type == qstr("MESSAGE_NOT_MODIFIED")) { closeBox(); return true; - } else if (err == qstr("MESSAGE_EMPTY")) { + } else if (type == qstr("MESSAGE_EMPTY")) { _field->setFocus(); _field->showError(); } else { diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 6a9baec1e..ed6152957 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_chat.h" #include "data/data_channel.h" +#include "window/window_session_controller.h" #include "styles/style_settings.h" #include "styles/style_boxes.h" @@ -113,9 +114,11 @@ QString EditPrivacyController::optionLabel(Option option) { EditPrivacyBox::EditPrivacyBox( QWidget*, + not_null window, std::unique_ptr controller, const Value &value) -: _controller(std::move(controller)) +: _window(window) +, _controller(std::move(controller)) , _value(value) { } @@ -350,7 +353,7 @@ void EditPrivacyBox::setupContent() { addLabel(content, _controller->exceptionsDescription()); AddSkip(content); - if (auto below = _controller->setupBelowWidget(content)) { + if (auto below = _controller->setupBelowWidget(_window, content)) { content->add(std::move(below)); } @@ -358,7 +361,7 @@ void EditPrivacyBox::setupContent() { const auto someAreDisallowed = (_value.option != Option::Everyone) || !_value.never.empty(); _controller->confirmSave(someAreDisallowed, crl::guard(this, [=] { - Auth().api().savePrivacy( + _window->session().api().savePrivacy( _controller->apiKey(), collectResult()); closeBox(); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.h b/Telegram/SourceFiles/boxes/edit_privacy_box.h index 1096d5f81..29110f2cf 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.h +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.h @@ -59,6 +59,7 @@ public: return { nullptr }; } [[nodiscard]] virtual object_ptr setupBelowWidget( + not_null controller, not_null parent) { return { nullptr }; } @@ -95,6 +96,7 @@ public: EditPrivacyBox( QWidget*, + not_null window, std::unique_ptr controller, const Value &value); @@ -117,6 +119,7 @@ private: void editExceptions(Exception exception, Fn done); std::vector> &exceptions(Exception exception); + const not_null _window; std::unique_ptr _controller; Value _value; diff --git a/Telegram/SourceFiles/boxes/local_storage_box.cpp b/Telegram/SourceFiles/boxes/local_storage_box.cpp index 7614a0c4c..047dcc2cb 100644 --- a/Telegram/SourceFiles/boxes/local_storage_box.cpp +++ b/Telegram/SourceFiles/boxes/local_storage_box.cpp @@ -265,11 +265,11 @@ QString LocalStorageBox::Row::sizeText(const Database::TaggedSummary &data) cons LocalStorageBox::LocalStorageBox( QWidget*, - not_null db, - not_null dbBig, + not_null session, CreateTag) -: _db(db) -, _dbBig(dbBig) { +: _session(session) +, _db(&session->data().cache()) +, _dbBig(&session->data().cacheBigFile()) { const auto &settings = Local::cacheSettings(); const auto &settingsBig = Local::cacheBigFileSettings(); _totalSizeLimit = settings.totalSizeLimit + settingsBig.totalSizeLimit; @@ -277,15 +277,13 @@ LocalStorageBox::LocalStorageBox( _timeLimit = settings.totalTimeLimit; } -void LocalStorageBox::Show( - not_null db, - not_null dbBig) { +void LocalStorageBox::Show(not_null<::Main::Session*> session) { auto shared = std::make_shared>( - Box(db, dbBig, CreateTag())); + Box(session, CreateTag())); const auto weak = shared->data(); rpl::combine( - db->statsOnMain(), - dbBig->statsOnMain() + session->data().cache().statsOnMain(), + session->data().cacheBigFile().statsOnMain() ) | rpl::start_with_next([=]( Database::Stats &&stats, Database::Stats &&statsBig) { @@ -592,7 +590,7 @@ void LocalStorageBox::save() { updateBig.totalSizeLimit = _mediaSizeLimit; updateBig.totalTimeLimit = _timeLimit; Local::updateCacheSettings(update, updateBig); - Auth().data().cache().updateSettings(update); + _session->data().cache().updateSettings(update); closeBox(); } diff --git a/Telegram/SourceFiles/boxes/local_storage_box.h b/Telegram/SourceFiles/boxes/local_storage_box.h index 5a9bc4e30..f00d83958 100644 --- a/Telegram/SourceFiles/boxes/local_storage_box.h +++ b/Telegram/SourceFiles/boxes/local_storage_box.h @@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "storage/cache/storage_cache_database.h" +namespace Main { +class Session; +} // namespace Main + namespace Storage { namespace Cache { class Database; @@ -33,11 +37,10 @@ public: LocalStorageBox( QWidget*, - not_null db, - not_null dbBig, + not_null session, CreateTag); - static void Show(not_null db, not_null dbBig); + static void Show(not_null session); protected: void prepare() override; @@ -80,8 +83,10 @@ private: Value currentValue, Callback &&callback); - not_null _db; - not_null _dbBig; + const not_null _session; + const not_null _db; + const not_null _dbBig; + Database::Stats _stats; Database::Stats _statsBig; diff --git a/Telegram/SourceFiles/boxes/mute_settings_box.cpp b/Telegram/SourceFiles/boxes/mute_settings_box.cpp index d809afe17..996d424a2 100644 --- a/Telegram/SourceFiles/boxes/mute_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/mute_settings_box.cpp @@ -10,6 +10,7 @@ Copyright (C) 2017, Nicholas Guriev #include "lang/lang_keys.h" #include "main/main_session.h" #include "data/data_session.h" +#include "data/data_peer.h" #include "styles/style_boxes.h" #include "ui/special_buttons.h" #include "ui/widgets/checkbox.h" @@ -73,7 +74,7 @@ void MuteSettingsBox::prepare() { _save = [=] { const auto muteForSeconds = group->value() * 3600; - Auth().data().updateNotifySettings( + _peer->session().data().updateNotifySettings( _peer, muteForSeconds); closeBox(); diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 05cfa92ef..a8a0b19f2 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -40,8 +40,12 @@ PasscodeBox::CloudFields PasscodeBox::CloudFields::From( return result; } -PasscodeBox::PasscodeBox(QWidget*, bool turningOff) -: _turningOff(turningOff) +PasscodeBox::PasscodeBox( + QWidget*, + not_null session, + bool turningOff) +: _session(session) +, _turningOff(turningOff) , _about(st::boxWidth - st::boxPadding.left() * 1.5) , _oldPasscode(this, st::defaultInputField, tr::lng_passcode_enter_old()) , _newPasscode(this, st::defaultInputField, Global::LocalPasscode() ? tr::lng_passcode_enter_new() : tr::lng_passcode_enter_first()) @@ -51,8 +55,12 @@ PasscodeBox::PasscodeBox(QWidget*, bool turningOff) , _recover(this, tr::lng_signin_recover(tr::now)) { } -PasscodeBox::PasscodeBox(QWidget*, const CloudFields &fields) -: _turningOff(fields.turningOff) +PasscodeBox::PasscodeBox( + QWidget*, + not_null session, + const CloudFields &fields) +: _session(session) +, _turningOff(fields.turningOff) , _cloudPwd(true) , _cloudFields(fields) , _about(st::boxWidth - st::boxPadding.left() * 1.5) @@ -506,7 +514,7 @@ void PasscodeBox::save(bool force) { const auto weak = make_weak(this); cSetPasscodeBadTries(0); Local::setPasscode(pwd.toUtf8()); - Auth().localPasscodeChanged(); + _session->localPasscodeChanged(); if (weak) { closeBox(); } diff --git a/Telegram/SourceFiles/boxes/passcode_box.h b/Telegram/SourceFiles/boxes/passcode_box.h index 8b9dbdf05..7c907d523 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.h +++ b/Telegram/SourceFiles/boxes/passcode_box.h @@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "core/core_cloud_password.h" +namespace Main { +class Session; +} // namespace Main + namespace Ui { class InputField; class PasswordInput; @@ -23,7 +27,7 @@ struct CloudPasswordState; class PasscodeBox : public BoxContent, private MTP::Sender { public: - PasscodeBox(QWidget*, bool turningOff); + PasscodeBox(QWidget*, not_null session, bool turningOff); struct CloudFields { static CloudFields From(const Core::CloudPasswordState ¤t); @@ -42,7 +46,10 @@ public: std::optional customDescription; rpl::producer customSubmitButton; }; - PasscodeBox(QWidget*, const CloudFields &fields); + PasscodeBox( + QWidget*, + not_null session, + const CloudFields &fields); rpl::producer newPasswordSet() const; rpl::producer<> passwordReloadNeeded() const; @@ -122,6 +129,8 @@ private: void passwordChecked(); void serverError(); + const not_null _session; + QString _pattern; QPointer _replacedBy; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 851629750..3809c0d73 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -57,7 +57,7 @@ void SetCloudPassword(not_null box, not_null user) { ) | rpl::start_with_next([=] { using namespace Settings; const auto weak = make_weak(box); - if (CheckEditCloudPassword()) { + if (CheckEditCloudPassword(&user->session())) { box->getDelegate()->show( EditCloudPasswordBox(&user->session())); } else { @@ -566,7 +566,9 @@ void EditAdminBox::requestTransferPassword(not_null channel) { const Core::CloudPasswordResult &result) { sendTransferRequestFrom(*box, channel, result); }); - *box = getDelegate()->show(Box(fields)); + *box = getDelegate()->show(Box( + &channel->session(), + fields)); }, lifetime()); } diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index c91dd5f04..f12b4fb00 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -480,6 +480,17 @@ void Application::writeInstallBetaVersionsSetting() { _launcher->writeInstallBetaVersionsSetting(); } +bool Application::exportPreventsQuit() { + if (!activeAccount().sessionExists() + || !activeAccount().session().data().exportInProgress()) { + return false; + } + activeAccount().session().data().stopExportWithConfirmation([] { + App::quit(); + }); + return true; +} + int Application::unreadBadge() const { return activeAccount().sessionExists() ? activeAccount().session().data().unreadBadge() @@ -551,12 +562,15 @@ bool Application::openLocalUrl(const QString &url, QVariant context) { } auto command = urlTrimmed.midRef(protocol.size()); + const auto session = activeAccount().sessionExists() + ? &activeAccount().session() + : nullptr; using namespace qthelp; const auto options = RegExOption::CaseInsensitive; for (const auto &[expression, handler] : LocalUrlHandlers()) { const auto match = regex_match(expression, command, options); if (match) { - return handler(match, context); + return handler(session, match, context); } } return false; diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index f9d8c444d..10fc5c8ea 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -130,17 +130,18 @@ public: void badMtprotoConfigurationError(); // Databases. - Storage::Databases &databases() { + [[nodiscard]] Storage::Databases &databases() { return *_databases; } // Account component. - Main::Account &activeAccount() const { + [[nodiscard]] Main::Account &activeAccount() const { return *_account; } + [[nodiscard]] bool exportPreventsQuit(); // Main::Session component. - int unreadBadge() const; + [[nodiscard]] int unreadBadge() const; bool unreadBadgeMuted() const; // Media component. diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index d7468ea25..f80888243 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -33,19 +33,22 @@ namespace { using Match = qthelp::RegularExpressionMatch; -bool JoinGroupByHash(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool JoinGroupByHash( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } const auto hash = match->captured(1); - Auth().api().checkChatInvite(hash, [=](const MTPChatInvite &result) { + session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) { Core::App().hideMediaView(); result.match([=](const MTPDchatInvite &data) { - Ui::show(Box(data, [=] { - Auth().api().importChatInvite(hash); + Ui::show(Box(session, data, [=] { + session->api().importChatInvite(hash); })); }, [=](const MTPDchatInviteAlready &data) { - if (const auto chat = Auth().data().processChat(data.vchat())) { + if (const auto chat = session->data().processChat(data.vchat())) { App::wnd()->sessionController()->showPeerHistory( chat, Window::SectionShow::Way::Forward); @@ -61,8 +64,11 @@ bool JoinGroupByHash(const Match &match, const QVariant &context) { return true; } -bool ShowStickerSet(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ShowStickerSet( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } Core::App().hideMediaView(); @@ -72,14 +78,20 @@ bool ShowStickerSet(const Match &match, const QVariant &context) { return true; } -bool SetLanguage(const Match &match, const QVariant &context) { +bool SetLanguage( + Main::Session *session, + const Match &match, + const QVariant &context) { const auto languageId = match->captured(1); Lang::CurrentCloudManager().switchWithWarning(languageId); return true; } -bool ShareUrl(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ShareUrl( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } auto params = url_parse_params( @@ -93,8 +105,11 @@ bool ShareUrl(const Match &match, const QVariant &context) { return true; } -bool ConfirmPhone(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ConfirmPhone( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } auto params = url_parse_params( @@ -109,8 +124,11 @@ bool ConfirmPhone(const Match &match, const QVariant &context) { return true; } -bool ShareGameScore(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ShareGameScore( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } const auto params = url_parse_params( @@ -120,7 +138,10 @@ bool ShareGameScore(const Match &match, const QVariant &context) { return true; } -bool ApplySocksProxy(const Match &match, const QVariant &context) { +bool ApplySocksProxy( + Main::Session *session, + const Match &match, + const QVariant &context) { auto params = url_parse_params( match->captured(1), qthelp::UrlParamNameTransform::ToLower); @@ -128,7 +149,10 @@ bool ApplySocksProxy(const Match &match, const QVariant &context) { return true; } -bool ApplyMtprotoProxy(const Match &match, const QVariant &context) { +bool ApplyMtprotoProxy( + Main::Session *session, + const Match &match, + const QVariant &context) { auto params = url_parse_params( match->captured(1), qthelp::UrlParamNameTransform::ToLower); @@ -160,26 +184,36 @@ bool ShowPassportForm(const QMap ¶ms) { return false; } -bool ShowPassport(const Match &match, const QVariant &context) { +bool ShowPassport( + Main::Session *session, + const Match &match, + const QVariant &context) { return ShowPassportForm(url_parse_params( match->captured(1), qthelp::UrlParamNameTransform::ToLower)); } -bool ShowWallPaper(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ShowWallPaper( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } const auto params = url_parse_params( match->captured(1), qthelp::UrlParamNameTransform::ToLower); return BackgroundPreviewBox::Start( + session, params.value(qsl("slug")), params); } -bool ResolveUsername(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ResolveUsername( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } const auto params = url_parse_params( @@ -228,8 +262,11 @@ bool ResolveUsername(const Match &match, const QVariant &context) { return true; } -bool ResolvePrivatePost(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool ResolvePrivatePost( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } const auto params = url_parse_params( @@ -249,18 +286,17 @@ bool ResolvePrivatePost(const Match &match, const QVariant &context) { const auto fail = [=] { Ui::show(Box(tr::lng_error_post_link_invalid(tr::now))); }; - const auto auth = &Auth(); - if (const auto channel = auth->data().channelLoaded(channelId)) { + if (const auto channel = session->data().channelLoaded(channelId)) { done(channel); return true; } - auth->api().request(MTPchannels_GetChannels( + session->api().request(MTPchannels_GetChannels( MTP_vector( 1, MTP_inputChannel(MTP_int(channelId), MTP_long(0))) )).done([=](const MTPmessages_Chats &result) { result.match([&](const auto &data) { - const auto peer = auth->data().processChats(data.vchats()); + const auto peer = session->data().processChats(data.vchats()); if (peer && peer->id == peerFromChannel(channelId)) { done(peer); } else { @@ -273,8 +309,11 @@ bool ResolvePrivatePost(const Match &match, const QVariant &context) { return true; } -bool HandleUnknown(const Match &match, const QVariant &context) { - if (!Main::Session::Exists()) { +bool HandleUnknown( + Main::Session *session, + const Match &match, + const QVariant &context) { + if (!session) { return false; } const auto request = match->captured(1); @@ -298,7 +337,7 @@ bool HandleUnknown(const Match &match, const QVariant &context) { Ui::show(Box(text)); } }; - Auth().api().requestDeepLinkInfo(request, callback); + session->api().requestDeepLinkInfo(request, callback); return true; } diff --git a/Telegram/SourceFiles/core/local_url_handlers.h b/Telegram/SourceFiles/core/local_url_handlers.h index e4f266fec..a24040c08 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.h +++ b/Telegram/SourceFiles/core/local_url_handlers.h @@ -11,11 +11,16 @@ namespace qthelp { class RegularExpressionMatch; } // namespace qthelp +namespace Main { +class Session; +} // namespace Main + namespace Core { struct LocalUrlHandler { QString expression; Fn handler; }; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 77f814ff8..7a5abb47f 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -3012,6 +3012,7 @@ void HistoryInner::deleteAsGroup(FullMsgId itemId) { return deleteItem(item); } Ui::show(Box( + &session(), session().data().itemsToIds(group->items))); } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index b5b9c4b31..80b7ccd27 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6131,7 +6131,9 @@ void HistoryWidget::confirmDeleteSelected() { return; } const auto weak = make_weak(this); - const auto box = Ui::show(Box(std::move(items))); + const auto box = Ui::show(Box( + &session(), + std::move(items))); box->setDeleteConfirmedCallback([=] { if (const auto strong = weak.data()) { strong->clearSelected(); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index f90924b87..ec582e384 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -298,10 +298,13 @@ bool AddDeleteSelectedAction( return false; } + const auto session = request.session; menu->addAction(tr::lng_context_delete_selected(tr::now), [=] { const auto weak = make_weak(list); auto items = ExtractIdsList(request.selectedItems); - const auto box = Ui::show(Box(std::move(items))); + const auto box = Ui::show(Box( + session, + std::move(items))); box->setDeleteConfirmedCallback([=] { if (const auto strong = weak.data()) { strong->cancelSelection(); @@ -338,6 +341,7 @@ bool AddDeleteMessageAction( if (asGroup) { if (const auto group = owner->groups().find(item)) { Ui::show(Box( + &owner->session(), owner->itemsToIds(group->items))); return; } @@ -439,6 +443,10 @@ void AddCopyLinkAction( } // namespace +ContextMenuRequest::ContextMenuRequest(not_null session) +: session(session) { +} + base::unique_qptr FillContextMenu( not_null list, const ContextMenuRequest &request) { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index 2e5915665..65d870a1b 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -13,6 +13,10 @@ namespace Ui { class PopupMenu; } // namespace Ui +namespace Main { +class Session; +} // namespace Main + namespace HistoryView { enum class PointState : char; @@ -22,6 +26,9 @@ struct SelectedItem; using SelectedItems = std::vector; struct ContextMenuRequest { + explicit ContextMenuRequest(not_null session); + + const not_null session; ClickHandlerPtr link; Element *view = nullptr; HistoryItem *item = nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 02f46c5c5..021c649a4 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1611,7 +1611,8 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { mouseActionUpdate(e->globalPos()); } - ContextMenuRequest request; + auto request = ContextMenuRequest(&_controller->session()); + request.link = ClickHandler::getActive(); request.view = _overElement; request.item = _overItemExact diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index f00d453df..08add27da 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -35,9 +35,11 @@ namespace Info { TopBar::TopBar( QWidget *parent, + not_null session, const style::InfoTopBar &st, SelectedItems &&selectedItems) : RpWidget(parent) +, _session(session) , _st(st) , _selectedItems(Section::MediaType::kCount) { setAttribute(Qt::WA_OpaquePaintEvent); @@ -516,8 +518,8 @@ MessageIdsList TopBar::collectItems() const { _selectedItems.list ) | ranges::view::transform([](auto &&item) { return item.msgId; - }) | ranges::view::filter([](FullMsgId msgId) { - return Auth().data().message(msgId) != nullptr; + }) | ranges::view::filter([&](FullMsgId msgId) { + return _session->data().message(msgId) != nullptr; }) | ranges::to_vector; } @@ -541,7 +543,9 @@ void TopBar::performDelete() { if (items.empty()) { _cancelSelectionClicks.fire({}); } else { - const auto box = Ui::show(Box(std::move(items))); + const auto box = Ui::show(Box( + _session, + std::move(items))); box->setDeleteConfirmedCallback([weak = make_weak(this)] { if (weak) { weak->_cancelSelectionClicks.fire({}); diff --git a/Telegram/SourceFiles/info/info_top_bar.h b/Telegram/SourceFiles/info/info_top_bar.h index 82396bcdf..3a92216b2 100644 --- a/Telegram/SourceFiles/info/info_top_bar.h +++ b/Telegram/SourceFiles/info/info_top_bar.h @@ -39,6 +39,7 @@ class TopBar : public Ui::RpWidget { public: TopBar( QWidget *parent, + not_null session, const style::InfoTopBar &st, SelectedItems &&items); @@ -130,6 +131,8 @@ private: template void registerToggleControlCallback(Widget *widget, IsVisible &&callback); + const not_null _session; + const style::InfoTopBar &_st; Ui::Animations::Simple _a_highlight; bool _highlight = false; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 0ff8df071..00e5aca2e 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -353,7 +353,11 @@ void WrapWidget::createTopBar() { auto selectedItems = _topBar ? _topBar->takeSelectedItems() : SelectedItems(Section::MediaType::kCount); - _topBar.create(this, TopBarStyle(wrapValue), std::move(selectedItems)); + _topBar.create( + this, + &session(), + TopBarStyle(wrapValue), + std::move(selectedItems)); _topBar->cancelSelectionRequests( ) | rpl::start_with_next([this] { _content->cancelSelection(); @@ -582,7 +586,7 @@ void WrapWidget::showTopBarMenu() { _topBarMenu = nullptr; controller->showSettings(type); }; - ::Settings::FillMenu(showOther, addAction); + ::Settings::FillMenu(&self->session(), showOther, addAction); } else { _topBarMenu = nullptr; return; diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 4dc05f78a..d1ee7add9 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1422,7 +1422,9 @@ void ListWidget::deleteItem(UniversalMsgId universalId) { DeleteMessagesBox *ListWidget::deleteItems(MessageIdsList &&items) { if (!items.empty()) { const auto box = Ui::show( - Box(std::move(items))).data(); + Box( + &_controller->session(), + std::move(items))).data(); setActionBoxWeak(box); return box; } diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp index 734b794ba..89a09479c 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp @@ -45,8 +45,7 @@ Widget::Widget( , _inner(setInnerWidget(::Settings::CreateSection( _type, this, - controller->parentController(), - _self))) { + controller->parentController()))) { _inner->sectionShowOther( ) | rpl::start_with_next([=](Type type) { controller->showSettings(type); diff --git a/Telegram/SourceFiles/passport/passport_form_controller.h b/Telegram/SourceFiles/passport/passport_form_controller.h index e05664745..aadb0cd90 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_controller.h @@ -325,6 +325,10 @@ public: not_null controller, const FormRequest &request); + not_null window() const { + return _controller; + } + void show(); UserData *bot() const; QString privacyPolicyUrl() const; diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index 8fbf26bbf..bd22ba3d7 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "boxes/passcode_box.h" #include "boxes/confirm_box.h" +#include "window/window_session_controller.h" #include "ui/toast/toast.h" #include "ui/rp_widget.h" #include "ui/countryinput.h" @@ -723,7 +724,7 @@ void PanelController::setupPassword() { auto fields = PasscodeBox::CloudFields(); fields.newAlgo = settings.newAlgo; fields.newSecureSecretAlgo = settings.newSecureAlgo; - auto box = show(Box(fields)); + auto box = show(Box(&_form->window()->session(), fields)); box->newPasswordSet( ) | rpl::filter([=](const QByteArray &password) { return !password.isEmpty(); diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 5f4456c38..a1ebd6169 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_button.h" #include "platform/platform_specific.h" #include "platform/platform_info.h" +#include "window/window_session_controller.h" #include "lang/lang_keys.h" #include "core/update_checker.h" #include "core/application.h" @@ -418,7 +419,9 @@ void SetupAnimations(not_null container) { }, container->lifetime()); } -void SetupPerformance(not_null container) { +void SetupPerformance( + not_null controller, + not_null container) { SetupAnimations(container); AddButton( @@ -430,10 +433,10 @@ void SetupPerformance(not_null container) { )->toggledValue( ) | rpl::filter([](bool enabled) { return (enabled != cAutoPlayGif()); - }) | rpl::start_with_next([](bool enabled) { + }) | rpl::start_with_next([=](bool enabled) { cSetAutoPlayGif(enabled); if (!cAutoPlayGif()) { - Auth().data().stopAutoplayAnimations(); + controller->session().data().stopAutoplayAnimations(); } Local::writeUserSettings(); }, container->lifetime()); @@ -456,16 +459,18 @@ void SetupSystemIntegration( AddSkip(container); } -Advanced::Advanced(QWidget *parent, UserData *self) +Advanced::Advanced( + QWidget *parent, + not_null controller) : Section(parent) { - setupContent(); + setupContent(controller); } rpl::producer Advanced::sectionShowOther() { return _showOther.events(); } -void Advanced::setupContent() { +void Advanced::setupContent(not_null controller) { const auto content = Ui::CreateChild(this); auto empty = true; @@ -495,8 +500,8 @@ void Advanced::setupContent() { SetupConnectionType(content); AddSkip(content); } - SetupDataStorage(content); - SetupAutoDownload(content); + SetupDataStorage(controller, content); + SetupAutoDownload(controller, content); SetupSystemIntegration(content, [=](Type type) { _showOther.fire_copy(type); }); @@ -504,7 +509,7 @@ void Advanced::setupContent() { AddDivider(content); AddSkip(content); AddSubsectionTitle(content, tr::lng_settings_performance()); - SetupPerformance(content); + SetupPerformance(controller, content); AddSkip(content); if (cAutoUpdate()) { diff --git a/Telegram/SourceFiles/settings/settings_advanced.h b/Telegram/SourceFiles/settings/settings_advanced.h index 60d8c3f44..998f3700d 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.h +++ b/Telegram/SourceFiles/settings/settings_advanced.h @@ -21,12 +21,14 @@ void SetupAnimations(not_null container); class Advanced : public Section { public: - explicit Advanced(QWidget *parent, UserData *self = nullptr); + Advanced( + QWidget *parent, + not_null controller); rpl::producer sectionShowOther() override; private: - void setupContent(); + void setupContent(not_null controller); rpl::event_stream _showOther; diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index 3bc9015ae..5a1e2cdd7 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -38,9 +38,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { -Calls::Calls(QWidget *parent, UserData *self) +Calls::Calls( + QWidget *parent, + not_null controller) : Section(parent) { - setupContent(); + setupContent(controller); } Calls::~Calls() { @@ -56,7 +58,7 @@ void Calls::sectionSaveChanges(FnMut done) { done(); } -void Calls::setupContent() { +void Calls::setupContent(not_null controller) { using namespace tgvoip; const auto content = Ui::CreateChild(this); diff --git a/Telegram/SourceFiles/settings/settings_calls.h b/Telegram/SourceFiles/settings/settings_calls.h index 7745f8ecc..9fc098400 100644 --- a/Telegram/SourceFiles/settings/settings_calls.h +++ b/Telegram/SourceFiles/settings/settings_calls.h @@ -11,27 +11,28 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" namespace Calls { - class Call; +class Call; } // namespace Calls namespace Ui { - class LevelMeter; -} +class LevelMeter; +} // namespace Ui namespace tgvoip { - class AudioInputTester; -} +class AudioInputTester; +} // namespace tgvoip namespace Settings { class Calls : public Section { public: - explicit Calls(QWidget *parent, UserData *self = nullptr); - virtual ~Calls(); - virtual void sectionSaveChanges(FnMut done) override; + Calls(QWidget *parent, not_null controller); + ~Calls(); + + void sectionSaveChanges(FnMut done) override; private: - void setupContent(); + void setupContent(not_null controller); void requestPermissionAndStartTestingMicrophone(); void startTestingMicrophone(); void stopTestingMicrophone(); @@ -43,6 +44,7 @@ private: std::unique_ptr _micTester; Ui::LevelMeter *_micTestLevel = nullptr; base::Timer _levelUpdateTimer; + }; } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index cb626ab93..7ad4da393 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "window/themes/window_theme_editor.h" #include "window/themes/window_theme.h" +#include "window/window_session_controller.h" #include "info/profile/info_profile_button.h" #include "storage/localstorage.h" #include "core/file_utilities.h" @@ -44,7 +45,9 @@ namespace Settings { class BackgroundRow : public Ui::RpWidget { public: - BackgroundRow(QWidget *parent); + BackgroundRow( + QWidget *parent, + not_null controller); protected: void paintEvent(QPaintEvent *e) override; @@ -106,9 +109,14 @@ private: }; -void ChooseFromFile(not_null parent); +void ChooseFromFile( + not_null<::Main::Session*> session, + not_null parent); -BackgroundRow::BackgroundRow(QWidget *parent) : RpWidget(parent) +BackgroundRow::BackgroundRow( + QWidget *parent, + not_null controller) +: RpWidget(parent) , _chooseFromGallery( this, tr::lng_settings_bg_from_gallery(tr::now), @@ -117,11 +125,11 @@ BackgroundRow::BackgroundRow(QWidget *parent) : RpWidget(parent) , _radial([=](crl::time now) { radialAnimationCallback(now); }) { updateImage(); - _chooseFromGallery->addClickHandler([] { - Ui::show(Box()); + _chooseFromGallery->addClickHandler([=] { + Ui::show(Box(&controller->session())); }); _chooseFromFile->addClickHandler([=] { - ChooseFromFile(this); + ChooseFromFile(&controller->session(), this); }); using Update = const Window::Theme::BackgroundUpdate; @@ -361,14 +369,17 @@ void DefaultTheme::checkedChangedHook(anim::type animated) { _radio.setChecked(checked(), animated); } -void ChooseFromFile(not_null parent) { +void ChooseFromFile( + not_null<::Main::Session*> session, + not_null parent) { const auto &imgExtensions = cImgExtensions(); auto filters = QStringList( qsl("Theme files (*.tdesktop-theme *.tdesktop-palette *") + imgExtensions.join(qsl(" *")) + qsl(")")); filters.push_back(FileDialog::AllFilesFilter()); - const auto callback = [=](const FileDialog::OpenResult &result) { + const auto callback = crl::guard(session, [=]( + const FileDialog::OpenResult &result) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { return; } @@ -396,8 +407,8 @@ void ChooseFromFile(not_null parent) { std::make_unique( std::move(image), "JPG"))); - Ui::show(Box(local)); - }; + Ui::show(Box(session, local)); + }); FileDialog::GetOpenPath( parent.get(), tr::lng_choose_image(tr::now), @@ -492,7 +503,9 @@ void SetupStickersEmoji(not_null container) { AddSkip(container, st::settingsCheckboxesSkip); } -void SetupMessages(not_null container) { +void SetupMessages( + not_null controller, + not_null container) { AddDivider(container); AddSkip(container); @@ -512,7 +525,7 @@ void SetupMessages(not_null container) { QMargins(0, skip, 0, skip))); const auto group = std::make_shared>( - Auth().settings().sendSubmitWay()); + controller->session().settings().sendSubmitWay()); const auto add = [&](SendByType value, const QString &text) { inner->add( object_ptr>( @@ -532,8 +545,8 @@ void SetupMessages(not_null container) { ? tr::lng_settings_send_cmdenter(tr::now) : tr::lng_settings_send_ctrlenter(tr::now))); - group->setChangedCallback([](SendByType value) { - Auth().settings().setSendSubmitWay(value); + group->setChangedCallback([=](SendByType value) { + controller->session().settings().setSendSubmitWay(value); if (App::main()) { App::main()->ctrlEnterSubmitUpdated(); } @@ -543,33 +556,38 @@ void SetupMessages(not_null container) { AddSkip(inner, st::settingsCheckboxesSkip); } -void SetupExport(not_null container) { +void SetupExport( + not_null controller, + not_null container) { AddButton( container, tr::lng_settings_export_data(), st::settingsButton - )->addClickHandler([] { + )->addClickHandler([=] { + const auto session = &controller->session(); Ui::hideSettingsAndLayer(); App::CallDelayed( st::boxDuration, - &Auth(), - [] { Auth().data().startExport(); }); + session, + [=] { session->data().startExport(); }); }); } -void SetupLocalStorage(not_null container) { +void SetupLocalStorage( + not_null controller, + not_null container) { AddButton( container, tr::lng_settings_manage_local_storage(), st::settingsButton - )->addClickHandler([] { - LocalStorageBox::Show( - &Auth().data().cache(), - &Auth().data().cacheBigFile()); + )->addClickHandler([=] { + LocalStorageBox::Show(&controller->session()); }); } -void SetupDataStorage(not_null container) { +void SetupDataStorage( + not_null controller, + not_null container) { using namespace rpl::mappers; AddDivider(container); @@ -623,13 +641,15 @@ void SetupDataStorage(not_null container) { }, ask->lifetime()); - SetupLocalStorage(container); - SetupExport(container); + SetupLocalStorage(controller, container); + SetupExport(controller, container); AddSkip(container, st::settingsCheckboxesSkip); } -void SetupAutoDownload(not_null container) { +void SetupAutoDownload( + not_null controller, + not_null container) { AddDivider(container); AddSkip(container); @@ -642,7 +662,7 @@ void SetupAutoDownload(not_null container) { std::move(label), st::settingsButton )->addClickHandler([=] { - Ui::show(Box(source)); + Ui::show(Box(&controller->session(), source)); }); }; add(tr::lng_media_auto_in_private(), Source::User); @@ -652,14 +672,16 @@ void SetupAutoDownload(not_null container) { AddSkip(container, st::settingsCheckboxesSkip); } -void SetupChatBackground(not_null container) { +void SetupChatBackground( + not_null controller, + not_null container) { AddDivider(container); AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_section_background()); container->add( - object_ptr(container), + object_ptr(container, controller), st::settingsBackgroundPadding); const auto skipTop = st::settingsCheckbox.margin.top(); @@ -925,10 +947,12 @@ void SetupThemeOptions(not_null container) { AddSkip(container); } -void SetupSupportSwitchSettings(not_null container) { +void SetupSupportSwitchSettings( + not_null controller, + not_null container) { using SwitchType = Support::SwitchSettings; const auto group = std::make_shared>( - Auth().settings().supportSwitch()); + controller->session().settings().supportSwitch()); const auto add = [&](SwitchType value, const QString &label) { container->add( object_ptr>( @@ -942,13 +966,15 @@ void SetupSupportSwitchSettings(not_null container) { add(SwitchType::None, "Just send the reply"); add(SwitchType::Next, "Send and switch to next"); add(SwitchType::Previous, "Send and switch to previous"); - group->setChangedCallback([](SwitchType value) { - Auth().settings().setSupportSwitch(value); + group->setChangedCallback([=](SwitchType value) { + controller->session().settings().setSupportSwitch(value); Local::writeUserSettings(); }); } -void SetupSupportChatsLimitSlice(not_null container) { +void SetupSupportChatsLimitSlice( + not_null controller, + not_null container) { constexpr auto kDayDuration = 24 * 60 * 60; struct Option { int days = 0; @@ -961,7 +987,7 @@ void SetupSupportChatsLimitSlice(not_null container) { { 365, "1 year" }, { 0, "All of them" }, }; - const auto current = Auth().settings().supportChatsTimeSlice(); + const auto current = controller->session().settings().supportChatsTimeSlice(); const auto days = current / kDayDuration; const auto best = ranges::min_element( options, @@ -980,12 +1006,15 @@ void SetupSupportChatsLimitSlice(not_null container) { st::settingsSendTypePadding); } group->setChangedCallback([=](int days) { - Auth().settings().setSupportChatsTimeSlice(days * kDayDuration); + controller->session().settings().setSupportChatsTimeSlice( + days * kDayDuration); Local::writeUserSettings(); }); } -void SetupSupport(not_null container) { +void SetupSupport( + not_null controller, + not_null container) { AddSkip(container); AddSubsectionTitle(container, rpl::single(qsl("Support settings"))); @@ -1001,7 +1030,7 @@ void SetupSupport(not_null container) { std::move(wrap), QMargins(0, skip, 0, skip))); - SetupSupportSwitchSettings(inner); + SetupSupportSwitchSettings(controller, inner); AddSkip(inner, st::settingsCheckboxesSkip); @@ -1009,12 +1038,13 @@ void SetupSupport(not_null container) { object_ptr( inner, "Enable templates autocomplete", - Auth().settings().supportTemplatesAutocomplete(), + controller->session().settings().supportTemplatesAutocomplete(), st::settingsCheckbox), st::settingsSendTypePadding )->checkedChanges( ) | rpl::start_with_next([=](bool checked) { - Auth().settings().setSupportTemplatesAutocomplete(checked); + controller->session().settings().setSupportTemplatesAutocomplete( + checked); Local::writeUserSettings(); }, inner->lifetime()); @@ -1022,26 +1052,25 @@ void SetupSupport(not_null container) { AddSubsectionTitle(inner, rpl::single(qsl("Load chats for a period"))); - SetupSupportChatsLimitSlice(inner); + SetupSupportChatsLimitSlice(controller, inner); AddSkip(inner, st::settingsCheckboxesSkip); AddSkip(inner); } -Chat::Chat(QWidget *parent, not_null self) -: Section(parent) -, _self(self) { - setupContent(); +Chat::Chat(QWidget *parent, not_null controller) +: Section(parent) { + setupContent(controller); } -void Chat::setupContent() { +void Chat::setupContent(not_null controller) { const auto content = Ui::CreateChild(this); SetupThemeOptions(content); - SetupChatBackground(content); + SetupChatBackground(controller, content); SetupStickersEmoji(content); - SetupMessages(content); + SetupMessages(controller, content); Ui::ResizeFitChild(this, content); } diff --git a/Telegram/SourceFiles/settings/settings_chat.h b/Telegram/SourceFiles/settings/settings_chat.h index f9f2f9818..578210d77 100644 --- a/Telegram/SourceFiles/settings/settings_chat.h +++ b/Telegram/SourceFiles/settings/settings_chat.h @@ -11,19 +11,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { -void SetupDataStorage(not_null container); -void SetupAutoDownload(not_null container); +void SetupDataStorage( + not_null controller, + not_null container); +void SetupAutoDownload( + not_null controller, + not_null container); void SetupDefaultThemes(not_null container); -void SetupSupport(not_null container); +void SetupSupport( + not_null controller, + not_null container); class Chat : public Section { public: - Chat(QWidget *parent, not_null self); + Chat(QWidget *parent, not_null controller); private: - void setupContent(); - - not_null _self; + void setupContent(not_null controller); }; diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index f4522887a..378fa8a7d 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -27,8 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { auto GenerateCodes() { - auto codes = std::map>(); - codes.emplace(qsl("debugmode"), [] { + auto codes = std::map>(); + codes.emplace(qsl("debugmode"), [](::Main::Session *session) { QString text = Logs::DebugEnabled() ? qsl("Do you want to disable DEBUG logs?") : qsl("Do you want to enable DEBUG logs?\n\n" @@ -37,24 +37,24 @@ auto GenerateCodes() { Core::App().switchDebugMode(); })); }); - codes.emplace(qsl("viewlogs"), [] { + codes.emplace(qsl("viewlogs"), [](::Main::Session *session) { File::ShowInFolder(cWorkingDir() + "log.txt"); }); - codes.emplace(qsl("testmode"), [] { + codes.emplace(qsl("testmode"), [](::Main::Session *session) { auto text = cTestMode() ? qsl("Do you want to disable TEST mode?") : qsl("Do you want to enable TEST mode?\n\nYou will be switched to test cloud."); Ui::show(Box(text, [] { Core::App().switchTestMode(); })); }); if (!Core::UpdaterDisabled()) { - codes.emplace(qsl("testupdate"), [] { + codes.emplace(qsl("testupdate"), [](::Main::Session *session) { Core::UpdateChecker().test(); }); } - codes.emplace(qsl("loadlang"), [] { + codes.emplace(qsl("loadlang"), [](::Main::Session *session) { Lang::CurrentCloudManager().switchToLanguage({ qsl("#custom") }); }); - codes.emplace(qsl("debugfiles"), [] { + codes.emplace(qsl("debugfiles"), [](::Main::Session *session) { if (!Logs::DebugEnabled()) { return; } @@ -65,39 +65,39 @@ auto GenerateCodes() { } Ui::show(Box(DebugLogging::FileLoader() ? qsl("Enabled file download logging") : qsl("Disabled file download logging"))); }); - codes.emplace(qsl("crashplease"), [] { + codes.emplace(qsl("crashplease"), [](::Main::Session *session) { Unexpected("Crashed in Settings!"); }); - codes.emplace(qsl("workmode"), [] { + codes.emplace(qsl("workmode"), [](::Main::Session *session) { auto text = Global::DialogsModeEnabled() ? qsl("Disable work mode?") : qsl("Enable work mode?"); Ui::show(Box(text, [] { Core::App().switchWorkMode(); })); }); - codes.emplace(qsl("moderate"), [] { + codes.emplace(qsl("moderate"), [](::Main::Session *session) { auto text = Global::ModerateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?"); - Ui::show(Box(text, []() { + Ui::show(Box(text, [] { Global::SetModerateModeEnabled(!Global::ModerateModeEnabled()); Local::writeUserSettings(); Ui::hideLayer(); })); }); - codes.emplace(qsl("getdifference"), [] { + codes.emplace(qsl("getdifference"), [](::Main::Session *session) { if (auto main = App::main()) { main->getDifference(); } }); - codes.emplace(qsl("loadcolors"), [] { + codes.emplace(qsl("loadcolors"), [](::Main::Session *session) { FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open palette file", "Palette (*.tdesktop-palette)", [](const FileDialog::OpenResult &result) { if (!result.paths.isEmpty()) { Window::Theme::Apply(result.paths.front()); } }); }); - codes.emplace(qsl("edittheme"), [] { + codes.emplace(qsl("edittheme"), [](::Main::Session *session) { Window::Theme::Editor::Start(); }); - codes.emplace(qsl("videoplayer"), [] { + codes.emplace(qsl("videoplayer"), [](::Main::Session *session) { auto text = cUseExternalVideoPlayer() ? qsl("Use internal video player?") : qsl("Use external video player?"); Ui::show(Box(text, [] { cSetUseExternalVideoPlayer(!cUseExternalVideoPlayer()); @@ -105,7 +105,7 @@ auto GenerateCodes() { Ui::hideLayer(); })); }); - codes.emplace(qsl("endpoints"), [] { + codes.emplace(qsl("endpoints"), [](::Main::Session *session) { FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open DC endpoints", "DC Endpoints (*.tdesktop-endpoints)", [](const FileDialog::OpenResult &result) { if (!result.paths.isEmpty()) { if (!Core::App().dcOptions()->loadFromFile(result.paths.front())) { @@ -114,12 +114,12 @@ auto GenerateCodes() { } }); }); - codes.emplace(qsl("registertg"), [] { + codes.emplace(qsl("registertg"), [](::Main::Session *session) { Platform::RegisterCustomScheme(); Ui::Toast::Show("Forced custom scheme register."); }); - codes.emplace(qsl("export"), [] { - Auth().data().startExport(); + codes.emplace(qsl("export"), [](::Main::Session *session) { + session->data().startExport(); }); auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter(); @@ -132,28 +132,28 @@ auto GenerateCodes() { qsl("call_end"), }; for (auto &key : audioKeys) { - codes.emplace(key, [audioFilters, key] { - if (!Main::Session::Exists()) { + codes.emplace(key, [=](::Main::Session *session) { + if (!session) { return; } - FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, [key](const FileDialog::OpenResult &result) { + FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, crl::guard(session, [=](const FileDialog::OpenResult &result) { if (Main::Session::Exists() && !result.paths.isEmpty()) { auto track = Media::Audio::Current().createTrack(); track->fillFromFile(result.paths.front()); if (track->failed()) { Ui::show(Box("Could not audio :( Errors in 'log.txt'.")); } else { - Auth().settings().setSoundOverride(key, result.paths.front()); + session->settings().setSoundOverride(key, result.paths.front()); Local::writeUserSettings(); } } - }); + })); }); } - codes.emplace(qsl("sounds_reset"), [] { - if (Main::Session::Exists()) { - Auth().settings().clearSoundOverrides(); + codes.emplace(qsl("sounds_reset"), [](::Main::Session *session) { + if (session) { + session->settings().clearSoundOverrides(); Local::writeUserSettings(); Ui::show(Box("All sound overrides were reset.")); } @@ -161,7 +161,7 @@ auto GenerateCodes() { return codes; } -void CodesFeedString(const QString &text) { +void CodesFeedString(::Main::Session *session, const QString &text) { static const auto codes = GenerateCodes(); static auto secret = QString(); @@ -172,7 +172,7 @@ void CodesFeedString(const QString &text) { auto found = false; for (const auto &[key, method] : codes) { if (piece == key) { - method(); + method(session); from = size; found = true; break; diff --git a/Telegram/SourceFiles/settings/settings_codes.h b/Telegram/SourceFiles/settings/settings_codes.h index 27798adc5..850daed45 100644 --- a/Telegram/SourceFiles/settings/settings_codes.h +++ b/Telegram/SourceFiles/settings/settings_codes.h @@ -7,8 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +namespace Main { +class Session; +} // namespace Main + namespace Settings { -void CodesFeedString(const QString &text); +void CodesFeedString(::Main::Session *session, const QString &text); } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index a7cc1022c..16cf208e0 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -30,23 +30,22 @@ namespace Settings { object_ptr
CreateSection( Type type, not_null parent, - Window::SessionController *controller, - UserData *self) { + not_null controller) { switch (type) { case Type::Main: - return object_ptr
(parent, controller, self); + return object_ptr
(parent, controller); case Type::Information: - return object_ptr(parent, controller, self); + return object_ptr(parent, controller); case Type::Notifications: - return object_ptr(parent, self); + return object_ptr(parent, controller); case Type::PrivacySecurity: - return object_ptr(parent, self); + return object_ptr(parent, controller); case Type::Advanced: - return object_ptr(parent, self); + return object_ptr(parent, controller); case Type::Chat: - return object_ptr(parent, self); + return object_ptr(parent, controller); case Type::Calls: - return object_ptr(parent, self); + return object_ptr(parent, controller); } Unexpected("Settings section type in Widget::createInnerWidget."); } @@ -170,8 +169,11 @@ void AddSubsectionTitle( st::settingsSubsectionTitlePadding); } -void FillMenu(Fn showOther, MenuCallback addAction) { - if (!Auth().supportMode()) { +void FillMenu( + not_null<::Main::Session*> session, + Fn showOther, + MenuCallback addAction) { + if (!session->supportMode()) { addAction( tr::lng_settings_information(tr::now), [=] { showOther(Type::Information); }); diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index 204a53d52..b0999709d 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" +namespace Main { +class Session; +} // namespace Main + namespace Ui { class VerticalLayout; } // namespace Ui @@ -60,8 +64,7 @@ public: object_ptr
CreateSection( Type type, not_null parent, - Window::SessionController *controller = nullptr, - UserData *self = nullptr); + not_null controller); void AddSkip(not_null container); void AddSkip(not_null container, int skip); @@ -96,6 +99,7 @@ using MenuCallback = Fn handler)>; void FillMenu( + not_null<::Main::Session*> session, Fn showOther, MenuCallback addAction); diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 0572a773d..cc880344a 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_button.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "window/window_session_controller.h" #include "apiwrap.h" #include "core/file_utilities.h" #include "styles/style_boxes.h" @@ -79,7 +80,9 @@ void SetupPhoto( Box(image, tr::lng_settings_crop_profile(tr::now))); box->ready( ) | rpl::start_with_next([=](QImage &&image) { - Auth().api().uploadPeerPhoto(self, std::move(image)); + self->session().api().uploadPeerPhoto( + self, + std::move(image)); }, box->lifetime()); }; FileDialog::GetOpenPath( @@ -229,7 +232,7 @@ void SetupRows( tr::lng_settings_phone_label(), Info::Profile::PhoneValue(self), tr::lng_profile_copy_phone(tr::now), - [] { Ui::show(Box()); }, + [=] { Ui::show(Box(&self->session())); }, st::settingsInfoPhone); auto username = Info::Profile::UsernameValue(self); @@ -333,7 +336,7 @@ BioManager SetupBio( countdown->setText(QString::number(countLeft)); }; const auto save = [=](FnMut done) { - Auth().api().saveSelfBio( + self->session().api().saveSelfBio( TextUtilities::PrepareForSending(bio->getLastText()), std::move(done)); }; @@ -408,10 +411,8 @@ BioManager SetupBio( Information::Information( QWidget *parent, - not_null controller, - not_null self) -: Section(parent) -, _self(self) { + not_null controller) +: Section(parent) { setupContent(controller); } @@ -423,13 +424,15 @@ Information::Information( // _save(std::move(done)); //} -void Information::setupContent(not_null controller) { +void Information::setupContent( + not_null controller) { const auto content = Ui::CreateChild(this); - SetupPhoto(content, controller, _self); - SetupRows(content, _self); - SetupBio(content, _self); - //auto manager = SetupBio(content, _self); + const auto self = controller->session().user(); + SetupPhoto(content, controller, self); + SetupRows(content, self); + SetupBio(content, self); + //auto manager = SetupBio(content, self); //_canSaveChanges = std::move(manager.canSave); //_save = std::move(manager.save); diff --git a/Telegram/SourceFiles/settings/settings_information.h b/Telegram/SourceFiles/settings/settings_information.h index 0bd591721..b450101c8 100644 --- a/Telegram/SourceFiles/settings/settings_information.h +++ b/Telegram/SourceFiles/settings/settings_information.h @@ -15,13 +15,11 @@ class Information : public Section { public: Information( QWidget *parent, - not_null controller, - not_null self); + not_null controller); private: void setupContent(not_null controller); - not_null _self; //rpl::variable _canSaveChanges; //Fn done)> _save; diff --git a/Telegram/SourceFiles/settings/settings_intro.cpp b/Telegram/SourceFiles/settings/settings_intro.cpp index bb994caaf..7897ee5f1 100644 --- a/Telegram/SourceFiles/settings/settings_intro.cpp +++ b/Telegram/SourceFiles/settings/settings_intro.cpp @@ -345,7 +345,7 @@ void IntroWidget::resizeEvent(QResizeEvent *e) { } void IntroWidget::keyPressEvent(QKeyEvent *e) { - CodesFeedString(e->text()); + CodesFeedString(nullptr, e->text()); return RpWidget::keyPressEvent(e); } diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 861afef9a..413b64f89 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -55,6 +55,7 @@ void SetupLanguageButton( } void SetupSections( + not_null controller, not_null container, Fn showOther) { AddDivider(container); @@ -71,8 +72,8 @@ void SetupSections( icon )->addClickHandler([=] { showOther(type); }); }; - if (Auth().supportMode()) { - SetupSupport(container); + if (controller->session().supportMode()) { + SetupSupport(controller, container); AddDivider(container); AddSkip(container); @@ -227,51 +228,50 @@ void SetupFaq(not_null container, bool icon) { )->addClickHandler(OpenFaq); } -void SetupHelp(not_null container) { +void SetupHelp( + not_null controller, + not_null container) { AddDivider(container); AddSkip(container); SetupFaq(container); - if (::Main::Session::Exists()) { - const auto button = AddButton( - container, - tr::lng_settings_ask_question(), - st::settingsSectionButton); - button->addClickHandler([=] { - const auto ready = crl::guard(button, [](const MTPUser &data) { - if (const auto user = Auth().data().processUser(data)) { - Ui::showPeerHistory(user, ShowAtUnreadMsgId); - } - }); - const auto sure = crl::guard(button, [=] { - Auth().api().requestSupportContact(ready); - }); - auto box = Box( - tr::lng_settings_ask_sure(tr::now), - tr::lng_settings_ask_ok(tr::now), - tr::lng_settings_faq_button(tr::now), - sure, - OpenFaq); - box->setStrictCancel(true); - Ui::show(std::move(box)); + const auto button = AddButton( + container, + tr::lng_settings_ask_question(), + st::settingsSectionButton); + button->addClickHandler([=] { + const auto ready = crl::guard(button, [=](const MTPUser &data) { + if (const auto user = controller->session().data().processUser(data)) { + Ui::showPeerHistory(user, ShowAtUnreadMsgId); + } }); - } + const auto sure = crl::guard(button, [=] { + controller->session().api().requestSupportContact(ready); + }); + auto box = Box( + tr::lng_settings_ask_sure(tr::now), + tr::lng_settings_ask_ok(tr::now), + tr::lng_settings_faq_button(tr::now), + sure, + OpenFaq); + box->setStrictCancel(true); + Ui::show(std::move(box)); + }); AddSkip(container); } Main::Main( QWidget *parent, - not_null controller, - not_null self) + not_null controller) : Section(parent) -, _self(self) { +, _controller(controller) { setupContent(controller); } void Main::keyPressEvent(QKeyEvent *e) { - CodesFeedString(e->text()); + CodesFeedString(&_controller->session(), e->text()); return Section::keyPressEvent(e); } @@ -280,11 +280,11 @@ void Main::setupContent(not_null controller) { const auto cover = content->add(object_ptr( content, - _self, + controller->session().user(), controller)); cover->setOnlineCount(rpl::single(0)); - SetupSections(content, [=](Type type) { + SetupSections(controller, content, [=](Type type) { _showOther.fire_copy(type); }); if (HasInterfaceScale()) { @@ -293,7 +293,7 @@ void Main::setupContent(not_null controller) { SetupInterfaceScale(content); AddSkip(content); } - SetupHelp(content); + SetupHelp(controller, content); Ui::ResizeFitChild(this, content); diff --git a/Telegram/SourceFiles/settings/settings_main.h b/Telegram/SourceFiles/settings/settings_main.h index 9724780f6..5a68bd197 100644 --- a/Telegram/SourceFiles/settings/settings_main.h +++ b/Telegram/SourceFiles/settings/settings_main.h @@ -32,10 +32,7 @@ void SetupFaq( class Main : public Section { public: - Main( - QWidget *parent, - not_null controller, - not_null self); + Main(QWidget *parent, not_null controller); rpl::producer sectionShowOther() override; @@ -45,7 +42,7 @@ protected: private: void setupContent(not_null controller); - not_null _self; + const not_null _controller; rpl::event_stream _showOther; }; diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 1465bcf95..71ded811c 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_button.h" #include "storage/localstorage.h" #include "window/notifications_manager.h" +#include "window/window_session_controller.h" #include "platform/platform_notifications_manager.h" #include "platform/platform_info.h" #include "mainwindow.h" @@ -42,7 +43,9 @@ using ChangeType = Window::Notifications::ChangeType; class NotificationsCount : public Ui::RpWidget { public: - NotificationsCount(QWidget *parent); + NotificationsCount( + QWidget *parent, + not_null controller); void setCount(int count); @@ -72,6 +75,8 @@ private: void prepareNotificationSampleLarge(); void prepareNotificationSampleUserpic(); + const not_null _controller; + QPixmap _notificationSampleUserpic; QPixmap _notificationSampleSmall; QPixmap _notificationSampleLarge; @@ -114,8 +119,11 @@ private: }; -NotificationsCount::NotificationsCount(QWidget *parent) -: _chosenCorner(Global::NotificationsCorner()) +NotificationsCount::NotificationsCount( + QWidget *parent, + not_null controller) +: _controller(controller) +, _chosenCorner(Global::NotificationsCorner()) , _oldCount(CurrentCount()) { setMouseTracking(true); @@ -176,7 +184,8 @@ void NotificationsCount::setCount(int count) { if (count != Global::NotificationsCount()) { Global::SetNotificationsCount(count); - Auth().notifications().settingsChanged().notify(ChangeType::MaxCount); + _controller->session().notifications().settingsChanged().notify( + ChangeType::MaxCount); Local::writeUserSettings(); } } @@ -340,7 +349,8 @@ void NotificationsCount::setOverCorner(Notify::ScreenCorner corner) { _isOverCorner = true; setCursor(style::cur_pointer); Global::SetNotificationsDemoIsShown(true); - Auth().notifications().settingsChanged().notify(ChangeType::DemoIsShown); + _controller->session().notifications().settingsChanged().notify( + ChangeType::DemoIsShown); } _overCorner = corner; @@ -375,10 +385,10 @@ void NotificationsCount::clearOverCorner() { _isOverCorner = false; setCursor(style::cur_default); Global::SetNotificationsDemoIsShown(false); - Auth().notifications().settingsChanged().notify(ChangeType::DemoIsShown); + _controller->session().notifications().settingsChanged().notify(ChangeType::DemoIsShown); - for_const (auto &samples, _cornerSamples) { - for_const (auto widget, samples) { + for_const (const auto &samples, _cornerSamples) { + for_const (const auto widget, samples) { widget->hideFast(); } } @@ -392,13 +402,17 @@ void NotificationsCount::mousePressEvent(QMouseEvent *e) { void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) { auto isDownCorner = base::take(_isDownCorner); - if (isDownCorner && _isOverCorner && _downCorner == _overCorner && _downCorner != _chosenCorner) { + if (isDownCorner + && _isOverCorner + && _downCorner == _overCorner + && _downCorner != _chosenCorner) { _chosenCorner = _downCorner; update(); if (_chosenCorner != Global::NotificationsCorner()) { Global::SetNotificationsCorner(_chosenCorner); - Auth().notifications().settingsChanged().notify(ChangeType::Corner); + _controller->session().notifications().settingsChanged().notify( + ChangeType::Corner); Local::writeUserSettings(); } } @@ -487,7 +501,9 @@ void NotificationsCount::SampleWidget::destroyDelayed() { #endif // Q_OS_LINUX32 || Q_OS_LINUX64 } -void SetupAdvancedNotifications(not_null container) { +void SetupAdvancedNotifications( + not_null controller, + not_null container) { AddSkip(container, st::settingsCheckboxesSkip); AddDivider(container); AddSkip(container, st::settingsCheckboxesSkip); @@ -495,7 +511,7 @@ void SetupAdvancedNotifications(not_null container) { AddSkip(container, st::settingsCheckboxesSkip); const auto position = container->add( - object_ptr(container)); + object_ptr(container, controller)); AddSkip(container, st::settingsCheckboxesSkip); AddSubsectionTitle(container, tr::lng_settings_notifications_count()); @@ -514,9 +530,12 @@ void SetupAdvancedNotifications(not_null container) { AddSkip(container, st::settingsCheckboxesSkip); } -void SetupNotificationsContent(not_null container) { +void SetupNotificationsContent( + not_null controller, + not_null container) { AddSubsectionTitle(container, tr::lng_settings_notify_title()); + const auto session = &controller->session(); const auto checkbox = [&](const QString &label, bool checked) { return object_ptr( container, @@ -556,10 +575,10 @@ void SetupNotificationsContent(not_null container) { const auto muted = addCheckbox( tr::lng_settings_include_muted(tr::now), - Auth().settings().includeMutedCounter()); + session->settings().includeMutedCounter()); const auto count = addCheckbox( tr::lng_settings_count_unread(tr::now), - Auth().settings().countUnreadMessages()); + session->settings().countUnreadMessages()); AddSkip(container, st::settingsCheckboxesSkip); @@ -569,32 +588,32 @@ void SetupNotificationsContent(not_null container) { const auto joined = addCheckbox( tr::lng_settings_events_joined(tr::now), - !Auth().api().contactSignupSilentCurrent().value_or(false)); - Auth().api().contactSignupSilent( + !session->api().contactSignupSilentCurrent().value_or(false)); + session->api().contactSignupSilent( ) | rpl::start_with_next([=](bool silent) { joined->setChecked(!silent); }, joined->lifetime()); joined->checkedChanges( - ) | rpl::filter([](bool enabled) { - const auto silent = Auth().api().contactSignupSilentCurrent(); + ) | rpl::filter([=](bool enabled) { + const auto silent = session->api().contactSignupSilentCurrent(); return (enabled == silent.value_or(false)); }) | rpl::start_with_next([=](bool enabled) { - Auth().api().saveContactSignupSilent(!enabled); + session->api().saveContactSignupSilent(!enabled); }, joined->lifetime()); const auto pinned = addCheckbox( tr::lng_settings_events_pinned(tr::now), - Auth().settings().notifyAboutPinned()); - Auth().settings().notifyAboutPinnedChanges( + session->settings().notifyAboutPinned()); + session->settings().notifyAboutPinnedChanges( ) | rpl::start_with_next([=](bool notify) { pinned->setChecked(notify); }, pinned->lifetime()); pinned->checkedChanges( - ) | rpl::filter([](bool notify) { - return (notify != Auth().settings().notifyAboutPinned()); + ) | rpl::filter([=](bool notify) { + return (notify != session->settings().notifyAboutPinned()); }) | rpl::start_with_next([=](bool notify) { - Auth().settings().setNotifyAboutPinned(notify); - Auth().saveSettingsDelayed(); + session->settings().setNotifyAboutPinned(notify); + session->saveSettingsDelayed(); }, joined->lifetime()); const auto nativeText = [&] { @@ -629,7 +648,7 @@ void SetupNotificationsContent(not_null container) { ? advancedSlide->entity() : nullptr; if (advancedWrap) { - SetupAdvancedNotifications(advancedWrap); + SetupAdvancedNotifications(controller, advancedWrap); } if (!name->entity()->checked()) { @@ -644,9 +663,9 @@ void SetupNotificationsContent(not_null container) { } using Change = Window::Notifications::ChangeType; - const auto changed = [](Change change) { + const auto changed = [=](Change change) { Local::writeUserSettings(); - Auth().notifications().settingsChanged().notify(change); + session->notifications().settingsChanged().notify(change); }; desktop->checkedChanges( ) | rpl::filter([](bool checked) { @@ -695,23 +714,23 @@ void SetupNotificationsContent(not_null container) { }, sound->lifetime()); muted->checkedChanges( - ) | rpl::filter([](bool checked) { - return (checked != Auth().settings().includeMutedCounter()); + ) | rpl::filter([=](bool checked) { + return (checked != session->settings().includeMutedCounter()); }) | rpl::start_with_next([=](bool checked) { - Auth().settings().setIncludeMutedCounter(checked); + session->settings().setIncludeMutedCounter(checked); changed(Change::IncludeMuted); }, muted->lifetime()); count->checkedChanges( - ) | rpl::filter([](bool checked) { - return (checked != Auth().settings().countUnreadMessages()); + ) | rpl::filter([=](bool checked) { + return (checked != session->settings().countUnreadMessages()); }) | rpl::start_with_next([=](bool checked) { - Auth().settings().setCountUnreadMessages(checked); + session->settings().setCountUnreadMessages(checked); changed(Change::CountMessages); }, count->lifetime()); base::ObservableViewer( - Auth().notifications().settingsChanged() + session->notifications().settingsChanged() ) | rpl::start_with_next([=](Change change) { if (change == Change::DesktopEnabled) { desktop->setChecked(Global::DesktopNotify()); @@ -734,7 +753,7 @@ void SetupNotificationsContent(not_null container) { Global::SetNativeNotifications(checked); Local::writeUserSettings(); - Auth().notifications().createManager(); + session->notifications().createManager(); if (advancedSlide) { advancedSlide->toggle( @@ -745,11 +764,13 @@ void SetupNotificationsContent(not_null container) { } } -void SetupNotifications(not_null container) { +void SetupNotifications( + not_null controller, + not_null container) { AddSkip(container, st::settingsCheckboxesSkip); auto wrap = object_ptr(container); - SetupNotificationsContent(wrap.data()); + SetupNotificationsContent(controller, wrap.data()); container->add(object_ptr( container, @@ -760,16 +781,18 @@ void SetupNotifications(not_null container) { } // namespace -Notifications::Notifications(QWidget *parent, not_null self) -: Section(parent) -, _self(self) { - setupContent(); +Notifications::Notifications( + QWidget *parent, + not_null controller) +: Section(parent) { + setupContent(controller); } -void Notifications::setupContent() { +void Notifications::setupContent( + not_null controller) { const auto content = Ui::CreateChild(this); - SetupNotifications(content); + SetupNotifications(controller, content); Ui::ResizeFitChild(this, content); } diff --git a/Telegram/SourceFiles/settings/settings_notifications.h b/Telegram/SourceFiles/settings/settings_notifications.h index 4bcdaba51..38327de92 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.h +++ b/Telegram/SourceFiles/settings/settings_notifications.h @@ -13,12 +13,12 @@ namespace Settings { class Notifications : public Section { public: - Notifications(QWidget *parent, not_null self); + Notifications( + QWidget *parent, + not_null controller); private: - void setupContent(); - - not_null _self; + void setupContent(not_null controller); }; diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 7ea0e13d5..5ebfd852c 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/image/image_prepare.h" #include "window/section_widget.h" +#include "window/window_session_controller.h" #include "boxes/peer_list_controllers.h" #include "boxes/confirm_box.h" #include "settings/settings_privacy_security.h" @@ -154,6 +155,11 @@ AdminLog::OwnedItem GenerateForwardedItem( } // namespace +BlockedBoxController::BlockedBoxController( + not_null window) +: _window(window) { +} + void BlockedBoxController::prepare() { delegate()->peerListSetTitle(tr::lng_blocked_list_title()); setDescriptionText(tr::lng_contacts_loading(tr::now)); @@ -166,7 +172,7 @@ void BlockedBoxController::prepare() { })); _loadRequestId = -1; - Auth().api().blockedUsersSlice( + _window->session().api().blockedUsersSlice( ) | rpl::take( 1 ) | rpl::start_with_next([=](const ApiWrap::BlockedUsersSlice &result) { @@ -193,8 +199,8 @@ void BlockedBoxController::loadMoreRows() { )).done([=](const MTPcontacts_Blocked &result) { _loadRequestId = 0; - auto handleContactsBlocked = [](auto &list) { - Auth().data().processUsers(list.vusers()); + auto handleContactsBlocked = [&](auto &list) { + _window->session().data().processUsers(list.vusers()); return list.vblocked().v; }; switch (result.type()) { @@ -222,7 +228,7 @@ void BlockedBoxController::rowActionClicked(not_null row) { auto user = row->peer()->asUser(); Expects(user != nullptr); - Auth().api().unblockUser(user); + _window->session().api().unblockUser(user); } void BlockedBoxController::receivedUsers(const QVector &result) { @@ -233,7 +239,7 @@ void BlockedBoxController::receivedUsers(const QVector &resul _offset += result.size(); for (const auto &item : result) { item.match([&](const MTPDcontactBlocked &data) { - if (const auto user = Auth().data().userLoaded(data.vuser_id().v)) { + if (const auto user = _window->session().data().userLoaded(data.vuser_id().v)) { appendRow(user); user->setIsBlocked(true); } @@ -254,11 +260,13 @@ void BlockedBoxController::handleBlockedEvent(not_null user) { } } -void BlockedBoxController::BlockNewUser() { +void BlockedBoxController::BlockNewUser( + not_null window) { auto controller = std::make_unique(); - auto initBox = [controller = controller.get()](not_null box) { - controller->setBlockUserCallback([box](not_null user) { - Auth().api().blockUser(user); + auto initBox = [=, controller = controller.get()]( + not_null box) { + controller->setBlockUserCallback([=](not_null user) { + window->session().api().blockUser(user); box->closeBox(); }); box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); @@ -346,6 +354,11 @@ rpl::producer PhoneNumberPrivacyController::exceptionsDescription() { return tr::lng_edit_privacy_phone_number_exceptions(); } +LastSeenPrivacyController::LastSeenPrivacyController( + not_null<::Main::Session*> session) +: _session(session) { +} + ApiWrap::Privacy::Key LastSeenPrivacyController::key() { return Key::LastSeen; } @@ -391,14 +404,15 @@ rpl::producer LastSeenPrivacyController::exceptionsDescription() { } void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, FnMut saveCallback) { - if (someAreDisallowed && !Auth().settings().lastSeenWarningSeen()) { + if (someAreDisallowed && !_session->settings().lastSeenWarningSeen()) { + const auto session = _session; auto weakBox = std::make_shared>(); - auto callback = [weakBox, saveCallback = std::move(saveCallback)]() mutable { + auto callback = [=, saveCallback = std::move(saveCallback)]() mutable { if (auto box = *weakBox) { box->closeBox(); } saveCallback(); - Auth().settings().setLastSeenWarningSeen(true); + session->settings().setLastSeenWarningSeen(true); Local::writeUserSettings(); }; auto box = Box( @@ -494,6 +508,7 @@ rpl::producer CallsPrivacyController::exceptionsDescription() { } object_ptr CallsPrivacyController::setupBelowWidget( + not_null controller, not_null parent) { auto result = object_ptr(parent); const auto content = result.data(); @@ -502,6 +517,7 @@ object_ptr CallsPrivacyController::setupBelowWidget( AddSkip(content); AddSubsectionTitle(content, tr::lng_settings_calls_peer_to_peer_title()); Settings::AddPrivacyButton( + controller, content, tr::lng_settings_calls_peer_to_peer_button(), ApiWrap::Privacy::Key::CallsPeer2Peer, @@ -563,6 +579,11 @@ rpl::producer CallsPeer2PeerPrivacyController::exceptionsDescription() return tr::lng_edit_privacy_calls_p2p_exceptions(); } +ForwardsPrivacyController::ForwardsPrivacyController( + not_null<::Main::Session*> session) +: _session(session) { +} + ApiWrap::Privacy::Key ForwardsPrivacyController::key() { return Key::Forwards; } @@ -613,7 +634,7 @@ object_ptr ForwardsPrivacyController::setupAboveWidget( auto message = GenerateForwardedItem( delegate(), - Auth().data().history( + _session->data().history( peerFromUser(PeerData::kServiceNotificationsId)), tr::lng_edit_privacy_forwards_sample_message(tr::now)); const auto view = message.get(); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 83e25b4f5..669a48577 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -16,12 +16,15 @@ namespace Settings { class BlockedBoxController : public PeerListController, private base::Subscriber, private MTP::Sender { public: + explicit BlockedBoxController( + not_null window); + void prepare() override; void rowClicked(not_null row) override; void rowActionClicked(not_null row) override; void loadMoreRows() override; - static void BlockNewUser(); + static void BlockNewUser(not_null window); private: void receivedUsers(const QVector &result); @@ -31,6 +34,8 @@ private: bool prependRow(not_null user); std::unique_ptr createRow(not_null user) const; + const not_null _window; + int _offset = 0; mtpRequestId _loadRequestId = 0; bool _allLoaded = false; @@ -60,6 +65,8 @@ public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; + explicit LastSeenPrivacyController(not_null<::Main::Session*> session); + Key key() override; MTPInputPrivacyKey apiKey() override; @@ -75,6 +82,9 @@ public: bool someAreDisallowed, FnMut saveCallback) override; +private: + const not_null<::Main::Session*> _session; + }; class GroupsInvitePrivacyController : public EditPrivacyController { @@ -111,6 +121,7 @@ public: rpl::producer exceptionsDescription() override; object_ptr setupBelowWidget( + not_null controller, not_null parent) override; }; @@ -141,6 +152,8 @@ public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; + explicit ForwardsPrivacyController(not_null<::Main::Session*> session); + Key key() override; MTPInputPrivacyKey apiKey() override; @@ -166,6 +179,8 @@ private: not_null view, Option value); + const not_null<::Main::Session*> _session; + }; class ProfilePhotoPrivacyController : public EditPrivacyController { diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 34b60af0b..bd48556aa 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat.h" #include "data/data_channel.h" #include "main/main_session.h" +#include "window/window_session_controller.h" #include "apiwrap.h" #include "styles/style_settings.h" #include "styles/style_boxes.h" @@ -72,9 +73,11 @@ QString PrivacyBase(Privacy::Key key, Privacy::Option option) { } } -rpl::producer PrivacyString(Privacy::Key key) { - Auth().api().reloadPrivacy(key); - return Auth().api().privacyValue( +rpl::producer PrivacyString( + not_null<::Main::Session*> session, + Privacy::Key key) { + session->api().reloadPrivacy(key); + return session->api().privacyValue( key ) | rpl::map([=](const Privacy &value) { auto add = QStringList(); @@ -93,20 +96,23 @@ rpl::producer PrivacyString(Privacy::Key key) { }); } -rpl::producer BlockedUsersCount() { - Auth().api().reloadBlockedUsers(); - return Auth().api().blockedUsersSlice( +rpl::producer BlockedUsersCount(not_null<::Main::Session*> session) { + session->api().reloadBlockedUsers(); + return session->api().blockedUsersSlice( ) | rpl::map([=](const ApiWrap::BlockedUsersSlice &data) { return data.total; }); } -void SetupPrivacy(not_null container) { +void SetupPrivacy( + not_null controller, + not_null container) { AddSkip(container, st::settingsPrivacySkip); AddSubsectionTitle(container, tr::lng_settings_privacy_title()); + const auto session = &controller->session(); auto count = rpl::combine( - BlockedUsersCount(), + BlockedUsersCount(session), tr::lng_settings_no_blocked_users() ) | rpl::map([](int count, const QString &none) { return count ? QString::number(count) : none; @@ -116,17 +122,17 @@ void SetupPrivacy(not_null container) { tr::lng_settings_blocked_users(), std::move(count), st::settingsButton - )->addClickHandler([] { - const auto initBox = [](not_null box) { + )->addClickHandler([=] { + const auto initBox = [=](not_null box) { box->addButton(tr::lng_close(), [=] { box->closeBox(); }); - box->addLeftButton(tr::lng_blocked_list_add(), [] { - BlockedBoxController::BlockNewUser(); + box->addLeftButton(tr::lng_blocked_list_add(), [=] { + BlockedBoxController::BlockNewUser(controller); }); }; Ui::show(Box( - std::make_unique(), + std::make_unique(controller), initBox)); }); @@ -134,8 +140,13 @@ void SetupPrivacy(not_null container) { const auto add = [&]( rpl::producer label, Key key, - auto controller) { - AddPrivacyButton(container, std::move(label), key, controller); + auto controllerFactory) { + AddPrivacyButton( + controller, + container, + std::move(label), + key, + controllerFactory); }; add( tr::lng_settings_phone_number_privacy(), @@ -144,11 +155,11 @@ void SetupPrivacy(not_null container) { add( tr::lng_settings_last_seen(), Key::LastSeen, - [] { return std::make_unique(); }); + [=] { return std::make_unique(session); }); add( tr::lng_settings_forwards_privacy(), Key::Forwards, - [] { return std::make_unique(); }); + [=] { return std::make_unique(session); }); add( tr::lng_settings_profile_photo_privacy(), Key::ProfilePhoto, @@ -175,7 +186,9 @@ not_null*> AddSeparator( st::settingsSeparatorPadding)); } -void SetupLocalPasscode(not_null container) { +void SetupLocalPasscode( + not_null controller, + not_null container) { AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_passcode_title()); @@ -195,8 +208,8 @@ void SetupLocalPasscode(not_null container) { container, std::move(text), st::settingsButton) - )->addClickHandler([] { - Ui::show(Box(false)); + )->addClickHandler([=] { + Ui::show(Box(&controller->session(), false)); }); const auto wrap = container->add( @@ -209,8 +222,8 @@ void SetupLocalPasscode(not_null container) { inner, tr::lng_settings_passcode_disable(), st::settingsButton) - )->addClickHandler([] { - Ui::show(Box(true)); + )->addClickHandler([=] { + Ui::show(Box(&controller->session(), true)); }); const auto label = Platform::LastUserInputTimeSupported() @@ -229,8 +242,8 @@ void SetupLocalPasscode(not_null container) { label(), std::move(value), st::settingsButton - )->addClickHandler([] { - Ui::show(Box()); + )->addClickHandler([=] { + Ui::show(Box(&controller->session())); }); wrap->toggleOn(base::duplicate(has)); @@ -238,7 +251,9 @@ void SetupLocalPasscode(not_null container) { AddSkip(container); } -void SetupCloudPassword(not_null container) { +void SetupCloudPassword( + not_null controller, + not_null container) { using namespace rpl::mappers; using State = Core::CloudPasswordState; @@ -246,15 +261,16 @@ void SetupCloudPassword(not_null container) { AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_password_title()); + const auto session = &controller->session(); auto has = rpl::single( false - ) | rpl::then(Auth().api().passwordState( + ) | rpl::then(controller->session().api().passwordState( ) | rpl::map([](const State &state) { return state.request || state.unknownAlgorithm || !state.unconfirmedPattern.isEmpty(); })) | rpl::distinct_until_changed(); - auto pattern = Auth().api().passwordState( + auto pattern = session->api().passwordState( ) | rpl::map([](const State &state) { return state.unconfirmedPattern; }); @@ -318,9 +334,9 @@ void SetupCloudPassword(not_null container) { ) | rpl::map( !_1 ))->setDuration(0); - change->entity()->addClickHandler([] { - if (CheckEditCloudPassword()) { - Ui::show(EditCloudPasswordBox(&Auth())); + change->entity()->addClickHandler([=] { + if (CheckEditCloudPassword(session)) { + Ui::show(EditCloudPasswordBox(session)); } else { Ui::show(CloudPasswordAppOutdatedBox()); } @@ -338,8 +354,8 @@ void SetupCloudPassword(not_null container) { ) | rpl::then(rpl::duplicate( unconfirmed )))->setDuration(0); - confirm->entity()->addClickHandler([] { - const auto state = Auth().api().passwordStateCurrent(); + confirm->entity()->addClickHandler([=] { + const auto state = session->api().passwordStateCurrent(); if (!state) { return; } @@ -347,22 +363,22 @@ void SetupCloudPassword(not_null container) { std::move( validation.reloadRequests - ) | rpl::start_with_next([] { - Auth().api().reloadPasswordState(); + ) | rpl::start_with_next([=] { + session->api().reloadPasswordState(); }, validation.box->lifetime()); std::move( validation.cancelRequests - ) | rpl::start_with_next([] { - Auth().api().clearUnconfirmedPassword(); + ) | rpl::start_with_next([=] { + session->api().clearUnconfirmedPassword(); }, validation.box->lifetime()); Ui::show(std::move(validation.box)); }); - const auto remove = [] { - if (CheckEditCloudPassword()) { - RemoveCloudPassword(); + const auto remove = [=] { + if (CheckEditCloudPassword(session)) { + RemoveCloudPassword(session); } else { Ui::show(CloudPasswordAppOutdatedBox()); } @@ -395,7 +411,7 @@ void SetupCloudPassword(not_null container) { const auto reloadOnActivation = [=](Qt::ApplicationState state) { if (label->toggled() && state == Qt::ApplicationActive) { - Auth().api().reloadPasswordState(); + controller->session().api().reloadPasswordState(); } }; QObject::connect( @@ -404,19 +420,23 @@ void SetupCloudPassword(not_null container) { label, reloadOnActivation); - Auth().api().reloadPasswordState(); + session->api().reloadPasswordState(); AddSkip(container); } -void SetupSelfDestruction(not_null container) { +void SetupSelfDestruction( + not_null controller, + not_null container) { AddDivider(container); AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_destroy_title()); - Auth().api().reloadSelfDestruct(); - const auto label = [] { - return Auth().api().selfDestructValue( + const auto session = &controller->session(); + + session->api().reloadSelfDestruct(); + const auto label = [&] { + return session->api().selfDestructValue( ) | rpl::map( SelfDestructionBox::DaysLabel ); @@ -427,14 +447,16 @@ void SetupSelfDestruction(not_null container) { tr::lng_settings_destroy_if(), label(), st::settingsButton - )->addClickHandler([] { - Ui::show(Box(Auth().api().selfDestructValue())); + )->addClickHandler([=] { + Ui::show(Box(session->api().selfDestructValue())); }); AddSkip(container); } -void SetupSessionsList(not_null container) { +void SetupSessionsList( + not_null controller, + not_null container) { AddSkip(container); AddSubsectionTitle(container, tr::lng_settings_sessions_title()); @@ -463,8 +485,8 @@ int ExceptionUsersCount(const std::vector> &exceptions) { return ranges::accumulate(exceptions, 0, add); } -bool CheckEditCloudPassword() { - const auto current = Auth().api().passwordStateCurrent(); +bool CheckEditCloudPassword(not_null<::Main::Session*> session) { + const auto current = session->api().passwordStateCurrent(); Assert(current.has_value()); if (!current->unknownAlgorithm @@ -479,7 +501,9 @@ object_ptr EditCloudPasswordBox(not_null session) { const auto current = session->api().passwordStateCurrent(); Assert(current.has_value()); - auto result = Box(PasscodeBox::CloudFields::From(*current)); + auto result = Box( + session, + PasscodeBox::CloudFields::From(*current)); const auto box = result.data(); rpl::merge( @@ -497,29 +521,29 @@ object_ptr EditCloudPasswordBox(not_null session) { return std::move(result); } -void RemoveCloudPassword() { - const auto current = Auth().api().passwordStateCurrent(); +void RemoveCloudPassword(not_null<::Main::Session*> session) { + const auto current = session->api().passwordStateCurrent(); Assert(current.has_value()); if (!current->request) { - Auth().api().clearUnconfirmedPassword(); + session->api().clearUnconfirmedPassword(); return; } auto fields = PasscodeBox::CloudFields::From(*current); fields.turningOff = true; - const auto box = Ui::show(Box(fields)); + const auto box = Ui::show(Box(session, fields)); rpl::merge( box->newPasswordSet( ) | rpl::map([] { return rpl::empty_value(); }), box->passwordReloadNeeded() ) | rpl::start_with_next([=] { - Auth().api().reloadPasswordState(); + session->api().reloadPasswordState(); }, box->lifetime()); box->clearUnconfirmedPassword( ) | rpl::start_with_next([=] { - Auth().api().clearUnconfirmedPassword(); + session->api().clearUnconfirmedPassword(); }, box->lifetime()); } @@ -538,43 +562,47 @@ object_ptr CloudPasswordAppOutdatedBox() { } void AddPrivacyButton( + not_null controller, not_null container, rpl::producer label, Privacy::Key key, - Fn()> controller) { + Fn()> controllerFactory) { const auto shower = Ui::CreateChild(container.get()); + const auto session = &controller->session(); AddButtonWithLabel( container, std::move(label), - PrivacyString(key), + PrivacyString(session, key), st::settingsButton )->addClickHandler([=] { - *shower = Auth().api().privacyValue( + *shower = session->api().privacyValue( key ) | rpl::take( 1 ) | rpl::start_with_next([=](const Privacy &value) { Ui::show( - Box(controller(), value), + Box(controller, controllerFactory(), value), LayerOption::KeepOther); }); }); } -PrivacySecurity::PrivacySecurity(QWidget *parent, not_null self) -: Section(parent) -, _self(self) { - setupContent(); +PrivacySecurity::PrivacySecurity( + QWidget *parent, + not_null controller) +: Section(parent) { + setupContent(controller); } -void PrivacySecurity::setupContent() { +void PrivacySecurity::setupContent( + not_null controller) { const auto content = Ui::CreateChild(this); - SetupPrivacy(content); - SetupSessionsList(content); - SetupLocalPasscode(content); - SetupCloudPassword(content); - SetupSelfDestruction(content); + SetupPrivacy(controller, content); + SetupSessionsList(controller, content); + SetupLocalPasscode(controller, content); + SetupCloudPassword(controller, content); + SetupSelfDestruction(controller, content); Ui::ResizeFitChild(this, content); } diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.h b/Telegram/SourceFiles/settings/settings_privacy_security.h index 0023ab44b..13291ead7 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.h +++ b/Telegram/SourceFiles/settings/settings_privacy_security.h @@ -16,26 +16,27 @@ namespace Settings { int ExceptionUsersCount(const std::vector> &exceptions); -bool CheckEditCloudPassword(); +bool CheckEditCloudPassword(not_null<::Main::Session*> session); object_ptr EditCloudPasswordBox( not_null<::Main::Session*> session); -void RemoveCloudPassword(); +void RemoveCloudPassword(not_null<::Main::Session*> session); object_ptr CloudPasswordAppOutdatedBox(); void AddPrivacyButton( + not_null controller, not_null container, rpl::producer label, ApiWrap::Privacy::Key key, - Fn()> controller); + Fn()> controllerFactory); class PrivacySecurity : public Section { public: - PrivacySecurity(QWidget *parent, not_null self); + PrivacySecurity( + QWidget *parent, + not_null controller); private: - void setupContent(); - - not_null _self; + void setupContent(not_null controller); };