Handle forum / topic links.

This commit is contained in:
John Preston 2022-10-14 18:34:04 +04:00
parent 16e189a2ce
commit ead427793b
6 changed files with 25 additions and 7 deletions

View File

@ -659,6 +659,7 @@ QString ApiWrap::exportDirectMessageLink(
auto linkItemId = item->id; auto linkItemId = item->id;
auto linkCommentId = MsgId(); auto linkCommentId = MsgId();
auto linkThreadId = MsgId(); auto linkThreadId = MsgId();
auto linkThreadIsTopic = false;
if (inRepliesContext) { if (inRepliesContext) {
if (const auto rootId = item->replyToTop()) { if (const auto rootId = item->replyToTop()) {
const auto root = item->history()->owner().message( const auto root = item->history()->owner().message(
@ -680,6 +681,7 @@ QString ApiWrap::exportDirectMessageLink(
} else { } else {
// Reply in a thread, maybe comment in a private channel. // Reply in a thread, maybe comment in a private channel.
linkThreadId = rootId; linkThreadId = rootId;
linkThreadIsTopic = (item->topicRootId() == rootId);
} }
} }
} }
@ -692,7 +694,8 @@ QString ApiWrap::exportDirectMessageLink(
+ (linkCommentId + (linkCommentId
? "?comment=" + QString::number(linkCommentId.bare) ? "?comment=" + QString::number(linkCommentId.bare)
: linkThreadId : linkThreadId
? "?thread=" + QString::number(linkThreadId.bare) ? ((linkThreadIsTopic ? "?topic=" : "?thread=")
+ QString::number(linkThreadId.bare))
: ""); : "");
if (linkChannel->hasUsername() if (linkChannel->hasUsername()
&& !linkChannel->isMegagroup() && !linkChannel->isMegagroup()

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_channel.h"
#include "data/data_download_manager.h" #include "data/data_download_manager.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/event_filter.h" #include "base/event_filter.h"
@ -1229,6 +1230,9 @@ void Application::closeChatFromWindows(not_null<PeerData*> peer) {
PeerId(0), PeerId(0),
Window::SectionShow::Way::ClearStack); Window::SectionShow::Way::ClearStack);
} }
if (primary->openedForum().current() == peer) {
primary->closeForum();
}
} }
} }

View File

@ -362,8 +362,10 @@ bool ResolveUsernameOrPhone(
} }
const auto commentParam = params.value(qsl("comment")); const auto commentParam = params.value(qsl("comment"));
const auto commentId = commentParam.toInt(); 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 threadParam = params.value(qsl("thread"));
const auto threadId = threadParam.toInt(); const auto threadId = topicId ? topicId : threadParam.toInt();
const auto gameParam = params.value(qsl("game")); const auto gameParam = params.value(qsl("game"));
if (!gameParam.isEmpty() && validDomain(gameParam)) { if (!gameParam.isEmpty() && validDomain(gameParam)) {
startToken = gameParam; startToken = gameParam;
@ -422,8 +424,10 @@ bool ResolvePrivatePost(
const auto msgId = params.value(qsl("post")).toInt(); const auto msgId = params.value(qsl("post")).toInt();
const auto commentParam = params.value(qsl("comment")); const auto commentParam = params.value(qsl("comment"));
const auto commentId = commentParam.toInt(); 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 threadParam = params.value(qsl("thread"));
const auto threadId = threadParam.toInt(); const auto threadId = topicId ? topicId : threadParam.toInt();
if (!channelId || !IsServerMsgId(msgId)) { if (!channelId || !IsServerMsgId(msgId)) {
return false; return false;
} }

View File

@ -685,9 +685,12 @@ bool ListWidget::showAtPositionNow(
&& position != Data::UnreadMessagePosition) { && position != Data::UnreadMessagePosition) {
highlightMessage(position.fullId); highlightMessage(position.fullId);
} }
done(!position.fullId.peer if (done) {
const auto found = !position.fullId.peer
|| !position.fullId.msg || !position.fullId.msg
|| viewForItem(position.fullId)); || viewForItem(position.fullId);
done(found);
}
return true; return true;
} }
return false; return false;

View File

@ -1174,7 +1174,9 @@ void RepliesWidget::refreshJoinGroupButton() {
} }
}; };
const auto channel = _history->peer->asChannel(); const auto channel = _history->peer->asChannel();
if (channel->amIn() || !channel->joinToWrite() || channel->amCreator()) { if (channel->amIn()
|| !channel->joinToWrite()
|| (channel->amCreator() && channel->canWrite())) {
set(nullptr); set(nullptr);
} else { } else {
if (!_joinGroup) { if (!_joinGroup) {

View File

@ -343,6 +343,8 @@ void SessionNavigation::showPeerByLinkResolved(
info.messageId, info.messageId,
commentId->id, commentId->id,
params); params);
} else if (peer->isForum()) {
parentController()->openForum(peer->asChannel(), params);
} else if (bot } else if (bot
&& (info.resolveType == ResolveType::AddToGroup && (info.resolveType == ResolveType::AddToGroup
|| info.resolveType == ResolveType::AddToChannel || info.resolveType == ResolveType::AddToChannel