Add "View in Thread" context menu button.

This commit is contained in:
John Preston 2022-10-25 12:12:25 +04:00
parent 48fb410bc7
commit 6e491913d6
2 changed files with 37 additions and 8 deletions

View file

@ -2097,16 +2097,30 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
const auto repliesCount = item->repliesCount(); const auto repliesCount = item->repliesCount();
const auto withReplies = (repliesCount > 0); const auto withReplies = (repliesCount > 0);
if (withReplies && item->history()->peer->isMegagroup()) { const auto topicRootId = item->history()->peer->isForum()
const auto rootId = repliesCount ? item->id : item->replyToTop(); ? item->topicRootId()
const auto phrase = (repliesCount > 0) : 0;
if (topicRootId
|| (withReplies && item->history()->peer->isMegagroup())) {
const auto highlightId = topicRootId ? item->id : 0;
const auto rootId = topicRootId
? topicRootId
: repliesCount
? item->id
: item->replyToTop();
const auto phrase = topicRootId
? u"View in Thread"_q // #TODO lang-forum
: (repliesCount > 0)
? tr::lng_replies_view( ? tr::lng_replies_view(
tr::now, tr::now,
lt_count, lt_count,
repliesCount) repliesCount)
: tr::lng_replies_view_thread(tr::now); : tr::lng_replies_view_thread(tr::now);
_menu->addAction(phrase, [=] { _menu->addAction(phrase, [=] {
controller->showRepliesForMessage(_history, rootId); controller->showRepliesForMessage(
_history,
rootId,
highlightId);
}, &st::menuIconViewReplies); }, &st::menuIconViewReplies);
} }
const auto t = base::unixtime::now(); const auto t = base::unixtime::now();

View file

@ -616,13 +616,25 @@ bool AddViewRepliesAction(
|| (context != Context::History && context != Context::Pinned)) { || (context != Context::History && context != Context::Pinned)) {
return false; return false;
} }
const auto topicRootId = item->history()->peer->isForum()
? item->topicRootId()
: 0;
const auto repliesCount = item->repliesCount(); const auto repliesCount = item->repliesCount();
const auto withReplies = (repliesCount > 0); const auto withReplies = (repliesCount > 0);
if (!withReplies || !item->history()->peer->isMegagroup()) { if (!withReplies || !item->history()->peer->isMegagroup()) {
return false; if (!topicRootId) {
return false;
}
} }
const auto rootId = repliesCount ? item->id : item->replyToTop(); const auto rootId = topicRootId
const auto phrase = (repliesCount > 0) ? topicRootId
: repliesCount
? item->id
: item->replyToTop();
const auto highlightId = topicRootId ? item->id : 0;
const auto phrase = topicRootId
? u"View in Thread"_q // #TODO lang-forum
: (repliesCount > 0)
? tr::lng_replies_view( ? tr::lng_replies_view(
tr::now, tr::now,
lt_count, lt_count,
@ -631,7 +643,10 @@ bool AddViewRepliesAction(
const auto controller = list->controller(); const auto controller = list->controller();
const auto history = item->history(); const auto history = item->history();
menu->addAction(phrase, crl::guard(controller, [=] { menu->addAction(phrase, crl::guard(controller, [=] {
controller->showRepliesForMessage(history, rootId); controller->showRepliesForMessage(
history,
rootId,
highlightId);
}), &st::menuIconViewReplies); }), &st::menuIconViewReplies);
return true; return true;
} }