From d8fb5be9b559fe5b55aa39ab6ea4e85a597875da Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 7 Oct 2021 19:16:42 +0300 Subject: [PATCH] Moved opening peer from PeerClickHandler to SessionController. --- Telegram/SourceFiles/data/data_peer.cpp | 42 +++++++------------ .../history/view/history_view_view_button.cpp | 7 +++- .../window/window_session_controller.cpp | 24 +++++++++++ .../window/window_session_controller.h | 2 + 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index c0144bc4e..b303fac02 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -29,7 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_app_config.h" #include "mtproto/mtproto_config.h" #include "core/application.h" -#include "mainwindow.h" +#include "core/click_handler_types.h" #include "window/window_session_controller.h" #include "ui/image/image.h" #include "ui/empty_userpic.h" @@ -42,7 +42,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_download.h" #include "storage/storage_facade.h" #include "storage/storage_shared_media.h" -#include "facades.h" // Ui::showPeerProfile namespace { @@ -168,33 +167,22 @@ void PeerClickHandler::onClick(ClickContext context) const { if (context.button != Qt::LeftButton) { return; } - const auto &windows = _peer->session().windows(); - if (windows.empty()) { - Core::App().domain().activate(&_peer->session().account()); + const auto my = context.other.value(); + const auto window = [&]() -> Window::SessionController* { + if (const auto controller = my.sessionWindow.get()) { + return controller; + } + const auto &windows = _peer->session().windows(); if (windows.empty()) { - return; + _peer->session().domain().activate(&_peer->session().account()); + if (windows.empty()) { + return nullptr; + } } - } - const auto window = windows.front(); - const auto currentPeer = window->activeChatCurrent().peer(); - if (_peer && _peer->isChannel() && currentPeer != _peer) { - const auto clickedChannel = _peer->asChannel(); - if (!clickedChannel->isPublic() - && !clickedChannel->amIn() - && (!currentPeer->isChannel() - || currentPeer->asChannel()->linkedChat() != clickedChannel)) { - Ui::ShowMultilineToast({ - .text = { _peer->isMegagroup() - ? tr::lng_group_not_accessible(tr::now) - : tr::lng_channel_not_accessible(tr::now) }, - }); - } else { - window->showPeerHistory( - _peer, - Window::SectionShow::Way::Forward); - } - } else { - Ui::showPeerProfile(_peer); + return windows.front(); + }(); + if (window) { + window->showPeer(_peer); } } diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.cpp b/Telegram/SourceFiles/history/view/history_view_view_button.cpp index c1f33bda1..ff444a8d2 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_view_button.cpp @@ -57,7 +57,12 @@ struct ViewButton::Inner { ViewButton::Inner::Inner(not_null peer, Fn updateCallback) : margins(st::historyViewButtonMargins) -, link(peer->openLink()) +, link(std::make_shared([=](ClickContext context) { + const auto my = context.other.value(); + if (const auto controller = my.sessionWindow.get()) { + controller->showPeer(peer); + } +})) , updateCallback(std::move(updateCallback)) , text(st::historyViewButtonTextStyle, PeerToPhrase(peer)) { } diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index e676c3303..9d93b3897 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1074,6 +1074,30 @@ void SessionController::closeThirdSection() { } } +void SessionController::showPeer(not_null peer, MsgId msgId) { + const auto currentPeer = activeChatCurrent().peer(); + if (peer && peer->isChannel() && currentPeer != peer) { + const auto clickedChannel = peer->asChannel(); + if (!clickedChannel->isPublic() + && !clickedChannel->amIn() + && (!currentPeer->isChannel() + || currentPeer->asChannel()->linkedChat() + != clickedChannel)) { + Ui::ShowMultilineToast({ + .text = { + .text = peer->isMegagroup() + ? tr::lng_group_not_accessible(tr::now) + : tr::lng_channel_not_accessible(tr::now) + }, + }); + } else { + showPeerHistory(peer->id, SectionShow(), msgId); + } + } else { + showPeerInfo(peer, SectionShow()); + } +} + void SessionController::startOrJoinGroupCall( not_null peer, QString joinHash, diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index c524f1bc2..648ee3be8 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -322,6 +322,8 @@ public: void resizeForThirdSection(); void closeThirdSection(); + void showPeer(not_null peer, MsgId msgId = ShowAtUnreadMsgId); + enum class GroupCallJoinConfirm { None, IfNowInAnother,