diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index f4a08928a..19f33dfa5 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -477,7 +477,7 @@ void ApiWrap::importChatInvite(const QString &hash) { handleChats(data.vchats()); }, [&](auto &&) { LOG(("API Error: unexpected update cons %1 " - "(MainWidget::inviteImportDone)").arg(result.type())); + "(ApiWrap::importChatInvite)").arg(result.type())); }); }).fail([=](const RPCError &error) { const auto &type = error.type(); diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index d7e04a3b2..cdc9e428f 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -207,16 +207,16 @@ namespace App { if (update.paletteChanged()) { createPaletteCorners(); - if (App::main()) { - App::main()->updateScrollColors(); + if (const auto m = App::main()) { // multi good + m->updateScrollColors(); } HistoryView::serviceColorsUpdated(); } else if (update.type == Update::Type::New) { prepareCorners(StickerCorners, st::dateRadius, st::msgServiceBg); prepareCorners(StickerSelectedCorners, st::dateRadius, st::msgServiceBgSelected); - if (App::main()) { - App::main()->updateScrollColors(); + if (const auto m = App::main()) { // multi good + m->updateScrollColors(); } HistoryView::serviceColorsUpdated(); } diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 03700d875..625b78149 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document_media.h" #include "boxes/background_preview_box.h" #include "boxes/confirm_box.h" +#include "window/window_session_controller.h" #include "app.h" #include "styles/style_overview.h" #include "styles/style_layers.h" @@ -131,8 +132,10 @@ private: }; -BackgroundBox::BackgroundBox(QWidget*, not_null session) -: _session(session) { +BackgroundBox::BackgroundBox( + QWidget*, + not_null controller) +: _controller(controller) { } void BackgroundBox::prepare() { @@ -143,13 +146,13 @@ void BackgroundBox::prepare() { setDimensions(st::boxWideWidth, st::boxMaxListHeight); _inner = setInnerWidget( - object_ptr(this, _session), + object_ptr(this, &_controller->session()), st::backgroundScroll); _inner->chooseEvents( ) | rpl::start_with_next([=](const Data::WallPaper &paper) { Ui::show( - Box(_session, paper), + Box(_controller, paper), Ui::LayerOption::KeepOther); }, _inner->lifetime()); @@ -161,7 +164,7 @@ void BackgroundBox::prepare() { void BackgroundBox::removePaper(const Data::WallPaper &paper) { const auto box = std::make_shared>(); - const auto session = _session; + const auto session = &_controller->session(); const auto remove = [=, weak = Ui::MakeWeak(this)]{ if (*box) { (*box)->closeBox(); diff --git a/Telegram/SourceFiles/boxes/background_box.h b/Telegram/SourceFiles/boxes/background_box.h index dbfd8439e..e3d5994ae 100644 --- a/Telegram/SourceFiles/boxes/background_box.h +++ b/Telegram/SourceFiles/boxes/background_box.h @@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" -namespace Main { -class Session; -} // namespace Main +namespace Window { +class SessionController; +} // namespace Window namespace Data { class WallPaper; @@ -19,7 +19,7 @@ class WallPaper; class BackgroundBox : public Ui::BoxContent { public: - BackgroundBox(QWidget*, not_null session); + BackgroundBox(QWidget*, not_null controller); protected: void prepare() override; @@ -29,7 +29,7 @@ private: void removePaper(const Data::WallPaper &paper); - const not_null _session; + const not_null _controller; QPointer _inner; diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index db5c71fc8..7a368677f 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "boxes/confirm_box.h" #include "boxes/background_preview_box.h" +#include "window/window_session_controller.h" #include "app.h" #include "styles/style_history.h" #include "styles/style_layers.h" @@ -396,18 +397,18 @@ QImage PrepareScaledFromFull( BackgroundPreviewBox::BackgroundPreviewBox( QWidget*, - not_null session, + not_null controller, const Data::WallPaper &paper) -: _session(session) +: _controller(controller) , _text1(GenerateTextItem( delegate(), - _session->data().history( + _controller->session().data().history( peerFromUser(PeerData::kServiceNotificationsId)), tr::lng_background_text1(tr::now), false)) , _text2(GenerateTextItem( delegate(), - _session->data().history( + _controller->session().data().history( peerFromUser(PeerData::kServiceNotificationsId)), tr::lng_background_text2(tr::now), true)) @@ -417,7 +418,9 @@ BackgroundPreviewBox::BackgroundPreviewBox( if (_media) { _media->thumbnailWanted(_paper.fileOrigin()); } - subscribe(_session->downloaderTaskFinished(), [=] { update(); }); + subscribe(_controller->session().downloaderTaskFinished(), [=] { + update(); + }); } not_null BackgroundPreviewBox::delegate() { @@ -500,9 +503,9 @@ void BackgroundPreviewBox::createBlurCheckbox() { void BackgroundPreviewBox::apply() { const auto install = (_paper.id() != Window::Theme::Background()->id()) && Data::IsCloudWallPaper(_paper); - App::main()->setChatBackground(_paper, std::move(_full)); + _controller->content()->setChatBackground(_paper, std::move(_full)); if (install) { - _session->api().request(MTPaccount_InstallWallPaper( + _controller->session().api().request(MTPaccount_InstallWallPaper( _paper.mtpInput(), _paper.mtpSettings() )).send(); @@ -763,12 +766,12 @@ void BackgroundPreviewBox::checkLoadedDocument() { } bool BackgroundPreviewBox::Start( - not_null session, + not_null controller, const QString &slug, const QMap ¶ms) { if (const auto paper = Data::WallPaper::FromColorSlug(slug)) { Ui::show(Box( - session, + controller, paper->withUrlParams(params))); return true; } @@ -776,9 +779,10 @@ bool BackgroundPreviewBox::Start( Ui::show(Box(tr::lng_background_bad_link(tr::now))); return false; } - session->api().requestWallPaper(slug, [=](const Data::WallPaper &result) { + controller->session().api().requestWallPaper(slug, [=]( + const Data::WallPaper &result) { Ui::show(Box( - session, + controller, 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 773759e7a..28d45b659 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -19,9 +19,9 @@ namespace Data { class DocumentMedia; } // namespace Data -namespace Main { -class Session; -} // namespace Main +namespace Window { +class SessionController; +} // namespace Window namespace Ui { class Checkbox; @@ -34,11 +34,11 @@ class BackgroundPreviewBox public: BackgroundPreviewBox( QWidget*, - not_null session, + not_null controller, const Data::WallPaper &paper); static bool Start( - not_null session, + not_null controller, const QString &slug, const QMap ¶ms); @@ -71,7 +71,7 @@ private: void startFadeInFrom(QPixmap previous); void checkBlurAnimationStart(); - const not_null _session; + const not_null _controller; AdminLog::OwnedItem _text1; AdminLog::OwnedItem _text2; Data::WallPaper _paper; diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 3ec7844b7..ef50b16b3 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unique_qptr.h" #include "base/event_filter.h" #include "base/call_delayed.h" +#include "window/window_session_controller.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_settings.h" @@ -748,11 +749,11 @@ void Options::checkLastOption() { CreatePollBox::CreatePollBox( QWidget*, - not_null session, + not_null controller, PollData::Flags chosen, PollData::Flags disabled, Api::SendType sendType) -: _session(session) +: _controller(controller) , _chosen(chosen) , _disabled(disabled) , _sendType(sendType) { @@ -774,6 +775,7 @@ not_null CreatePollBox::setupQuestion( not_null container) { using namespace Settings; + const auto session = &_controller->session(); AddSubsectionTitle(container, tr::lng_polls_create_question()); const auto question = container->add( object_ptr( @@ -782,7 +784,7 @@ not_null CreatePollBox::setupQuestion( Ui::InputField::Mode::MultiLine, tr::lng_polls_create_question_placeholder()), st::createPollFieldPadding); - InitField(getDelegate()->outerContainer(), question, _session); + InitField(getDelegate()->outerContainer(), question, session); question->setMaxLength(kQuestionLimit + kErrorLimit); question->setSubmitSettings(Ui::InputField::SubmitSettings::Both); question->customTab(true); @@ -824,6 +826,7 @@ not_null CreatePollBox::setupSolution( )->setDuration(0)->toggleOn(std::move(shown)); const auto inner = outer->entity(); + const auto session = &_controller->session(); AddSkip(inner); AddSubsectionTitle(inner, tr::lng_polls_solution_title()); const auto solution = inner->add( @@ -833,14 +836,14 @@ not_null CreatePollBox::setupSolution( Ui::InputField::Mode::MultiLine, tr::lng_polls_solution_placeholder()), st::createPollFieldPadding); - InitField(getDelegate()->outerContainer(), solution, _session); + InitField(getDelegate()->outerContainer(), solution, session); solution->setMaxLength(kSolutionLimit + kErrorLimit); solution->setInstantReplaces(Ui::InstantReplaces::Default()); solution->setInstantReplacesEnabled( - _session->settings().replaceEmojiValue()); + session->settings().replaceEmojiValue()); solution->setMarkdownReplacesEnabled(rpl::single(true)); solution->setEditLinkCallback( - DefaultEditLinkCallback(_session, solution)); + DefaultEditLinkCallback(_controller, solution)); solution->customTab(true); const auto warning = CreateWarningLabel( @@ -896,7 +899,7 @@ object_ptr CreatePollBox::setupContent() { const auto options = lifetime().make_state( getDelegate()->outerContainer(), container, - _session, + &_controller->session(), (_chosen & PollData::Flag::Quiz)); auto limit = options->usedCount() | rpl::after_next([=](int count) { setCloseByEscape(!count); @@ -1011,7 +1014,7 @@ object_ptr CreatePollBox::setupContent() { const auto collectResult = [=] { using Flag = PollData::Flag; - auto result = PollData(&_session->data(), id); + auto result = PollData(&_controller->session().data(), id); result.question = question->getLastText().trimmed(); result.answers = options->toPollAnswers(); const auto solutionWithTags = quiz->checked() diff --git a/Telegram/SourceFiles/boxes/create_poll_box.h b/Telegram/SourceFiles/boxes/create_poll_box.h index 5c0258b26..f88de5418 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.h +++ b/Telegram/SourceFiles/boxes/create_poll_box.h @@ -18,9 +18,9 @@ namespace Ui { class VerticalLayout; } // namespace Ui -namespace Main { -class Session; -} // namespace Main +namespace Window { +class SessionController; +} // namespace Window class CreatePollBox : public Ui::BoxContent { public: @@ -31,7 +31,7 @@ public: CreatePollBox( QWidget*, - not_null session, + not_null controller, PollData::Flags chosen, PollData::Flags disabled, Api::SendType sendType); @@ -62,7 +62,7 @@ private: not_null container, rpl::producer shown); - const not_null _session; + const not_null _controller; const PollData::Flags _chosen = PollData::Flags(); const PollData::Flags _disabled = PollData::Flags(); const Api::SendType _sendType = Api::SendType(); diff --git a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp index 7712b6676..facced46b 100644 --- a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp +++ b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/wrap/slide_wrap.h" #include "ui/effects/animations.h" +#include "window/window_session_controller.h" namespace Ui { namespace { @@ -48,7 +49,7 @@ class Inner : public Ui::RpWidget { public: Inner( QWidget *parent, - not_null session, + not_null controller, Dictionaries enabledDictionaries); Dictionaries enabledRows() const; @@ -56,7 +57,7 @@ public: private: void setupContent( - not_null session, + not_null controller, Dictionaries enabledDictionaries); Dictionaries _enabledRows; @@ -101,10 +102,10 @@ auto CreateMultiSelect(QWidget *parent) { Inner::Inner( QWidget *parent, - not_null session, + not_null controller, Dictionaries enabledDictionaries) : RpWidget(parent) { - setupContent(session, std::move(enabledDictionaries)); + setupContent(controller, std::move(enabledDictionaries)); } QueryCallback Inner::queryCallback() const { @@ -117,7 +118,7 @@ Dictionaries Inner::enabledRows() const { auto AddButtonWithLoader( not_null content, - not_null session, + not_null controller, const Spellchecker::Dict &dict, bool buttonEnabled, rpl::producer query) { @@ -295,8 +296,8 @@ auto AddButtonWithLoader( if (toggled && (state.is() || state.is())) { const auto weak = Ui::MakeWeak(button); setLocalLoader(base::make_unique_q( - App::main(), - session, + controller->content(), + &controller->session(), id, Spellchecker::GetDownloadLocation(id), Spellchecker::DictPathByLangId(id), @@ -346,7 +347,7 @@ auto AddButtonWithLoader( } void Inner::setupContent( - not_null session, + not_null controller, Dictionaries enabledDictionaries) { const auto content = Ui::CreateChild(this); @@ -357,7 +358,7 @@ void Inner::setupContent( const auto id = dict.id; const auto row = AddButtonWithLoader( content, - session, + controller, dict, ranges::contains(enabledDictionaries, id), queryStream->events()); @@ -387,8 +388,8 @@ void Inner::setupContent( ManageDictionariesBox::ManageDictionariesBox( QWidget*, - not_null session) -: _session(session) { + not_null controller) +: _controller(controller) { } void ManageDictionariesBox::setInnerFocus() { @@ -398,11 +399,12 @@ void ManageDictionariesBox::setInnerFocus() { void ManageDictionariesBox::prepare() { const auto multiSelect = CreateMultiSelect(this); + const auto session = &_controller->session(); const auto inner = setInnerWidget( object_ptr( this, - _session, - _session->settings().dictionariesEnabled()), + _controller, + session->settings().dictionariesEnabled()), st::boxScroll, multiSelect->height() ); @@ -420,9 +422,9 @@ void ManageDictionariesBox::prepare() { setTitle(tr::lng_settings_manage_dictionaries()); addButton(tr::lng_settings_save(), [=] { - _session->settings().setDictionariesEnabled( + session->settings().setDictionariesEnabled( FilterEnabledDict(inner->enabledRows())); - _session->saveSettingsDelayed(); + session->saveSettingsDelayed(); // Ignore boxClosing() when the Save button was pressed. lifetime().destroy(); closeBox(); @@ -430,9 +432,9 @@ void ManageDictionariesBox::prepare() { addButton(tr::lng_close(), [=] { closeBox(); }); boxClosing() | rpl::start_with_next([=] { - _session->settings().setDictionariesEnabled( + session->settings().setDictionariesEnabled( FilterEnabledDict(initialEnabledRows)); - _session->saveSettingsDelayed(); + session->saveSettingsDelayed(); }, lifetime()); setDimensionsToContent(st::boxWidth, inner); diff --git a/Telegram/SourceFiles/boxes/dictionaries_manager.h b/Telegram/SourceFiles/boxes/dictionaries_manager.h index f137a76ca..39fd951ec 100644 --- a/Telegram/SourceFiles/boxes/dictionaries_manager.h +++ b/Telegram/SourceFiles/boxes/dictionaries_manager.h @@ -11,9 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" -namespace Main { -class Session; -} // namespace Main +namespace Window { +class SessionController; +} // namespace Window namespace Ui { @@ -21,14 +21,14 @@ class ManageDictionariesBox : public Ui::BoxContent { public: ManageDictionariesBox( QWidget*, - not_null session); + not_null controller); protected: void prepare() override; void setInnerFocus() override; private: - const not_null _session; + const not_null _controller; Fn _setInnerFocus; }; diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index f07b4e577..461213e5e 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -309,9 +309,9 @@ EditCaptionBox::EditCaptionBox( _controller->session().settings().replaceEmojiValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setEditLinkCallback( - DefaultEditLinkCallback(&_controller->session(), _field)); + DefaultEditLinkCallback(_controller, _field)); - InitSpellchecker(&_controller->session(), _field); + InitSpellchecker(_controller, _field); auto r = object_ptr>( this, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index e2e3d2eda..08f82b88b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -1440,15 +1440,22 @@ void Controller::deleteChannel() { const auto channel = _peer->asChannel(); const auto chat = channel->migrateFrom(); + const auto session = &_peer->session(); + Ui::hideLayer(); Ui::showChatsList(); if (chat) { - chat->session().api().deleteConversation(chat, false); + session->api().deleteConversation(chat, false); } - MTP::send( - MTPchannels_DeleteChannel(channel->inputChannel), - App::main()->rpcDone(&MainWidget::sentUpdatesReceived), - App::main()->rpcFail(&MainWidget::deleteChannelFailed)); + session->api().request(MTPchannels_DeleteChannel( + channel->inputChannel + )).done([=](const MTPUpdates &result) { + session->api().applyUpdates(result); + //}).fail([=](const RPCError &error) { + // if (error.type() == qstr("CHANNEL_TOO_LARGE")) { + // Ui::show(Box(tr::lng_cant_delete_channel(tr::now))); + // } + }).send(); } } // namespace diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 3fc3a6df2..e3c6570b9 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -2069,13 +2069,13 @@ void SendFilesBox::setupCaption() { _controller->session().settings().replaceEmojiValue()); _caption->setMarkdownReplacesEnabled(rpl::single(true)); _caption->setEditLinkCallback( - DefaultEditLinkCallback(&_controller->session(), _caption)); + DefaultEditLinkCallback(_controller, _caption)); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), _caption, &_controller->session()); - InitSpellchecker(&_controller->session(), _caption); + InitSpellchecker(_controller, _caption); updateCaptionPlaceholder(); setupEmojiPanel(); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index b44f76d27..b0bba83ec 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -205,10 +205,10 @@ void ShareBox::prepareCommentField() { _navigation->session().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); field->setEditLinkCallback( - DefaultEditLinkCallback(&_navigation->session(), field)); + DefaultEditLinkCallback(_navigation->parentController(), field)); field->setSubmitSettings(_navigation->session().settings().sendSubmitWay()); - InitSpellchecker(&_navigation->session(), field); + InitSpellchecker(_navigation->parentController(), field); Ui::SendPendingMoveResizeEvents(_comment); } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 9a71890e3..3b06a15b6 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -62,7 +62,7 @@ class EditLinkBox : public Ui::BoxContent { public: EditLinkBox( QWidget*, - not_null session, + not_null controller, const QString &text, const QString &link, Fn callback); @@ -73,7 +73,7 @@ protected: void prepare() override; private: - const not_null _session; + const not_null _controller; QString _startText; QString _startLink; Fn _callback; @@ -111,11 +111,11 @@ QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) { EditLinkBox::EditLinkBox( QWidget*, - not_null session, + not_null controller, const QString &text, const QString &link, Fn callback) -: _session(session) +: _controller(controller) , _startText(text) , _startLink(link) , _callback(std::move(callback)) { @@ -131,6 +131,7 @@ void EditLinkBox::setInnerFocus() { void EditLinkBox::prepare() { const auto content = Ui::CreateChild(this); + const auto session = &_controller->session(); const auto text = content->add( object_ptr( content, @@ -140,12 +141,12 @@ void EditLinkBox::prepare() { st::markdownLinkFieldPadding); text->setInstantReplaces(Ui::InstantReplaces::Default()); text->setInstantReplacesEnabled( - _session->settings().replaceEmojiValue()); + session->settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), text, - _session); - InitSpellchecker(_session, text); + session); + InitSpellchecker(_controller, text); const auto url = content->add( object_ptr( @@ -249,7 +250,7 @@ Fn DefaultEditLinkCallback( - not_null session, + not_null controller, not_null field) { const auto weak = Ui::MakeWeak(field); return [=]( @@ -261,7 +262,7 @@ Fn(session, text, link, [=]( + Ui::show(Box(controller, text, link, [=]( const QString &text, const QString &link) { if (const auto strong = weak.data()) { @@ -289,20 +290,19 @@ void InitMessageField( field->setInstantReplacesEnabled( controller->session().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); - field->setEditLinkCallback( - DefaultEditLinkCallback(&controller->session(), field)); + field->setEditLinkCallback(DefaultEditLinkCallback(controller, field)); } void InitSpellchecker( - not_null session, + not_null controller, not_null field) { #ifndef TDESKTOP_DISABLE_SPELLCHECK const auto s = Ui::CreateChild( field.get(), - session->settings().spellcheckerEnabledValue(), + controller->session().settings().spellcheckerEnabledValue(), Spellchecker::SpellingHighlighter::CustomContextMenuItem{ tr::lng_settings_manage_dictionaries(tr::now), - [=] { Ui::show(Box(session)); } + [=] { Ui::show(Box(controller)); } }); field->setExtendedContextMenu(s->contextMenuCreated()); #endif // TDESKTOP_DISABLE_SPELLCHECK diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index aba01cb68..b67bff668 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -34,14 +34,14 @@ Fn DefaultEditLinkCallback( - not_null session, + not_null controller, not_null field); void InitMessageField( not_null controller, not_null field); void InitSpellchecker( - not_null session, + not_null controller, not_null field); bool HasSendText(not_null field); diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index bbeb7196d..a37fee555 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -241,7 +241,7 @@ bool ShowWallPaper( match->captured(1), qthelp::UrlParamNameTransform::ToLower); return BackgroundPreviewBox::Start( - session, + App::wnd()->sessionController(), params.value(qsl("slug")), params); } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 600aa1366..2b016491e 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -94,6 +94,7 @@ void CheckForSwitchInlineButton(not_null item) { using ButtonType = HistoryMessageMarkupButton::Type; if (button.type == ButtonType::SwitchInline) { Notify::switchInlineBotButtonReceived( + &item->history()->session(), QString::fromUtf8(button.data)); return; } @@ -889,6 +890,25 @@ void Session::chatsListDone(Data::Folder *folder) { _chatsListLoadedEvents.fire_copy(folder); } +void Session::userIsBotChanged(not_null user) { + if (const auto history = this->history(user)) { + chatsFilters().refreshHistory(history); + } + _userIsBotChanges.fire_copy(user); +} + +rpl::producer> Session::userIsBotChanges() const { + return _userIsBotChanges.events(); +} + +void Session::botCommandsChanged(not_null user) { + _botCommandsChanges.fire_copy(user); +} + +rpl::producer> Session::botCommandsChanges() const { + return _botCommandsChanges.events(); +} + Storage::Cache::Database &Session::cache() { return *_cache; } diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 012a53978..508ffd1b8 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -200,6 +200,11 @@ public: void chatsListChanged(Data::Folder *folder); void chatsListDone(Data::Folder *folder); + void userIsBotChanged(not_null user); + [[nodiscard]] rpl::producer> userIsBotChanges() const; + void botCommandsChanged(not_null user); + [[nodiscard]] rpl::producer> botCommandsChanges() const; + struct ItemVisibilityQuery { not_null item; not_null isVisible; @@ -771,6 +776,8 @@ private: rpl::variable _contactsLoaded = false; rpl::event_stream _chatsListLoadedEvents; rpl::event_stream _chatsListChanged; + rpl::event_stream> _userIsBotChanges; + rpl::event_stream> _botCommandsChanges; base::Observable _queryItemVisibility; rpl::event_stream _itemIdChanges; rpl::event_stream> _itemLayoutChanges; diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index f9b64be55..d4e8f5b1c 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -131,22 +131,15 @@ void UserData::setPhone(const QString &newPhone) { void UserData::setBotInfoVersion(int version) { if (version < 0) { - if (botInfo) { - if (!botInfo->commands.isEmpty()) { - botInfo->commands.clear(); - Notify::botCommandsChanged(this); - } - botInfo = nullptr; - Notify::userIsBotChanged(this); - } + // We don't support bots becoming non-bots. } else if (!botInfo) { botInfo = std::make_unique(); botInfo->version = version; - Notify::userIsBotChanged(this); + owner().userIsBotChanged(this); } else if (botInfo->version < version) { if (!botInfo->commands.isEmpty()) { botInfo->commands.clear(); - Notify::botCommandsChanged(this); + owner().botCommandsChanged(this); } botInfo->description.clear(); botInfo->version = version; @@ -199,7 +192,7 @@ void UserData::setBotInfo(const MTPBotInfo &info) { botInfo->inited = true; if (changedCommands) { - Notify::botCommandsChanged(this); + owner().botCommandsChanged(this); } } break; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 1bb96971d..0b336ce3a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -239,7 +239,7 @@ InnerWidget::InnerWidget( } if (update.flags & (UpdateFlag::PhotoChanged | UpdateFlag::UserOccupiedChanged)) { this->update(); - emit App::main()->dialogsUpdated(); + emit controller->content()->dialogsUpdated(); } if (update.flags & UpdateFlag::UserIsContact) { if (update.peer->isUser()) { @@ -1498,7 +1498,7 @@ void InnerWidget::removeDialog(Key key) { refresh(); } - emit App::main()->dialogsUpdated(); + emit _controller->content()->dialogsUpdated(); refresh(); } @@ -3019,7 +3019,7 @@ void InnerWidget::setupShortcuts() { }) | rpl::start_with_next([=](not_null request) { using Command = Shortcuts::Command; - if (App::main()->selectingPeer()) { + if (_controller->content()->selectingPeer()) { return; } const auto row = _controller->activeChatEntryCurrent(); @@ -3059,7 +3059,9 @@ void InnerWidget::setupShortcuts() { return jumpToDialogRow(last); }); request->check(Command::ChatSelf) && request->handle([=] { - App::main()->choosePeer(session().userPeerId(), ShowAtUnreadMsgId); + _controller->content()->choosePeer( + session().userPeerId(), + ShowAtUnreadMsgId); return true; }); request->check(Command::ShowArchive) && request->handle([=] { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 779261f8b..7ef29a5de 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -199,10 +199,10 @@ Widget::Widget( }); _inner->chosenRow( ) | rpl::start_with_next([=](const ChosenRow &row) { - const auto openSearchResult = !App::main()->selectingPeer() + const auto openSearchResult = !controller->content()->selectingPeer() && row.filteredRow; if (const auto history = row.key.history()) { - App::main()->choosePeer( + controller->content()->choosePeer( history->peer->id, (controller->uniqueChatsInSearchResults() ? ShowAtUnreadMsgId @@ -642,7 +642,7 @@ void Widget::showAnimated(Window::SlideDirection direction, const Window::Sectio _cacheUnder = params.oldContentCache; showFast(); - _cacheOver = App::main()->grabForShowAnimation(params); + _cacheOver = controller()->content()->grabForShowAnimation(params); if (_updateTelegram) { _updateTelegram->hide(); @@ -698,7 +698,7 @@ void Widget::escape() { } else if (controller()->activeChatsFilterCurrent()) { controller()->setActiveChatsFilter(FilterId(0)); } - } else if (!_searchInChat && !App::main()->selectingPeer()) { + } else if (!_searchInChat && !controller()->content()->selectingPeer()) { if (controller()->activeChatEntryCurrent().key) { emit cancelled(); } @@ -1243,7 +1243,9 @@ bool Widget::peopleFailed(const RPCError &error, mtpRequestId req) { void Widget::dragEnterEvent(QDragEnterEvent *e) { using namespace Storage; - if (App::main()->selectingPeer()) return; + if (controller()->content()->selectingPeer()) { + return; + } const auto data = e->mimeData(); _dragInScroll = false; @@ -1295,9 +1297,9 @@ void Widget::updateDragInScroll(bool inScroll) { if (_dragInScroll != inScroll) { _dragInScroll = inScroll; if (_dragInScroll) { - App::main()->showForwardLayer({}); + controller()->content()->showForwardLayer({}); } else { - App::main()->dialogsCancelled(); + controller()->content()->dialogsCancelled(); } } } @@ -1307,7 +1309,9 @@ void Widget::dropEvent(QDropEvent *e) { if (_scroll->geometry().contains(e->pos())) { if (auto peer = _inner->updateFromParentDrag(mapToGlobal(e->pos()))) { e->acceptProposedAction(); - App::main()->onFilesOrForwardDrop(peer->id, e->mimeData()); + controller()->content()->onFilesOrForwardDrop( + peer->id, + e->mimeData()); controller()->widget()->activateWindow(); } } @@ -1556,7 +1560,7 @@ void Widget::updateControlsGeometry() { right -= _chooseFromUser->width(); _chooseFromUser->moveToLeft(right, _filter->y()); auto scrollTop = filterAreaTop + filterAreaHeight; - auto addToScroll = App::main() ? App::main()->contentScrollAddToY() : 0; + auto addToScroll = controller()->content()->contentScrollAddToY(); auto newScrollTop = _scroll->scrollTop() + addToScroll; auto scrollHeight = height() - scrollTop; const auto putBottomButton = [&](object_ptr &button) { @@ -1589,14 +1593,16 @@ void Widget::updateControlsGeometry() { } void Widget::updateForwardBar() { - auto selecting = App::main()->selectingPeer(); + auto selecting = controller()->content()->selectingPeer(); auto oneColumnSelecting = (Adaptive::OneColumn() && selecting); if (!oneColumnSelecting == !_forwardCancel) { return; } if (oneColumnSelecting) { _forwardCancel.create(this, st::dialogsForwardCancel); - _forwardCancel->setClickedCallback([] { Global::RefPeerChooseCancel().notify(true); }); + _forwardCancel->setClickedCallback([] { + Global::RefPeerChooseCancel().notify(true); + }); if (!_a_show.animating()) _forwardCancel->show(); } else { _forwardCancel.destroyDelayed(); @@ -1737,7 +1743,7 @@ bool Widget::onCancelSearch() { void Widget::onCancelSearchInChat() { cancelSearchRequest(); if (_searchInChat) { - if (Adaptive::OneColumn() && !App::main()->selectingPeer()) { + if (Adaptive::OneColumn() && !controller()->content()->selectingPeer()) { if (const auto peer = _searchInChat.peer()) { Ui::showPeerHistory(peer, ShowAtUnreadMsgId); //} else if (const auto feed = _searchInChat.feed()) { // #feed @@ -1752,7 +1758,7 @@ void Widget::onCancelSearchInChat() { _filter->clear(); _filter->updatePlaceholder(); applyFilterUpdate(); - if (!Adaptive::OneColumn() && !App::main()->selectingPeer()) { + if (!Adaptive::OneColumn() && !controller()->content()->selectingPeer()) { emit cancelled(); } } diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 4d3e3633b..af71ca3a1 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -35,20 +35,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace App { -void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) { - if (auto m = App::main()) { - m->sendBotCommand(peer, bot, cmd, replyTo); +void sendBotCommand( + not_null peer, + UserData *bot, + const QString &cmd, MsgId replyTo) { + if (const auto m = App::main()) { // multi good + if (&m->session() == &peer->session()) { + m->sendBotCommand(peer, bot, cmd, replyTo); + } } } -void hideSingleUseKeyboard(const HistoryItem *msg) { - if (auto m = App::main()) { - m->hideSingleUseKeyboard(msg->history()->peer, msg->id); +void hideSingleUseKeyboard(not_null message) { + if (const auto m = App::main()) { // multi good + if (&m->session() == &message->history()->session()) { + m->hideSingleUseKeyboard(message->history()->peer, message->id); + } } } bool insertBotCommand(const QString &cmd) { - if (auto m = App::main()) { + if (const auto m = App::main()) { // multi good return m->insertBotCommand(cmd); } return false; @@ -82,8 +89,10 @@ void activateBotCommand( case ButtonType::Callback: case ButtonType::Game: { - if (auto m = App::main()) { - m->app_sendBotCallback(button, msg, row, column); + if (const auto m = App::main()) { // multi good + if (&m->session() == &msg->history()->session()) { + m->app_sendBotCallback(button, msg, row, column); + } } } break; @@ -94,7 +103,7 @@ void activateBotCommand( case ButtonType::Url: { auto url = QString::fromUtf8(button->data); auto skipConfirmation = false; - if (auto bot = msg->getMessageBot()) { + if (const auto bot = msg->getMessageBot()) { if (bot->isVerified()) { skipConfirmation = true; } @@ -137,27 +146,34 @@ void activateBotCommand( chosen |= PollData::Flag::Quiz; } } - Window::PeerMenuCreatePoll(msg->history()->peer, chosen, disabled); + if (const auto m = App::main()) { // multi good + if (&m->session() == &msg->history()->session()) { + Window::PeerMenuCreatePoll(m->controller(), msg->history()->peer, chosen, disabled); + } + } } break; case ButtonType::SwitchInlineSame: case ButtonType::SwitchInline: { - if (auto m = App::main()) { - if (auto bot = msg->getMessageBot()) { - auto tryFastSwitch = [bot, &button, msgId = msg->id]() -> bool { - auto samePeer = (button->type == ButtonType::SwitchInlineSame); - if (samePeer) { - Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data), bot, msgId); - return true; - } else if (bot->isBot() && bot->botInfo->inlineReturnPeerId) { - if (Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data))) { + const auto session = &msg->history()->session(); + if (const auto m = App::main()) { // multi good + if (&m->session() == session) { + if (const auto bot = msg->getMessageBot()) { + const auto fastSwitchDone = [&] { + auto samePeer = (button->type == ButtonType::SwitchInlineSame); + if (samePeer) { + Notify::switchInlineBotButtonReceived(session, QString::fromUtf8(button->data), bot, msg->id); return true; + } else if (bot->isBot() && bot->botInfo->inlineReturnPeerId) { + if (Notify::switchInlineBotButtonReceived(session, QString::fromUtf8(button->data))) { + return true; + } } + return false; + }(); + if (!fastSwitchDone) { + m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data)); } - return false; - }; - if (!tryFastSwitch()) { - m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data)); } } } @@ -170,20 +186,18 @@ void activateBotCommand( } void searchByHashtag(const QString &tag, PeerData *inPeer) { - if (const auto window = App::wnd()) { - if (const auto controller = window->sessionController()) { - if (controller->openedFolder().current()) { - controller->closeFolder(); + if (const auto m = App::main()) { // multi good + if (!inPeer || &m->session() == &inPeer->session()) { + if (m->controller()->openedFolder().current()) { + m->controller()->closeFolder(); } - } - Ui::hideSettingsAndLayer(); - Core::App().hideMediaView(); - if (const auto m = window->mainWidget()) { + Ui::hideSettingsAndLayer(); + Core::App().hideMediaView(); m->searchMessages( tag + ' ', (inPeer && !inPeer->isUser()) - ? inPeer->owner().history(inPeer).get() - : Dialogs::Key()); + ? inPeer->owner().history(inPeer).get() + : Dialogs::Key()); } } } @@ -216,8 +230,7 @@ void showPeerProfile(not_null history) { void showPeerHistory( const PeerId &peer, MsgId msgId) { - auto ms = crl::now(); - if (auto m = App::main()) { + if (const auto m = App::main()) { // multi good m->ui_showPeerHistory( peer, Window::SectionShow::Way::ClearStack, @@ -226,15 +239,22 @@ void showPeerHistory( } void showPeerHistoryAtItem(not_null item) { - showPeerHistory(item->history()->peer->id, item->id); + showPeerHistory(item->history()->peer, item->id); } void showPeerHistory(not_null history, MsgId msgId) { - showPeerHistory(history->peer->id, msgId); + showPeerHistory(history->peer, msgId); } -void showPeerHistory(const PeerData *peer, MsgId msgId) { - showPeerHistory(peer->id, msgId); +void showPeerHistory(not_null peer, MsgId msgId) { + if (const auto m = App::main()) { // multi good + if (&m->session() == &peer->session()) { + m->ui_showPeerHistory( + peer->id, + Window::SectionShow::Way::ClearStack, + msgId); + } + } } PeerData *getPeerForMouseAction() { @@ -254,36 +274,40 @@ bool skipPaintEvent(QWidget *widget, QPaintEvent *event) { namespace Notify { -void userIsBotChanged(UserData *user) { - if (MainWidget *m = App::main()) m->notify_userIsBotChanged(user); -} - -void botCommandsChanged(UserData *user) { - if (MainWidget *m = App::main()) { - m->notify_botCommandsChanged(user); - } - peerUpdatedDelayed(user, PeerUpdate::Flag::BotCommandsChanged); -} - -void inlineBotRequesting(bool requesting) { - if (MainWidget *m = App::main()) m->notify_inlineBotRequesting(requesting); -} - -void replyMarkupUpdated(const HistoryItem *item) { - if (MainWidget *m = App::main()) { - m->notify_replyMarkupUpdated(item); +void replyMarkupUpdated(not_null item) { + if (const auto m = App::main()) { // multi good + if (&m->session() == &item->history()->session()) { + m->notify_replyMarkupUpdated(item); + } } } -void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { - if (MainWidget *m = App::main()) { - m->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop); +void inlineKeyboardMoved( + not_null item, + int oldKeyboardTop, + int newKeyboardTop) { + if (const auto m = App::main()) { // multi good + if (&m->session() == &item->history()->session()) { + m->notify_inlineKeyboardMoved( + item, + oldKeyboardTop, + newKeyboardTop); + } } } -bool switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo) { - if (auto main = App::main()) { - return main->notify_switchInlineBotButtonReceived(query, samePeerBot, samePeerReplyTo); +bool switchInlineBotButtonReceived( + not_null session, + const QString &query, + UserData *samePeerBot, + MsgId samePeerReplyTo) { + if (const auto m = App::main()) { // multi good + if (session == &m->session()) { + return m->notify_switchInlineBotButtonReceived( + query, + samePeerBot, + samePeerReplyTo); + } } return false; } diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 2a18db821..c913ab35a 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -38,7 +38,7 @@ template } void sendBotCommand( - PeerData *peer, + not_null peer, UserData *bot, const QString &cmd, MsgId replyTo = 0); @@ -63,7 +63,7 @@ void showPeerProfile(not_null history); void showPeerHistory(const PeerId &peer, MsgId msgId); void showPeerHistoryAtItem(not_null item); -void showPeerHistory(const PeerData *peer, MsgId msgId); +void showPeerHistory(not_null peer, MsgId msgId); void showPeerHistory(not_null history, MsgId msgId); inline void showChatsList() { showPeerHistory(PeerId(0), 0); @@ -81,13 +81,16 @@ enum ClipStopperType { namespace Notify { -void userIsBotChanged(UserData *user); -void botCommandsChanged(UserData *user); - -void inlineBotRequesting(bool requesting); -void replyMarkupUpdated(const HistoryItem *item); -void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); -bool switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot = nullptr, MsgId samePeerReplyTo = 0); +void replyMarkupUpdated(not_null item); +void inlineKeyboardMoved( + not_null item, + int oldKeyboardTop, + int newKeyboardTop); +bool switchInlineBotButtonReceived( + not_null session, + const QString &query, + UserData *samePeerBot = nullptr, + MsgId samePeerReplyTo = 0); void unreadCounterUpdated(); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index 8c12454ff..d836c9d8a 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -432,7 +432,7 @@ void Widget::paintEvent(QPaintEvent *e) { //auto ms = crl::now(); //_historyDownShown.step(ms); - SectionWidget::PaintBackground(this, e->rect()); + SectionWidget::PaintBackground(controller(), this, e->rect()); } void Widget::onScroll() { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 6ff83f90f..58da4cf4a 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -633,7 +633,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { view->draw(p, clip.translated(0, -y), selection, ms); if (item->hasViews()) { - App::main()->scheduleViewIncrement(item); + _controller->content()->scheduleViewIncrement(item); } if (item->isUnreadMention() && !item->isUnreadMedia()) { readMentions.insert(item); @@ -689,7 +689,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { if (_visibleAreaBottom >= middle && _visibleAreaTop <= middle) { if (item->hasViews()) { - App::main()->scheduleViewIncrement(item); + _controller->content()->scheduleViewIncrement(item); } if (item->isUnreadMention() && !item->isUnreadMedia()) { readMentions.insert(item); @@ -1279,9 +1279,6 @@ void HistoryInner::itemRemoved(not_null item) { if (_history != item->history() && _migrated != item->history()) { return; } - if (!App::main()) { - return; - } _animatedStickersPlayed.remove(item); @@ -2495,6 +2492,18 @@ void HistoryInner::elementStartStickerLoop( _animatedStickersPlayed.emplace(view->data()); } +crl::time HistoryInner::elementHighlightTime(not_null view) { + const auto fullAnimMs = _controller->content()->highlightStartTime( + view->data()); + if (fullAnimMs > 0) { + const auto now = crl::now(); + if (fullAnimMs < now) { + return now - fullAnimMs; + } + } + return 0; +} + void HistoryInner::elementShowPollResults( not_null poll, FullMsgId context) { @@ -3117,7 +3126,7 @@ void HistoryInner::deleteItem(FullMsgId itemId) { void HistoryInner::deleteItem(not_null item) { if (auto message = item->toHistoryMessage()) { if (message->uploading()) { - App::main()->cancelUploadLayer(item); + _controller->content()->cancelUploadLayer(item); return; } } @@ -3331,20 +3340,12 @@ not_null HistoryInner::ElementDelegate() { replacing); } bool elementUnderCursor( - not_null view) override { + not_null view) override { return (App::hoveredItem() == view); } crl::time elementHighlightTime( - not_null view) override { - const auto fullAnimMs = App::main()->highlightStartTime( - view->data()); - if (fullAnimMs > 0) { - const auto now = crl::now(); - if (fullAnimMs < now) { - return now - fullAnimMs; - } - } - return crl::time(0); + not_null view) override { + return Instance ? Instance->elementHighlightTime(view) : 0; } bool elementInSelectionMode() override { return Instance ? Instance->inSelectionMode() : false; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index f66dc9c4c..9c369638e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -83,6 +83,8 @@ public: int from, int till) const; void elementStartStickerLoop(not_null view); + [[nodiscard]] crl::time elementHighlightTime( + not_null view); void elementShowPollResults( not_null poll, FullMsgId context); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index f03dbad5c..cf700636c 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -134,14 +134,6 @@ constexpr auto kCommonModifiers = 0 | Qt::ControlModifier; const auto kPsaAboutPrefix = "cloud_lng_about_psa_"; -ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() { - return [](ChannelData *channel, MsgId msgId) { - if (App::main()) { - App::main()->messageDataReceived(channel, msgId); - } - }; -} - void ActivateWindow(not_null controller) { const auto window = controller->widget(); window->activateWindow(); @@ -416,7 +408,7 @@ HistoryWidget::HistoryWidget( } Unexpected("action in MimeData hook."); }); - InitSpellchecker(&controller->session(), _field); + InitSpellchecker(controller, _field); const auto suggestions = Ui::Emoji::SuggestionsController::Init( this, @@ -520,6 +512,25 @@ HistoryWidget::HistoryWidget( } }, lifetime()); + session().data().userIsBotChanges( + ) | rpl::filter([=](not_null user) { + return (_peer == user.get()); + }) | rpl::start_with_next([=](not_null user) { + _list->notifyIsBotChanged(); + _list->updateBotInfo(); + updateControlsVisibility(); + updateControlsGeometry(); + }, lifetime()); + + session().data().botCommandsChanges( + ) | rpl::filter([=](not_null user) { + return _peer && (_peer == user || !_peer->isUser()); + }) | rpl::start_with_next([=](not_null user) { + if (_fieldAutocomplete->clearFilteredBotCommands()) { + onCheckFieldAutocomplete(); + } + }, lifetime()); + subscribe(Media::Player::instance()->switchToNextNotifier(), [this](const Media::Player::Instance::Switch &pair) { if (pair.from.type() == AudioMsgId::Type::Voice) { scrollToCurrentVoiceMessage(pair.from.contextId(), pair.to); @@ -1030,7 +1041,7 @@ void HistoryWidget::onHashtagOrBotCommandInsert( // Send bot command at once, if it was not inserted by pressing Tab. if (str.at(0) == '/' && method != FieldAutocomplete::ChooseMethod::ByTab) { App::sendBotCommand(_peer, nullptr, str, replyToId()); - App::main()->finishForwarding(Api::SendAction(_history)); + controller()->content()->finishForwarding(Api::SendAction(_history)); setFieldText(_field->getTextWithTagsPart(_field->textCursor().position())); } else { _field->insertTag(str); @@ -1045,14 +1056,12 @@ void HistoryWidget::updateInlineBotQuery() { if (_inlineBotUsername != query.username) { _inlineBotUsername = query.username; if (_inlineBotResolveRequestId) { -// Notify::inlineBotRequesting(false); MTP::cancel(_inlineBotResolveRequestId); _inlineBotResolveRequestId = 0; } if (query.lookingUpBot) { _inlineBot = nullptr; _inlineLookingUpBot = true; -// Notify::inlineBotRequesting(true); _inlineBotResolveRequestId = MTP::send( MTPcontacts_ResolveUsername(MTP_string(_inlineBotUsername)), rpcDone(&HistoryWidget::inlineBotResolveDone), @@ -1085,6 +1094,10 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) { UserData *bot) { sendInlineResult(result, bot); }); + _inlineResults->requesting( + ) | rpl::start_with_next([=](bool requesting) { + _tabbedSelectorToggle->setLoading(requesting); + }, _inlineResults->lifetime()); updateControlsGeometry(); orderWidgets(); } @@ -1217,9 +1230,7 @@ void HistoryWidget::saveFieldToHistoryLocalDraft() { } void HistoryWidget::onCloudDraftSave() { - if (App::main()) { - App::main()->saveDraftToCloud(); - } + controller()->content()->saveDraftToCloud(); } void HistoryWidget::writeDrafts(Data::Draft **localDraft, Data::Draft **editDraft) { @@ -1423,27 +1434,15 @@ void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) { } } -void HistoryWidget::notify_botCommandsChanged(UserData *user) { - if (_peer && (_peer == user || !_peer->isUser())) { - if (_fieldAutocomplete->clearFilteredBotCommands()) { - onCheckFieldAutocomplete(); - } - } -} - -void HistoryWidget::notify_inlineBotRequesting(bool requesting) { - _tabbedSelectorToggle->setLoading(requesting); -} - -void HistoryWidget::notify_replyMarkupUpdated(const HistoryItem *item) { +void HistoryWidget::notify_replyMarkupUpdated(not_null item) { if (_keyboard->forMsgId() == item->fullId()) { updateBotKeyboard(item->history(), true); } } -void HistoryWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { +void HistoryWidget::notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop) { if (_history == item->history() || _migrated == item->history()) { - if (int move = _list->moveScrollFollowingInlineKeyboard(item, oldKeyboardTop, newKeyboardTop)) { + if (const auto move = _list->moveScrollFollowingInlineKeyboard(item, oldKeyboardTop, newKeyboardTop)) { _addToScroll = move; } } @@ -1480,18 +1479,6 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U return false; } -void HistoryWidget::notify_userIsBotChanged(UserData *user) { - if (const auto history = session().data().history(user)) { - session().data().chatsFilters().refreshHistory(history); - } - if (_peer && _peer == user) { - _list->notifyIsBotChanged(); - _list->updateBotInfo(); - updateControlsVisibility(); - updateControlsGeometry(); - } -} - void HistoryWidget::setupShortcuts() { Shortcuts::Requests( ) | rpl::filter([=] { @@ -1502,7 +1489,7 @@ void HistoryWidget::setupShortcuts() { using Command = Shortcuts::Command; if (_history) { request->check(Command::Search, 1) && request->handle([=] { - App::main()->searchInChat(_history); + controller()->content()->searchInChat(_history); return true; }); if (session().supportMode()) { @@ -1631,10 +1618,7 @@ void HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) { if (_editMsgId || _replyToId) { updateReplyEditTexts(); if (!_replyEditMsg) { - session().api().requestMessageData( - _peer->asChannel(), - _editMsgId ? _editMsgId : _replyToId, - replyEditMessageDataCallback()); + requestMessageData(_editMsgId ? _editMsgId : _replyToId); } } } @@ -1751,9 +1735,7 @@ void HistoryWidget::showHistory( // Removing focus from list clears selected and updates top bar. setFocus(); } - if (App::main()) { - App::main()->saveDraftToCloud(); - } + controller()->content()->saveDraftToCloud(); if (_migrated) { _migrated->clearLocalDraft(); // use migrated draft only once _migrated->clearEditDraft(); @@ -3040,7 +3022,7 @@ void HistoryWidget::saveEditMsgDone(History *history, const MTPUpdates &updates, if (auto editDraft = history->editDraft()) { if (editDraft->saveRequestId == req) { history->clearEditDraft(); - if (App::main()) App::main()->writeDrafts(history); + controller()->content()->writeDrafts(history); } } } @@ -3135,8 +3117,8 @@ void HistoryWidget::send(Api::SendOptions options) { if (!_keyboard->hasMarkup() && _keyboard->forceReply() && !_kbReplyTo) { toggleKeyboard(); } - App::main()->historyToDown(_history); - App::main()->dialogsToUp(); + controller()->content()->historyToDown(_history); + controller()->content()->dialogsToUp(); } void HistoryWidget::sendWithModifiers(Qt::KeyboardModifiers modifiers) { @@ -3284,7 +3266,7 @@ void HistoryWidget::showAnimated( historyDownAnimationFinish(); unreadMentionsAnimationFinish(); _topShadow->setVisible(params.withTopBarShadow ? false : true); - _cacheOver = App::main()->grabForShowAnimation(params); + _cacheOver = controller()->content()->grabForShowAnimation(params); if (_tabbedPanel) { _tabbedPanel->hideFast(); @@ -3550,8 +3532,12 @@ void HistoryWidget::stopRecording(bool send) { _send->setRecordActive(false); } -void HistoryWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) { // replyTo != 0 from ReplyKeyboardMarkup, == 0 from cmd links - if (!_peer || _peer != peer) { +void HistoryWidget::sendBotCommand( + not_null peer, + UserData *bot, + const QString &cmd, + MsgId replyTo) { // replyTo != 0 from ReplyKeyboardMarkup, == 0 from cmd links + if (_peer != peer.get()) { return; } else if (showSlowmodeError()) { return; @@ -3853,7 +3839,6 @@ void HistoryWidget::inlineBotResolveDone( _inlineBotResolveRequestId = 0; const auto &data = result.c_contacts_resolvedPeer(); -// Notify::inlineBotRequesting(false); const auto resolvedBot = [&]() -> UserData* { if (const auto result = session().data().processUsers(data.vusers())) { if (result->isBot() @@ -3881,7 +3866,6 @@ bool HistoryWidget::inlineBotResolveFail(QString name, const RPCError &error) { } _inlineBotResolveRequestId = 0; -// Notify::inlineBotRequesting(false); if (name == _inlineBotUsername) { clearInlineBot(); } @@ -4840,9 +4824,9 @@ void HistoryWidget::sendFileConfirmed( session().data().sendHistoryChangeNotifications(); if (_peer && file->to.peer == _peer->id) { - App::main()->historyToDown(_history); + controller()->content()->historyToDown(_history); } - App::main()->dialogsToUp(); + controller()->content()->dialogsToUp(); } void HistoryWidget::photoUploaded( @@ -5044,7 +5028,7 @@ void HistoryWidget::updateControlsGeometry() { } } - updateHistoryGeometry(false, false, { ScrollChangeAdd, App::main() ? App::main()->contentScrollAddToY() : 0 }); + updateHistoryGeometry(false, false, { ScrollChangeAdd, controller()->content()->contentScrollAddToY() }); updateFieldSize(); @@ -5574,7 +5558,7 @@ void HistoryWidget::mousePressEvent(QMouseEvent *e) { } else if (_inReplyEditForward) { if (readyToForward()) { const auto items = std::move(_toForward); - App::main()->cancelForwarding(_history); + controller()->content()->cancelForwarding(_history); auto list = ranges::view::all( items ) | ranges::view::transform( @@ -5872,10 +5856,7 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() { updatePinnedBar(); } if (!_pinnedBar->msg) { - session().api().requestMessageData( - _peer->asChannel(), - _pinnedBar->msgId, - replyEditMessageDataCallback()); + requestMessageData(_pinnedBar->msgId); } } else if (_pinnedBar) { destroyPinnedBar(); @@ -5889,6 +5870,16 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() { return result; } +void HistoryWidget::requestMessageData(MsgId msgId) { + const auto callback = [=](ChannelData *channel, MsgId msgId) { + messageDataReceived(channel, msgId); + }; + session().api().requestMessageData( + _peer->asChannel(), + msgId, + crl::guard(this, callback)); +} + void HistoryWidget::destroyPinnedBar() { _pinnedBar.reset(); _inPinnedMsg = false; @@ -6017,7 +6008,7 @@ void HistoryWidget::replyToMessage(not_null item) { } else { const auto itemId = item->fullId(); Ui::show(Box(tr::lng_reply_cant_forward(tr::now), tr::lng_selected_forward(tr::now), crl::guard(this, [=] { - App::main()->setForwardDraft( + controller()->content()->setForwardDraft( _peer->id, { 1, itemId }); }))); @@ -6025,7 +6016,7 @@ void HistoryWidget::replyToMessage(not_null item) { return; } - App::main()->cancelForwarding(_history); + controller()->content()->cancelForwarding(_history); if (_editMsgId) { if (auto localDraft = _history->localDraft()) { @@ -6296,7 +6287,7 @@ void HistoryWidget::cancelFieldAreaState() { } else if (_editMsgId) { cancelEdit(); } else if (readyToForward()) { - App::main()->cancelForwarding(_history); + controller()->content()->cancelForwarding(_history); } else if (_replyToId) { cancelReply(); } else if (_kbReplyTo) { @@ -7030,7 +7021,7 @@ void HistoryWidget::paintEvent(QPaintEvent *e) { updateListSize(); } - Window::SectionWidget::PaintBackground(this, e->rect()); + Window::SectionWidget::PaintBackground(controller(), this, e->rect()); Painter p(this); const auto clip = e->rect(); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 640e5fc7f..c324894cd 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -182,7 +182,6 @@ public: void unpinMessage(FullMsgId itemId); MsgId replyToId() const; - void messageDataReceived(ChannelData *channel, MsgId msgId); bool lastForceReplyReplied(const FullMsgId &replyTo) const; bool lastForceReplyReplied() const; bool cancelReply(bool lastKeyboardUsed = false); @@ -204,7 +203,11 @@ public: void escape(); - void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo); + void sendBotCommand( + not_null peer, + UserData *bot, + const QString &cmd, + MsgId replyTo); void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo); bool insertBotCommand(const QString &cmd); @@ -270,12 +273,10 @@ public: PeerData *ui_getPeerForMouseAction(); - void notify_botCommandsChanged(UserData *user); void notify_inlineBotRequesting(bool requesting); - void notify_replyMarkupUpdated(const HistoryItem *item); - void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); + void notify_replyMarkupUpdated(not_null item); + void notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop); bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo); - void notify_userIsBotChanged(UserData *user); ~HistoryWidget(); @@ -376,6 +377,9 @@ private: void setTabbedPanel(std::unique_ptr panel); void updateField(); + void requestMessageData(MsgId msgId); + void messageDataReceived(ChannelData *channel, MsgId msgId); + void send(Api::SendOptions options); void sendWithModifiers(Qt::KeyboardModifiers modifiers); void sendSilent(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 55d6435fb..ae3223a01 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -852,7 +852,7 @@ void ScheduledWidget::paintEvent(QPaintEvent *e) { //auto ms = crl::now(); //_historyDownShown.step(ms); - SectionWidget::PaintBackground(this, e->rect()); + SectionWidget::PaintBackground(controller(), this, e->rect()); } void ScheduledWidget::onScroll() { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index df2dcb7e1..e322ce035 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -145,7 +145,6 @@ TopBarWidget::TopBarWidget( lifetime()); setCursor(style::cur_pointer); - updateControlsVisibility(); } TopBarWidget::~TopBarWidget() = default; @@ -182,7 +181,7 @@ void TopBarWidget::refreshLang() { void TopBarWidget::onSearch() { if (_activeChat) { - App::main()->searchInChat(_activeChat); + _controller->content()->searchInChat(_activeChat); } } @@ -620,7 +619,7 @@ void TopBarWidget::updateControlsVisibility() { _sendNow->setVisible(_canSendNow); auto backVisible = Adaptive::OneColumn() - || (App::main() && !App::main()->stackIsEmpty()) + || !_controller->content()->stackIsEmpty() || _activeChat.folder(); _back->setVisible(backVisible); if (_info) { @@ -653,11 +652,8 @@ void TopBarWidget::updateControlsVisibility() { } void TopBarWidget::updateMembersShowArea() { - if (!App::main()) { - return; - } - auto membersShowAreaNeeded = [this]() { - auto peer = App::main()->peer(); + const auto membersShowAreaNeeded = [&] { + auto peer = _controller->content()->peer(); if ((_selectedCount > 0) || !peer) { return false; } @@ -668,8 +664,8 @@ void TopBarWidget::updateMembersShowArea() { return megagroup->canViewMembers() && (megagroup->membersCount() < Global::ChatSizeMax()); } return false; - }; - if (!membersShowAreaNeeded()) { + }(); + if (!membersShowAreaNeeded) { if (_membersShowArea) { _membersShowAreaActive.fire(false); _membersShowArea.destroy(); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index b3ca0b051..feaca96cc 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -51,7 +51,7 @@ public: not_null controller); ~TopBarWidget(); - Main::Session &session() const; + [[nodiscard]] Main::Session &session() const; void updateControlsVisibility(); void finishAnimating(); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index fafe5299f..5b9389258 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -1019,7 +1019,9 @@ bool Widget::overlaps(const QRect &globalRect) const { } void Widget::inlineBotChanged() { - if (!_inlineBot) return; + if (!_inlineBot) { + return; + } if (!isHidden() && !_hiding) { hideAnimated(); @@ -1033,12 +1035,12 @@ void Widget::inlineBotChanged() { _inner->inlineBotChanged(); _inner->hideInlineRowsPanel(); - Notify::inlineBotRequesting(false); + _requesting.fire(false); } void Widget::inlineResultsDone(const MTPmessages_BotResults &result) { _inlineRequestId = 0; - Notify::inlineBotRequesting(false); + _requesting.fire(false); auto it = _inlineCache.find(_inlineQuery); auto adding = (it != _inlineCache.cend()); @@ -1104,7 +1106,7 @@ void Widget::queryInlineBot(UserData *bot, PeerData *peer, QString query) { if (_inlineRequestId) { MTP::cancel(_inlineRequestId); _inlineRequestId = 0; - Notify::inlineBotRequesting(false); + _requesting.fire(false); } if (_inlineCache.find(query) != _inlineCache.cend()) { _inlineRequestTimer.stop(); @@ -1129,7 +1131,7 @@ void Widget::onInlineRequest() { return; } } - Notify::inlineBotRequesting(true); + _requesting.fire(true); _inlineRequestId = _api.request(MTPmessages_GetInlineBotResults( MTP_flags(0), _inlineBot->inputUser, @@ -1141,7 +1143,7 @@ void Widget::onInlineRequest() { inlineResultsDone(result); }).fail([=](const RPCError &error) { // show error? - Notify::inlineBotRequesting(false); + _requesting.fire(false); _inlineRequestId = 0; }).handleAllErrors().send(); } diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index 3a763b3c0..c2e93dbe3 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -199,6 +199,10 @@ public: _inner->setResultSelectedCallback(std::move(callback)); } + [[nodiscard]] rpl::producer requesting() const { + return _requesting.events(); + } + ~Widget(); protected: @@ -276,6 +280,8 @@ private: QString _inlineQuery, _inlineNextQuery, _inlineNextOffset; mtpRequestId _inlineRequestId = 0; + rpl::event_stream _requesting; + }; } // namespace Layout diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e41cd4d47..664c3c8ef 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -525,6 +525,10 @@ Main::Session &MainWidget::session() const { return _controller->session(); } +not_null MainWidget::controller() const { + return _controller; +} + void MainWidget::setupConnectingWidget() { using namespace rpl::mappers; _connecting = std::make_unique( @@ -772,19 +776,11 @@ void MainWidget::onFilesOrForwardDrop( } } -void MainWidget::notify_botCommandsChanged(UserData *bot) { - _history->notify_botCommandsChanged(bot); -} - -void MainWidget::notify_inlineBotRequesting(bool requesting) { - _history->notify_inlineBotRequesting(requesting); -} - -void MainWidget::notify_replyMarkupUpdated(const HistoryItem *item) { +void MainWidget::notify_replyMarkupUpdated(not_null item) { _history->notify_replyMarkupUpdated(item); } -void MainWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { +void MainWidget::notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop) { _history->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop); } @@ -792,10 +788,6 @@ bool MainWidget::notify_switchInlineBotButtonReceived(const QString &query, User return _history->notify_switchInlineBotButtonReceived(query, samePeerBot, samePeerReplyTo); } -void MainWidget::notify_userIsBotChanged(UserData *bot) { - _history->notify_userIsBotChanged(bot); -} - void MainWidget::clearHider(not_null instance) { if (_hider != instance) { return; @@ -1010,7 +1002,11 @@ MsgId MainWidget::currentReplyToIdFor(not_null history) const { return 0; } -void MainWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) { +void MainWidget::sendBotCommand( + not_null peer, + UserData *bot, + const QString &cmd, + MsgId replyTo) { _history->sendBotCommand(peer, bot, cmd, replyTo); } @@ -1435,10 +1431,6 @@ Image *MainWidget::newBackgroundThumb() { : nullptr; } -void MainWidget::messageDataReceived(ChannelData *channel, MsgId msgId) { - _history->messageDataReceived(channel, msgId); -} - void MainWidget::updateBotKeyboard(History *h) { _history->updateBotKeyboard(h); } @@ -2180,16 +2172,6 @@ void MainWidget::sentUpdatesReceived(uint64 randomId, const MTPUpdates &result) feedUpdates(result, randomId); } -bool MainWidget::deleteChannelFailed(const RPCError &error) { - if (MTP::isDefaultHandledError(error)) return false; - - //if (error.type() == qstr("CHANNEL_TOO_LARGE")) { - // Ui::show(Box(tr::lng_cant_delete_channel(tr::now))); - //} - - return true; -} - void MainWidget::historyToDown(History *history) { _history->historyToDown(history); } @@ -2984,7 +2966,11 @@ void MainWidget::gotDifference(const MTPupdates_Difference &difference) { }; } -bool MainWidget::getDifferenceTimeChanged(ChannelData *channel, int32 ms, ChannelGetDifferenceTime &channelCurTime, crl::time &curTime) { +bool MainWidget::getDifferenceTimeChanged( + ChannelData *channel, + int32 ms, + ChannelGetDifferenceTime &channelCurTime, + crl::time &curTime) { if (channel) { if (ms <= 0) { ChannelGetDifferenceTime::iterator i = channelCurTime.find(channel); @@ -3133,11 +3119,11 @@ void MainWidget::getDifferenceAfterFail() { } void MainWidget::getDifference() { - if (this != App::main()) return; - _getDifferenceTimeByPts = 0; - if (requestingDifference()) return; + if (requestingDifference()) { + return; + } _bySeqUpdates.clear(); _bySeqTimer.cancel(); @@ -3158,9 +3144,9 @@ void MainWidget::getDifference() { rpcFail(&MainWidget::failDifference)); } -void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceRequest from) { - if (this != App::main() || !channel) return; - +void MainWidget::getChannelDifference( + not_null channel, + ChannelDifferenceRequest from) { if (from != ChannelDifferenceRequest::PtsGapOrShortPoll) { _channelGetDifferenceTimeByPts.remove(channel); } @@ -3187,8 +3173,8 @@ void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceReq filter, MTP_int(channel->pts()), MTP_int(kChannelGetDifferenceLimit)), - rpcDone(&MainWidget::gotChannelDifference, channel), - rpcFail(&MainWidget::failChannelDifference, channel)); + rpcDone(&MainWidget::gotChannelDifference, channel.get()), + rpcFail(&MainWidget::failChannelDifference, channel.get())); } void MainWidget::sendPing() { @@ -4628,7 +4614,7 @@ namespace App { MainWidget *main() { if (const auto window = wnd()) { - return window->mainWidget(); + return window->sessionContent(); } return nullptr; } diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index bda4ab0e6..a90a94914 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -113,6 +113,7 @@ public: not_null controller); [[nodiscard]] Main::Session &session() const; + [[nodiscard]] not_null controller() const; [[nodiscard]] bool isMainSectionShown() const; [[nodiscard]] bool isThirdSectionShown() const; @@ -149,7 +150,6 @@ public: void sentUpdatesReceived(const MTPUpdates &updates) { return sentUpdatesReceived(0, updates); } - bool deleteChannelFailed(const RPCError &error); void historyToDown(History *hist); void dialogsToUp(); void checkHistoryActivation(); @@ -211,7 +211,11 @@ public: MsgId currentReplyToIdFor(not_null history) const; - void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo); + void sendBotCommand( + not_null peer, + UserData *bot, + const QString &cmd, + MsgId replyTo); void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo); bool insertBotCommand(const QString &cmd); @@ -233,7 +237,6 @@ public: void checkChatBackground(); Image *newBackgroundThumb(); - void messageDataReceived(ChannelData *channel, MsgId msgId); void updateBotKeyboard(History *h); void pushReplyReturn(not_null item); @@ -284,12 +287,9 @@ public: MsgId msgId); PeerData *ui_getPeerForMouseAction(); - void notify_botCommandsChanged(UserData *bot); - void notify_inlineBotRequesting(bool requesting); - void notify_replyMarkupUpdated(const HistoryItem *item); - void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); + void notify_replyMarkupUpdated(not_null item); + void notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop); bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo); - void notify_userIsBotChanged(UserData *bot); void closeBothPlayers(); @@ -381,7 +381,9 @@ private: void saveSectionInStack(); - void getChannelDifference(ChannelData *channel, ChannelDifferenceRequest from = ChannelDifferenceRequest::Unknown); + void getChannelDifference( + not_null channel, + ChannelDifferenceRequest from = ChannelDifferenceRequest::Unknown); void gotDifference(const MTPupdates_Difference &diff); bool failDifference(const RPCError &e); void feedDifference(const MTPVector &users, const MTPVector &chats, const MTPVector &msgs, const MTPVector &other); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index c64cca946..0ea02edc4 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -405,8 +405,8 @@ void MainWindow::ui_removeLayerBlackout() { } } -MainWidget *MainWindow::mainWidget() { - return _main; +MainWidget *MainWindow::sessionContent() const { + return _main.data(); } void MainWindow::ui_showBox( diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 2f52c2107..831d1cc90 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -56,11 +56,7 @@ public: void setupIntro(); void setupMain(); - MainWidget *chatsWidget() { - return mainWidget(); - } - - MainWidget *mainWidget(); + MainWidget *sessionContent() const; [[nodiscard]] bool doWeMarkAsRead(); diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index 67ce10c0c..ec5d7981d 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -62,6 +62,7 @@ struct PeerUpdate { UserHasCalls = (1 << 27), UserOccupiedChanged = (1 << 28), UserSupportInfoChanged = (1 << 29), + UserIsBotChanged = (1 << 30), // For channels ChannelAmIn = (1 << 19), diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 1872e164c..2c12dc312 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -313,7 +313,7 @@ void SetupSpellchecker( Spellchecker::ButtonManageDictsState(session), st::settingsButton )->addClickHandler([=] { - Ui::show(Box(session)); + Ui::show(Box(controller)); }); button->toggledValue( diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 110e62154..0cf56d137 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -393,7 +393,7 @@ private: }; void ChooseFromFile( - not_null<::Main::Session*> session, + not_null controller, not_null parent); BackgroundRow::BackgroundRow( @@ -409,10 +409,10 @@ BackgroundRow::BackgroundRow( updateImage(); _chooseFromGallery->addClickHandler([=] { - Ui::show(Box(&controller->session())); + Ui::show(Box(controller)); }); _chooseFromFile->addClickHandler([=] { - ChooseFromFile(&controller->session(), this); + ChooseFromFile(controller, this); }); using Update = const Window::Theme::BackgroundUpdate; @@ -594,7 +594,7 @@ void BackgroundRow::updateImage() { } void ChooseFromFile( - not_null<::Main::Session*> session, + not_null controller, not_null parent) { const auto &imgExtensions = cImgExtensions(); auto filters = QStringList( @@ -602,7 +602,7 @@ void ChooseFromFile( + imgExtensions.join(qsl(" *")) + qsl(")")); filters.push_back(FileDialog::AllFilesFilter()); - const auto callback = crl::guard(session, [=]( + const auto callback = crl::guard(controller, [=]( const FileDialog::OpenResult &result) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { return; @@ -629,7 +629,7 @@ void ChooseFromFile( auto local = Data::CustomWallPaper(); local.setLocalImageAsThumbnail(std::make_shared( std::move(image))); - Ui::show(Box(session, local)); + Ui::show(Box(controller, local)); }); FileDialog::GetOpenPath( parent.get(), diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index a1f42e975..c4c0446ff 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -681,8 +681,8 @@ rpl::producer CallsPeer2PeerPrivacyController::exceptionsDescription() } ForwardsPrivacyController::ForwardsPrivacyController( - not_null<::Main::Session*> session) -: _session(session) { + not_null controller) +: _controller(controller) { } ApiWrap::Privacy::Key ForwardsPrivacyController::key() { @@ -735,7 +735,7 @@ object_ptr ForwardsPrivacyController::setupAboveWidget( auto message = GenerateForwardedItem( delegate(), - _session->data().history( + _controller->session().data().history( peerFromUser(PeerData::kServiceNotificationsId)), tr::lng_edit_privacy_forwards_sample_message(tr::now)); const auto view = message.get(); @@ -760,7 +760,7 @@ object_ptr ForwardsPrivacyController::setupAboveWidget( widget->paintRequest( ) | rpl::start_with_next([=](QRect rect) { - Window::SectionWidget::PaintBackground(widget, rect); + Window::SectionWidget::PaintBackground(_controller, widget, rect); Painter p(widget); p.translate(0, padding + view->marginBottom()); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 461b97b25..8dd664041 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_element.h" #include "mtproto/sender.h" +namespace Window { +class SessionController; +} // namespace Window + namespace Settings { class BlockedBoxController @@ -168,7 +172,8 @@ public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; - explicit ForwardsPrivacyController(not_null<::Main::Session*> session); + explicit ForwardsPrivacyController( + not_null controller); Key key() override; MTPInputPrivacyKey apiKey() override; @@ -195,7 +200,7 @@ private: not_null view, Option value); - const not_null<::Main::Session*> _session; + const not_null _controller; }; diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index d954034ad..eb39295cf 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -164,7 +164,7 @@ void SetupPrivacy( add( tr::lng_settings_forwards_privacy(), Key::Forwards, - [=] { return std::make_unique(session); }); + [=] { return std::make_unique(controller); }); add( tr::lng_settings_profile_photo_privacy(), Key::ProfilePhoto, diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index 9b7785c96..ec0d39582 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -48,7 +48,7 @@ class EditInfoBox : public Ui::BoxContent { public: EditInfoBox( QWidget*, - not_null session, + not_null controller, const TextWithTags &text, Fn)> submit); @@ -57,7 +57,7 @@ protected: void setInnerFocus() override; private: - not_null _session; + const not_null _controller; object_ptr _field = { nullptr }; Fn)> _submit; @@ -65,10 +65,10 @@ private: EditInfoBox::EditInfoBox( QWidget*, - not_null session, + not_null controller, const TextWithTags &text, Fn)> submit) -: _session(session) +: _controller(controller) , _field( this, st::supportInfoField, @@ -77,12 +77,13 @@ EditInfoBox::EditInfoBox( text) , _submit(std::move(submit)) { _field->setMaxLength(kMaxSupportInfoLength); - _field->setSubmitSettings(session->settings().sendSubmitWay()); + _field->setSubmitSettings( + controller->session().settings().sendSubmitWay()); _field->setInstantReplaces(Ui::InstantReplaces::Default()); _field->setInstantReplacesEnabled( - session->settings().replaceEmojiValue()); + controller->session().settings().replaceEmojiValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); - _field->setEditLinkCallback(DefaultEditLinkCallback(session, _field)); + _field->setEditLinkCallback(DefaultEditLinkCallback(controller, _field)); } void EditInfoBox::prepare() { @@ -106,7 +107,7 @@ void EditInfoBox::prepare() { Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), _field, - _session); + &_controller->session()); auto cursor = _field->textCursor(); cursor.movePosition(QTextCursor::End); @@ -427,9 +428,10 @@ void Helper::refreshInfo(not_null user) { user->inputUser )).done([=](const MTPhelp_UserInfo &result) { applyInfo(user, result); - if (_userInfoEditPending.contains(user)) { - _userInfoEditPending.erase(user); - showEditInfoBox(user); + if (const auto controller = _userInfoEditPending.take(user)) { + if (const auto strong = controller->get()) { + showEditInfoBox(strong, user); + } } }).send(); } @@ -497,14 +499,18 @@ UserInfo Helper::infoCurrent(not_null user) const { return (i != end(_userInformation)) ? i->second : UserInfo(); } -void Helper::editInfo(not_null user) { +void Helper::editInfo( + not_null controller, + not_null user) { if (!_userInfoEditPending.contains(user)) { - _userInfoEditPending.emplace(user); + _userInfoEditPending.emplace(user, controller.get()); refreshInfo(user); } } -void Helper::showEditInfoBox(not_null user) { +void Helper::showEditInfoBox( + not_null controller, + not_null user) { const auto info = infoCurrent(user); const auto editData = TextWithTags{ info.text.text, @@ -518,7 +524,7 @@ void Helper::showEditInfoBox(not_null user) { }, done); }; Ui::show( - Box(&user->session(), editData, save), + Box(controller, editData, save), Ui::LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/support/support_helper.h b/Telegram/SourceFiles/support/support_helper.h index 1352705fa..fd46acd38 100644 --- a/Telegram/SourceFiles/support/support_helper.h +++ b/Telegram/SourceFiles/support/support_helper.h @@ -59,7 +59,9 @@ public: rpl::producer infoTextValue( not_null user) const; UserInfo infoCurrent(not_null user) const; - void editInfo(not_null user); + void editInfo( + not_null controller, + not_null user); Templates &templates(); @@ -80,7 +82,9 @@ private: void applyInfo( not_null user, const MTPhelp_UserInfo &result); - void showEditInfoBox(not_null user); + void showEditInfoBox( + not_null controller, + not_null user); void saveInfo( not_null user, TextWithEntities text, @@ -98,7 +102,9 @@ private: base::flat_map, TimeId> _occupiedChats; base::flat_map, UserInfo> _userInformation; - base::flat_set> _userInfoEditPending; + base::flat_map< + not_null, + base::weak_ptr> _userInfoEditPending; base::flat_map, SavingInfo> _userInfoSaving; rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/window/section_widget.cpp b/Telegram/SourceFiles/window/section_widget.cpp index aa298db0c..5a7119ae6 100644 --- a/Telegram/SourceFiles/window/section_widget.cpp +++ b/Telegram/SourceFiles/window/section_widget.cpp @@ -84,17 +84,20 @@ QPixmap SectionWidget::grabForShowAnimation( return Ui::GrabWidget(this); } -void SectionWidget::PaintBackground(not_null widget, QRect clip) { +void SectionWidget::PaintBackground( + not_null controller, + not_null widget, + QRect clip) { Painter p(widget); - auto fill = QRect(0, 0, widget->width(), App::main()->height()); + auto fill = QRect(0, 0, widget->width(), controller->content()->height()); if (const auto color = Window::Theme::Background()->colorForFill()) { p.fillRect(fill, *color); return; } - auto fromy = App::main()->backgroundFromY(); + auto fromy = controller->content()->backgroundFromY(); auto x = 0, y = 0; - auto cached = App::main()->cachedBackground(fill, x, y); + auto cached = controller->content()->cachedBackground(fill, x, y); if (cached.isNull()) { if (Window::Theme::Background()->tile()) { auto &pix = Window::Theme::Background()->pixmapForTiled(); diff --git a/Telegram/SourceFiles/window/section_widget.h b/Telegram/SourceFiles/window/section_widget.h index f244a0f5a..fd5a33e3a 100644 --- a/Telegram/SourceFiles/window/section_widget.h +++ b/Telegram/SourceFiles/window/section_widget.h @@ -44,6 +44,9 @@ public: } [[nodiscard]] Main::Session &session() const; + [[nodiscard]] not_null controller() const { + return _controller; + } // Tabbed selector management. virtual bool pushTabbedSelectorToThirdSection( @@ -63,11 +66,6 @@ public: return mapToGlobal(rect()); } -protected: - [[nodiscard]] not_null controller() const { - return _controller; - } - private: const not_null _controller; @@ -88,7 +86,9 @@ struct SectionSlideParams { class SectionWidget : public AbstractSectionWidget { public: - SectionWidget(QWidget *parent, not_null controller); + SectionWidget( + QWidget *parent, + not_null controller); virtual Dialogs::RowDescriptor activeChat() const { return {}; @@ -140,7 +140,10 @@ public: return nullptr; } - static void PaintBackground(not_null widget, QRect clip); + static void PaintBackground( + not_null controller, + not_null widget, + QRect clip); protected: void paintEvent(QPaintEvent *e) override; diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index ee7b6388b..28d1b646c 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -135,7 +135,7 @@ MainMenu::MainMenu( setAttribute(Qt::WA_OpaquePaintEvent); const auto showSelfChat = [=] { - App::main()->choosePeer( + controller->content()->choosePeer( _controller->session().userPeerId(), ShowAtUnreadMsgId); }; @@ -143,7 +143,7 @@ MainMenu::MainMenu( const auto folder = _controller->session().data().folderLoaded( Data::Folder::kId); if (folder) { - App::wnd()->sessionController()->openFolder(folder); + controller->openFolder(folder); Ui::hideSettingsAndLayer(); } }; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 81427895c..40a2ca3b9 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -460,7 +460,7 @@ void Filler::addUserActions(not_null user) { if (_source != PeerMenuSource::ChatsList) { if (user->session().supportMode()) { _addAction("Edit support info", [=] { - user->session().supportHelper().editInfo(user); + user->session().supportHelper().editInfo(controller, user); }); } if (!user->isContact() && !user->isSelf() && !user->isBot()) { @@ -490,7 +490,7 @@ void Filler::addUserActions(not_null user) { if (user->canSendPolls()) { _addAction( tr::lng_polls_create(tr::now), - [=] { PeerMenuCreatePoll(user); }); + [=] { PeerMenuCreatePoll(controller, user); }); } if (user->canExportChatHistory()) { _addAction( @@ -528,7 +528,7 @@ void Filler::addChatActions(not_null chat) { if (chat->canSendPolls()) { _addAction( tr::lng_polls_create(tr::now), - [=] { PeerMenuCreatePoll(chat); }); + [=] { PeerMenuCreatePoll(controller, chat); }); } if (chat->canExportChatHistory()) { _addAction( @@ -574,7 +574,7 @@ void Filler::addChannelActions(not_null channel) { if (channel->canSendPolls()) { _addAction( tr::lng_polls_create(tr::now), - [=] { PeerMenuCreatePoll(channel); }); + [=] { PeerMenuCreatePoll(navigation, channel); }); } if (channel->canExportChatHistory()) { _addAction( @@ -790,6 +790,7 @@ void PeerMenuShareContactBox( } void PeerMenuCreatePoll( + not_null controller, not_null peer, PollData::Flags chosen, PollData::Flags disabled) { @@ -798,7 +799,7 @@ void PeerMenuCreatePoll( disabled |= PollData::Flag::PublicVotes; } const auto box = Ui::show(Box( - &peer->session(), + controller, chosen, disabled, Api::SendType::Normal)); @@ -811,7 +812,7 @@ void PeerMenuCreatePoll( auto action = Api::SendAction(peer->owner().history(peer)); action.clearDraft = false; action.options = result.options; - if (const auto id = App::main()->currentReplyToIdFor(action.history)) { + if (const auto id = controller->content()->currentReplyToIdFor(action.history)) { action.replyTo = id; } if (const auto localDraft = action.history->localDraft()) { @@ -919,7 +920,8 @@ QPointer ShowForwardMessagesBox( auto callback = [ ids = std::move(items), callback = std::move(successCallback), - weak + weak, + navigation ](not_null peer) mutable { if (peer->isSelf()) { auto items = peer->owner().idsToItems(ids); @@ -932,7 +934,7 @@ QPointer ShowForwardMessagesBox( Ui::Toast::Show(tr::lng_share_done(tr::now)); }); } - } else if (!App::main()->setForwardDraft(peer->id, std::move(ids))) { + } else if (!navigation->parentController()->content()->setForwardDraft(peer->id, std::move(ids))) { return; } if (const auto strong = *weak) { diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index cfdeecd8c..e68bdb138 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -62,6 +62,7 @@ void PeerMenuAddChannelMembers( not_null channel); //void PeerMenuUngroupFeed(not_null feed); // #feed void PeerMenuCreatePoll( + not_null controller, not_null peer, PollData::Flags chosen = PollData::Flags(), PollData::Flags disabled = PollData::Flags()); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index b21ec467d..bf2bf67dc 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -158,7 +158,7 @@ auto SessionController::tabbedSelector() const void SessionController::takeTabbedSelectorOwnershipFrom( not_null parent) { if (_tabbedSelector->parent() == parent) { - if (const auto chats = widget()->chatsWidget()) { + if (const auto chats = widget()->sessionContent()) { chats->returnTabbedSelector(); } if (_tabbedSelector->parent() == parent) { @@ -395,7 +395,7 @@ bool SessionController::forceWideDialogs() const { } else if (dialogsListFocused().value()) { return true; } - return !App::main()->isMainSectionShown(); + return !content()->isMainSectionShown(); } auto SessionController::computeColumnLayout() const -> ColumnLayout { @@ -499,7 +499,7 @@ bool SessionController::canShowThirdSectionWithoutResize() const { } bool SessionController::takeThirdSectionFromLayer() { - return App::wnd()->takeThirdSectionFromLayer(); + return widget()->takeThirdSectionFromLayer(); } void SessionController::resizeForThirdSection() { @@ -682,14 +682,14 @@ void SessionController::clearPassportForm() { } void SessionController::updateColumnLayout() { - App::main()->updateColumnLayout(); + content()->updateColumnLayout(); } void SessionController::showPeerHistory( PeerId peerId, const SectionShow ¶ms, MsgId msgId) { - App::main()->ui_showPeerHistory( + content()->ui_showPeerHistory( peerId, params, msgId); @@ -718,30 +718,30 @@ void SessionController::showPeerHistory( void SessionController::showSection( SectionMemento &&memento, const SectionShow ¶ms) { - if (!params.thirdColumn && App::wnd()->showSectionInExistingLayer( + if (!params.thirdColumn && widget()->showSectionInExistingLayer( &memento, params)) { return; } - App::main()->showSection(std::move(memento), params); + content()->showSection(std::move(memento), params); } void SessionController::showBackFromStack(const SectionShow ¶ms) { - chats()->showBackFromStack(params); + content()->showBackFromStack(params); } void SessionController::showSpecialLayer( object_ptr &&layer, anim::type animated) { - App::wnd()->showSpecialLayer(std::move(layer), animated); + widget()->showSpecialLayer(std::move(layer), animated); } void SessionController::removeLayerBlackout() { - App::wnd()->ui_removeLayerBlackout(); + widget()->ui_removeLayerBlackout(); } -not_null SessionController::chats() const { - return App::wnd()->chatsWidget(); +not_null SessionController::content() const { + return widget()->sessionContent(); } void SessionController::setDefaultFloatPlayerDelegate( diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 57aa189cb..8ef98ff05 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/flags.h" #include "base/observer.h" #include "base/object_ptr.h" +#include "base/weak_ptr.h" #include "dialogs/dialogs_key.h" #include "ui/effects/animation_value.h" @@ -163,6 +164,7 @@ private: class SessionController : public SessionNavigation + , public base::has_weak_ptr , private base::Subscriber { public: SessionController( @@ -173,6 +175,7 @@ public: return *_window; } [[nodiscard]] not_null<::MainWindow*> widget() const; + [[nodiscard]] not_null content() const; [[nodiscard]] auto tabbedSelector() const -> not_null; @@ -314,7 +317,6 @@ private: void checkOpenedFilter(); int minimalThreeColumnWidth() const; - not_null chats() const; int countDialogsWidthFromRatio(int bodyWidth) const; int countThirdColumnWidthFromRatio(int bodyWidth) const; struct ShrinkResult {