From ead427793b18aaed597943fcd8a940c6c3a730a0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 14 Oct 2022 18:34:04 +0400 Subject: [PATCH] Handle forum / topic links. --- Telegram/SourceFiles/apiwrap.cpp | 5 ++++- Telegram/SourceFiles/core/application.cpp | 4 ++++ Telegram/SourceFiles/core/local_url_handlers.cpp | 8 ++++++-- .../history/view/history_view_list_widget.cpp | 9 ++++++--- .../history/view/history_view_replies_section.cpp | 4 +++- .../SourceFiles/window/window_session_controller.cpp | 2 ++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 8c58f4e83e..214443d674 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -659,6 +659,7 @@ QString ApiWrap::exportDirectMessageLink( auto linkItemId = item->id; auto linkCommentId = MsgId(); auto linkThreadId = MsgId(); + auto linkThreadIsTopic = false; if (inRepliesContext) { if (const auto rootId = item->replyToTop()) { const auto root = item->history()->owner().message( @@ -680,6 +681,7 @@ QString ApiWrap::exportDirectMessageLink( } else { // Reply in a thread, maybe comment in a private channel. linkThreadId = rootId; + linkThreadIsTopic = (item->topicRootId() == rootId); } } } @@ -692,7 +694,8 @@ QString ApiWrap::exportDirectMessageLink( + (linkCommentId ? "?comment=" + QString::number(linkCommentId.bare) : linkThreadId - ? "?thread=" + QString::number(linkThreadId.bare) + ? ((linkThreadIsTopic ? "?topic=" : "?thread=") + + QString::number(linkThreadId.bare)) : ""); if (linkChannel->hasUsername() && !linkChannel->isMegagroup() diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 22c863affa..4d9d292163 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_session.h" #include "data/data_user.h" +#include "data/data_channel.h" #include "data/data_download_manager.h" #include "base/timer.h" #include "base/event_filter.h" @@ -1229,6 +1230,9 @@ void Application::closeChatFromWindows(not_null peer) { PeerId(0), Window::SectionShow::Way::ClearStack); } + if (primary->openedForum().current() == peer) { + primary->closeForum(); + } } } diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 14a6dc55c0..c7d577707e 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -362,8 +362,10 @@ bool ResolveUsernameOrPhone( } const auto commentParam = params.value(qsl("comment")); const auto commentId = commentParam.toInt(); + const auto topicParam = params.value(qsl("topic")); + const auto topicId = topicParam.toInt(); const auto threadParam = params.value(qsl("thread")); - const auto threadId = threadParam.toInt(); + const auto threadId = topicId ? topicId : threadParam.toInt(); const auto gameParam = params.value(qsl("game")); if (!gameParam.isEmpty() && validDomain(gameParam)) { startToken = gameParam; @@ -422,8 +424,10 @@ bool ResolvePrivatePost( const auto msgId = params.value(qsl("post")).toInt(); const auto commentParam = params.value(qsl("comment")); const auto commentId = commentParam.toInt(); + const auto topicParam = params.value(qsl("topic")); + const auto topicId = topicParam.toInt(); const auto threadParam = params.value(qsl("thread")); - const auto threadId = threadParam.toInt(); + const auto threadId = topicId ? topicId : threadParam.toInt(); if (!channelId || !IsServerMsgId(msgId)) { return false; } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index cd984f3591..14714e1c50 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -685,9 +685,12 @@ bool ListWidget::showAtPositionNow( && position != Data::UnreadMessagePosition) { highlightMessage(position.fullId); } - done(!position.fullId.peer - || !position.fullId.msg - || viewForItem(position.fullId)); + if (done) { + const auto found = !position.fullId.peer + || !position.fullId.msg + || viewForItem(position.fullId); + done(found); + } return true; } return false; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 72a7df19e4..46a0878754 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1174,7 +1174,9 @@ void RepliesWidget::refreshJoinGroupButton() { } }; const auto channel = _history->peer->asChannel(); - if (channel->amIn() || !channel->joinToWrite() || channel->amCreator()) { + if (channel->amIn() + || !channel->joinToWrite() + || (channel->amCreator() && channel->canWrite())) { set(nullptr); } else { if (!_joinGroup) { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 287d8aa171..94a1aed672 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -343,6 +343,8 @@ void SessionNavigation::showPeerByLinkResolved( info.messageId, commentId->id, params); + } else if (peer->isForum()) { + parentController()->openForum(peer->asChannel(), params); } else if (bot && (info.resolveType == ResolveType::AddToGroup || info.resolveType == ResolveType::AddToChannel