From 850746b0bac22d5158f1d9d0f344fafcbc254736 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 27 Oct 2022 11:35:35 +0400 Subject: [PATCH] Improve search-in-topic closing. --- .../SourceFiles/dialogs/dialogs_widget.cpp | 27 ++++++++++--------- .../window/window_session_controller.cpp | 16 ++++++++--- .../window/window_session_controller.h | 4 +++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 0cfe0ff035..81c209862b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -416,9 +416,8 @@ void Widget::chosenRow(const ChosenRow &row) { && row.filteredRow; const auto history = row.key.history(); if (const auto topic = row.key.topic()) { - controller()->showRepliesForMessage( - topic->history(), - topic->rootId(), + controller()->showTopic( + topic, row.message.fullId.msg, Window::SectionShow::Way::ClearStack); } else if (history && history->peer->isForum() && !row.message.fullId) { @@ -2309,32 +2308,34 @@ void Widget::clearSearchField() { } bool Widget::cancelSearch() { - bool clearing = !currentSearchQuery().isEmpty(); + auto clearingQuery = !currentSearchQuery().isEmpty(); + auto clearingInChat = false; cancelSearchRequest(); - if (!clearing && _searchInChat) { + if (!clearingQuery && _searchInChat) { if (controller()->adaptive().isOneColumn()) { if (const auto topic = _searchInChat.topic()) { - //controller()->showTopic(topic); // #TODO forum search + controller()->showTopic(topic); } else if (const auto peer = _searchInChat.peer()) { - controller()->showPeer(peer, ShowAtUnreadMsgId); + controller()->showPeerHistory(peer); } else { Unexpected("Empty key in cancelSearch()."); } } setSearchInChat(Key()); - clearing = true; - } else if (!clearing + clearingInChat = true; + } + if (!clearingQuery && _subsectionTopBar && _subsectionTopBar->toggleSearch(false, anim::type::normal)) { setFocus(); - return true; + clearingInChat = true; } _lastSearchPeer = nullptr; _lastSearchId = _lastSearchMigratedId = 0; _inner->clearFilter(); clearSearchField(); applyFilterUpdate(); - return clearing; + return clearingQuery || clearingInChat; } void Widget::cancelSearchInChat() { @@ -2345,9 +2346,9 @@ void Widget::cancelSearchInChat() { && !controller()->selectingPeer() && currentSearchQuery().trimmed().isEmpty()) { if (const auto topic = _searchInChat.topic()) { - // #TODO forum search + controller()->showTopic(topic); } else if (const auto peer = _searchInChat.peer()) { - Ui::showPeerHistory(peer, ShowAtUnreadMsgId); + controller()->showPeerHistory(peer); } else { Unexpected("Empty key in cancelSearchInPeer()."); } diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 69c4594558..33dd22ec44 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -575,6 +575,17 @@ void SessionNavigation::showPeerInfo( showPeerInfo(_session->data().peer(peerId), params); } +void SessionNavigation::showTopic( + not_null topic, + MsgId commentId, + const SectionShow ¶ms) { + return showRepliesForMessage( + topic->history(), + topic->rootId(), + commentId, + params); +} + void SessionNavigation::showPeerInfo( not_null peer, const SectionShow ¶ms) { @@ -1539,9 +1550,8 @@ void SessionController::showCalendar(Dialogs::Key chat, QDate requestedDate) { SectionShow::Way::Forward, id); } else if (const auto strongTopic = weakTopic.get()) { - strong->showRepliesForMessage( - strongTopic->history(), - strongTopic->rootId(), + strong->showTopic( + strongTopic, id, SectionShow::Way::Forward); strong->hideLayer(anim::type::normal); diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index a2413ba4af..8647efdf23 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -212,6 +212,10 @@ public: MsgId rootId, MsgId commentId = 0, const SectionShow ¶ms = SectionShow()); + void showTopic( + not_null topic, + MsgId commentId = 0, + const SectionShow ¶ms = SectionShow()); void showPeerInfo( PeerId peerId,