From 46886b4dcc4ef01d10ae852a928342cf88280bf0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 22 Aug 2025 17:08:46 +0400 Subject: [PATCH] Support channel direct messages links. --- .../SourceFiles/core/local_url_handlers.cpp | 4 +++- .../window/window_session_controller.cpp | 19 +++++++++++++++++++ .../window/window_session_controller.h | 4 ++++ .../window_session_controller_link_info.h | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index e386bcc9fe..65d423a245 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -646,7 +646,9 @@ bool ResolveUsernameOrPhone( const auto threadId = topicId ? topicId : threadParam.toInt(); const auto gameParam = params.value(u"game"_q); const auto videot = params.value(u"t"_q); - + if (params.contains(u"direct"_q)) { + resolveType = ResolveType::ChannelDirect; + } if (!gameParam.isEmpty() && validDomain(gameParam)) { startToken = gameParam; resolveType = ResolveType::ShareGame; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index db44cea1ce..4d3bf4b03f 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -431,6 +431,15 @@ void SessionNavigation::showPeerByLink(const PeerByLinkInfo &info) { } } +void SessionNavigation::fullInfoLoadedHook(not_null peer) { + if (!_waitingDirectChannel || _waitingDirectChannel != peer) { + return; + } + const auto monoforum = peer->broadcastMonoforum(); + const auto open = monoforum ? monoforum : peer.get(); + showPeerHistory(open, SectionShow::Way::Forward, ShowAtUnreadMsgId); +} + void SessionNavigation::resolvePhone( const QString &phone, Fn)> done) { @@ -725,6 +734,13 @@ void SessionNavigation::showPeerByLinkResolved( } } else if (resolveType == ResolveType::Boost && peer->isChannel()) { resolveBoostState(peer->asChannel()); + } else if (resolveType == ResolveType::ChannelDirect + && !peer->isFullLoaded()) { + _waitingDirectChannel = peer; + peer->updateFull(); + } else if (const auto monoforum = peer->broadcastMonoforum() + ; monoforum && resolveType == ResolveType::ChannelDirect) { + showPeerHistory(peer, params, ShowAtUnreadMsgId); } else { // Show specific posts only in channels / supergroups. const auto msgId = peer->isChannel() @@ -1554,6 +1570,9 @@ SessionController::SessionController( } } } + if (update.flags & Data::PeerUpdate::Flag::FullInfo) { + fullInfoLoadedHook(update.peer); + } return (update.flags & Data::PeerUpdate::Flag::FullInfo) && (update.peer == _showEditPeer); }) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 80a2fbaea2..b20da580bc 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -316,6 +316,9 @@ public: [[nodiscard]] virtual std::shared_ptr uiShow(); +protected: + void fullInfoLoadedHook(not_null peer); + private: void resolvePhone( const QString &phone, @@ -362,6 +365,7 @@ private: MTP::Sender _api; mtpRequestId _resolveRequestId = 0; + PeerData *_waitingDirectChannel = nullptr; History *_showingRepliesHistory = nullptr; MsgId _showingRepliesRootId = 0; diff --git a/Telegram/SourceFiles/window/window_session_controller_link_info.h b/Telegram/SourceFiles/window/window_session_controller_link_info.h index 7608a07b9c..71590b4221 100644 --- a/Telegram/SourceFiles/window/window_session_controller_link_info.h +++ b/Telegram/SourceFiles/window/window_session_controller_link_info.h @@ -23,6 +23,7 @@ enum class ResolveType { ShareGame, Mention, Boost, + ChannelDirect, Profile, };