diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index 97ff21621..c50fa875e 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -193,8 +193,8 @@ void SendExistingDocument( if (document->sticker()) { if (const auto main = App::main()) { main->incrementSticker(document); - document->owner().stickers().notifyRecentUpdated(); } + document->owner().stickers().notifyRecentUpdated(); } } diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index b1ad4c216..980c84b26 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -461,8 +461,8 @@ void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) { const auto index = stickerFromGlobalPos(e->globalPos()); if (index >= 0 && index < _pack.size() && !isMasksSet()) { const auto sticker = _pack[index]; - Ui::PostponeCall(crl::guard(App::main(), [=] { - if (App::main()->onSendSticker(sticker)) { + Ui::PostponeCall(crl::guard(_controller, [=] { + if (_controller->content()->sendExistingDocument(sticker)) { Ui::hideSettingsAndLayer(); } })); diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index f6e90c4f3..88754cb92 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -302,10 +302,14 @@ void BoxController::refreshAbout() { } void BoxController::rowClicked(not_null row) { - auto itemsRow = static_cast(row.get()); - auto itemId = itemsRow->maxItemId(); - InvokeQueued(App::main(), [peerId = row->peer()->id, itemId] { - Ui::showPeerHistory(peerId, itemId); + const auto itemsRow = static_cast(row.get()); + const auto itemId = itemsRow->maxItemId(); + const auto window = _window; + crl::on_main(window, [=, peer = row->peer()] { + window->showPeerHistory( + peer, + Window::SectionShow::Way::ClearStack, + itemId); }); } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 20f40fc25..354dd4f1f 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -904,16 +904,18 @@ ClickHandlerPtr goToMessageClickHandler( MsgId msgId, FullMsgId returnToId) { return std::make_shared([=] { - if (const auto main = App::main()) { - if (const auto returnTo = peer->owner().message(returnToId)) { - if (returnTo->history()->peer == peer) { - main->pushReplyReturn(returnTo); + if (const auto main = App::main()) { // multi good + if (&main->session() == &peer->session()) { + if (const auto returnTo = peer->owner().message(returnToId)) { + if (returnTo->history()->peer == peer) { + main->pushReplyReturn(returnTo); + } } + main->controller()->showPeerHistory( + peer, + Window::SectionShow::Way::Forward, + msgId); } - App::wnd()->sessionController()->showPeerHistory( - peer, - Window::SectionShow::Way::Forward, - msgId); } }); } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 898d71eff..7ba718719 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -506,8 +506,9 @@ bool AddDeleteMessageAction( } } } + const auto controller = list->controller(); const auto itemId = item->fullId(); - menu->addAction(tr::lng_context_delete_msg(tr::now), [=] { + const auto callback = crl::guard(controller, [=] { if (const auto item = owner->message(itemId)) { if (asGroup) { if (const auto group = owner->groups().find(item)) { @@ -519,7 +520,7 @@ bool AddDeleteMessageAction( } if (const auto message = item->toHistoryMessage()) { if (message->uploading()) { - App::main()->cancelUploadLayer(item); + controller->content()->cancelUploadLayer(item); return; } } @@ -527,6 +528,7 @@ bool AddDeleteMessageAction( Ui::show(Box(item, suggestModerateActions)); } }); + menu->addAction(tr::lng_context_delete_msg(tr::now), callback); return true; } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index c93c0128e..84b8ba105 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -305,6 +305,10 @@ Main::Session &ListWidget::session() const { return _controller->session(); } +not_null ListWidget::controller() const { + return _controller; +} + not_null ListWidget::delegate() const { return _delegate; } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 877d986f1..a36122faa 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -137,9 +137,9 @@ public: not_null controller, not_null delegate); - Main::Session &session() const; - - not_null delegate() const; + [[nodiscard]] Main::Session &session() const; + [[nodiscard]] not_null controller() const; + [[nodiscard]] not_null delegate() const; // Set the correct scroll position after being resized. void restoreScrollPosition(); @@ -437,8 +437,8 @@ private: static constexpr auto kMinimalIdsLimit = 24; - not_null _delegate; - not_null _controller; + const not_null _delegate; + const not_null _controller; Data::MessagePosition _aroundPosition; Data::MessagePosition _shownAtPosition; Context _context; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 6027b62cd..049b5decb 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1668,8 +1668,10 @@ ClickHandlerPtr Message::fastReplyLink() const { const auto itemId = data()->fullId(); _fastReplyLink = std::make_shared([=] { if (const auto item = owner->message(itemId)) { - if (const auto main = App::main()) { - main->replyToItem(item); + if (const auto main = App::main()) { // multi good + if (&main->session() == &owner->session()) { + main->replyToItem(item); + } } } }); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 931dbd9f6..44f0e04db 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1108,7 +1108,7 @@ void MainWidget::onSendFileConfirm( _history->sendFileConfirmed(file, oldId); } -bool MainWidget::onSendSticker(DocumentData *document) { +bool MainWidget::sendExistingDocument(not_null document) { return _history->sendExistingDocument(document); } diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index fb843bf7a..e56b78b2a 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -166,7 +166,7 @@ public: void onSendFileConfirm( const std::shared_ptr &file, const std::optional &oldId); - bool onSendSticker(DocumentData *sticker); + bool sendExistingDocument(not_null sticker); bool isActive() const; [[nodiscard]] bool doWeMarkAsRead() const; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 6271f0cb3..454888403 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1444,6 +1444,10 @@ void OverlayWidget::onForward() { if (!_session) { return; } + const auto &active = _session->windows(); + if (active.empty()) { + return; + } const auto item = _session->data().message(_msgid); if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) { return; @@ -1451,7 +1455,7 @@ void OverlayWidget::onForward() { close(); Window::ShowForwardMessagesBox( - App::wnd()->sessionController(), + active.front(), { 1, item->fullId() }); } @@ -1474,8 +1478,12 @@ void OverlayWidget::onDelete() { return false; }; + const auto &active = _session->windows(); + if (active.empty()) { + return; + } if (deletingPeerPhoto()) { - App::main()->deletePhotoLayer(_photo); + active.front()->content()->deletePhotoLayer(_photo); } else if (const auto item = session->data().message(_msgid)) { const auto suggestModerateActions = true; Ui::show(Box(item, suggestModerateActions)); diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index a6c913fe9..e6cb2017f 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -602,18 +602,20 @@ void AppendEmojiPacks( } - (void) buttonActionPin:(NSButton *)sender { + const auto active = Core::App().activeWindow(); + const auto controller = active ? active->sessionController() : nullptr; const auto openFolder = [=] { - if (!App::wnd()) { + if (!controller) { return; } if (const auto folder = _session->data().folderLoaded(Data::Folder::kId)) { - App::wnd()->sessionController()->openFolder(folder); + controller->openFolder(folder); } }; Core::Sandbox::Instance().customEnterFromEventLoop([=] { self.number == kArchiveId ? openFolder() - : App::main()->choosePeer(self.number == kSavedMessagesId + : controller->content()->choosePeer(self.number == kSavedMessagesId ? _session->userPeerId() : self.peer->id, ShowAtUnreadMsgId); }); @@ -1477,6 +1479,8 @@ void AppendEmojiPacks( - (void) buttonAction:(NSButton *)sender { const auto command = sender.tag; + const auto active = Core::App().activeWindow(); + const auto controller = active ? active->sessionController() : nullptr; Core::Sandbox::Instance().customEnterFromEventLoop([=] { switch (command) { case kCommandPlayPause: @@ -1489,7 +1493,7 @@ void AppendEmojiPacks( Media::Player::instance()->next(kSongType); break; case kCommandClosePlayer: - App::main()->closeBothPlayers(); + controller->content()->closeBothPlayers(); break; } }); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 0cf56d137..707a6b254 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -384,6 +384,7 @@ private: crl::time radialTimeShift() const; void radialAnimationCallback(crl::time now); + const not_null _controller; QPixmap _background; object_ptr _chooseFromGallery; object_ptr _chooseFromFile; @@ -400,6 +401,7 @@ BackgroundRow::BackgroundRow( QWidget *parent, not_null controller) : RpWidget(parent) +, _controller(controller) , _chooseFromGallery( this, tr::lng_settings_bg_from_gallery(tr::now), @@ -433,7 +435,7 @@ void BackgroundRow::paintEvent(QPaintEvent *e) { const auto radial = _radial.animating(); const auto radialOpacity = radial ? _radial.opacity() : 0.; if (radial) { - const auto backThumb = App::main()->newBackgroundThumb(); + const auto backThumb = _controller->content()->newBackgroundThumb(); if (!backThumb) { p.drawPixmap(0, 0, _background); } else { @@ -494,14 +496,14 @@ int BackgroundRow::resizeGetHeight(int newWidth) { } float64 BackgroundRow::radialProgress() const { - return App::main()->chatBackgroundProgress(); + return _controller->content()->chatBackgroundProgress(); } bool BackgroundRow::radialLoading() const { - const auto main = App::main(); - if (main->chatBackgroundLoading()) { - main->checkChatBackground(); - if (main->chatBackgroundLoading()) { + const auto widget = _controller->content(); + if (widget->chatBackgroundLoading()) { + widget->checkChatBackground(); + if (widget->chatBackgroundLoading()) { return true; } else { const_cast(this)->updateImage(); @@ -788,9 +790,7 @@ void SetupMessages( group->setChangedCallback([=](SendByType value) { controller->session().settings().setSendSubmitWay(value); - if (App::main()) { - App::main()->ctrlEnterSubmitUpdated(); - } + controller->content()->ctrlEnterSubmitUpdated(); controller->session().saveSettingsDelayed(); }); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 97a1ab4bb..93aa24c59 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -246,7 +246,8 @@ void BlockedBoxController::loadMoreRows() { } void BlockedBoxController::rowClicked(not_null row) { - InvokeQueued(App::main(), [peerId = row->peer()->id] { + const auto peer = row->peer(); + crl::on_main(&peer->session(), [peerId = peer->id] { Ui::showPeerHistory(peerId, ShowAtUnreadMsgId); }); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 40a2ca3b9..62ba85845 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -170,7 +170,9 @@ bool PinnedLimitReached(Dialogs::Key key, FilterId filterId) { return true; } -void TogglePinnedDialog(Dialogs::Key key) { +void TogglePinnedDialog( + not_null controller, + Dialogs::Key key) { if (!key.entry()->folderKnown()) { return; } @@ -198,15 +200,16 @@ void TogglePinnedDialog(Dialogs::Key key) { )).send(); } if (isPinned) { - if (const auto main = App::main()) { - main->dialogsToUp(); - } + controller->content()->dialogsToUp(); } } -void TogglePinnedDialog(Dialogs::Key key, FilterId filterId) { +void TogglePinnedDialog( + not_null controller, + Dialogs::Key key, + FilterId filterId) { if (!filterId) { - return TogglePinnedDialog(key); + return TogglePinnedDialog(controller, key); } const auto owner = &key.entry()->owner(); @@ -227,9 +230,7 @@ void TogglePinnedDialog(Dialogs::Key key, FilterId filterId) { owner->setChatPinned(key, filterId, isPinned); Api::SaveNewFilterPinned(&owner->session(), filterId); if (isPinned) { - if (const auto main = App::main()) { - main->dialogsToUp(); - } + controller->content()->dialogsToUp(); } } @@ -315,7 +316,10 @@ void Filler::addTogglePin() { : tr::lng_context_pin_to_top(tr::now); }; const auto pinToggle = [=] { - TogglePinnedDialog(peer->owner().history(peer), filterId); + TogglePinnedDialog( + _controller, + peer->owner().history(peer), + filterId); }; const auto pinAction = _addAction(pinText(isPinned), pinToggle); @@ -344,8 +348,10 @@ void Filler::addInfo() { } //void Filler::addSearch() { -// _addAction(tr::lng_profile_search_messages(tr::now), [peer = _peer] { -// App::main()->searchInChat(peer->owner().history(peer)); +// const auto controller = _controller; +// const auto peer = _peer; +// _addAction(tr::lng_profile_search_messages(tr::now), [=] { +// controller->content()->searchInChat(peer->owner().history(peer)); // }); //} @@ -689,8 +695,8 @@ void FolderFiller::addTogglesForArchive() { } // //void FolderFiller::addInfo() { -// auto controller = _controller; -// auto feed = _feed; +// const auto controller = _controller; +// const auto feed = _feed; // _addAction(tr::lng_context_view_feed_info(tr::now), [=] { // controller->showSection(Info::Memento( // feed, @@ -707,8 +713,9 @@ void FolderFiller::addTogglesForArchive() { // //void FolderFiller::addSearch() { // const auto feed = _feed; +// const auto controller = _controller; // _addAction(tr::lng_profile_search_messages(tr::now), [=] { -// App::main()->searchInChat(feed); +// controller->content()->searchInChat(feed); // }); //} //