From 527cb34f0f42a460764280bebfbeb2bb190fbb97 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 9 Jul 2026 18:25:48 +0400 Subject: [PATCH] Add This Community tab to message search scopes --- Telegram/Resources/langs/lang.strings | 1 + .../dialogs/dialogs_inner_widget.cpp | 30 +++++++++++++++---- .../dialogs/dialogs_inner_widget.h | 1 + Telegram/SourceFiles/dialogs/dialogs_key.cpp | 7 ++++- .../SourceFiles/dialogs/dialogs_widget.cpp | 26 ++++++++++++++-- Telegram/SourceFiles/dialogs/dialogs_widget.h | 3 ++ .../SourceFiles/dialogs/ui/chat_search_in.cpp | 2 ++ .../SourceFiles/dialogs/ui/chat_search_in.h | 1 + .../window/window_session_controller.cpp | 3 +- 9 files changed, 63 insertions(+), 11 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 61da095545..786f66070b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -8297,6 +8297,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_search_tab_this_group" = "This Group"; "lng_search_tab_public_posts" = "Public Posts"; "lng_search_tab_archive" = "Archive"; +"lng_search_tab_this_community" = "This Community"; "lng_search_tab_no_results" = "No Results"; "lng_search_tab_no_results_text" = "There were no results for \"{query}\"."; "lng_search_tab_no_results_retry" = "Try another hashtag."; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index a4e8e1c738..789f2fa409 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -176,6 +176,7 @@ constexpr auto kPreviewPostsLimit = 3; const auto fromPeer = (state.tab == ChatSearchTab::MyMessages || state.tab == ChatSearchTab::PublicPosts || state.tab == ChatSearchTab::Archive + || state.tab == ChatSearchTab::ThisCommunity || !state.inChat.peer() || !(state.inChat.peer()->isChat() || state.inChat.peer()->isMegagroup())) @@ -3791,7 +3792,8 @@ void InnerWidget::clearSelection() { void InnerWidget::fillSupportSearchMenu(not_null menu) { const auto globalSearch = (_searchState.tab == ChatSearchTab::MyMessages) || (_searchState.tab == ChatSearchTab::PublicPosts) - || (_searchState.tab == ChatSearchTab::Archive); + || (_searchState.tab == ChatSearchTab::Archive) + || (_searchState.tab == ChatSearchTab::ThisCommunity); if (!globalSearch && _searchState.inChat) { return; } @@ -4109,7 +4111,8 @@ void InnerWidget::applySearchState(SearchState state) { const auto ignoreInChat = (state.tab == ChatSearchTab::MyMessages) || (state.tab == ChatSearchTab::PublicPosts) - || (state.tab == ChatSearchTab::Archive); + || (state.tab == ChatSearchTab::Archive) + || (state.tab == ChatSearchTab::ThisCommunity); const auto sublist = ignoreInChat ? nullptr : state.inChat.sublist(); const auto peer = ignoreInChat ? nullptr : state.inChat.peer(); if (const auto migrateFrom = peer ? peer->migrateFrom() : nullptr) { @@ -4606,7 +4609,8 @@ void InnerWidget::searchReceived( const auto globalSearch = (_searchState.tab == ChatSearchTab::MyMessages) || (_searchState.tab == ChatSearchTab::PublicPosts) - || (_searchState.tab == ChatSearchTab::Archive); + || (_searchState.tab == ChatSearchTab::Archive) + || (_searchState.tab == ChatSearchTab::ThisCommunity); const auto key = globalSearch ? Key() : (!_openedForum || _searchState.inChat.topic()) @@ -5039,10 +5043,17 @@ bool InnerWidget::archiveSearchActive() const { || !QStringView(_searchState.query).trimmed().isEmpty()); } +bool InnerWidget::communitySearchActive() const { + return _openedCommunity + && ((_searchState.tab == ChatSearchTab::ThisCommunity) + || !QStringView(_searchState.query).trimmed().isEmpty()); +} + void InnerWidget::updateSearchIn() { if (!_searchState.inChat && _searchHashOrCashtag == HashOrCashtag::None - && !archiveSearchActive()) { + && !archiveSearchActive() + && !communitySearchActive()) { _searchIn = nullptr; return; } else if (!_searchIn) { @@ -5104,6 +5115,9 @@ void InnerWidget::updateSearchIn() { const auto archiveIcon = (_openedFolder && !_searchState.inChat) ? Ui::MakeIconThumbnail(st::menuIconArchive) : nullptr; + const auto communityIcon = (_openedCommunity && !_searchState.inChat) + ? Ui::MakeUserpicThumbnail(_openedCommunity->channel()) + : nullptr; const auto publicIcon = (_searchHashOrCashtag != HashOrCashtag::None) ? Ui::MakeIconThumbnail(st::menuIconChannel) : nullptr; @@ -5121,6 +5135,7 @@ void InnerWidget::updateSearchIn() { _searchIn->apply({ { ChatSearchTab::ThisTopic, topicIcon }, { ChatSearchTab::ThisPeer, peerIcon }, + { ChatSearchTab::ThisCommunity, communityIcon }, { ChatSearchTab::Archive, archiveIcon }, { ChatSearchTab::MyMessages, myIcon }, { ChatSearchTab::PublicPosts, publicIcon }, @@ -5152,8 +5167,11 @@ bool InnerWidget::computeSearchWithPostsPreview() const { void InnerWidget::clearFilter() { if (_state == WidgetState::Filtered || _searchState.inChat - || archiveSearchActive()) { - if (_searchState.inChat || archiveSearchActive()) { + || archiveSearchActive() + || communitySearchActive()) { + if (_searchState.inChat + || archiveSearchActive() + || communitySearchActive()) { setState(WidgetState::Filtered); } else { setState(WidgetState::Default); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index cdf8c87511..8ab4f85e79 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -534,6 +534,7 @@ private: // const style::icon *icon, // const Ui::Text::String &text) const; [[nodiscard]] bool archiveSearchActive() const; + [[nodiscard]] bool communitySearchActive() const; void updateSearchIn(); void repaintSearchResult(int index); void repaintPreviewResult(int index); diff --git a/Telegram/SourceFiles/dialogs/dialogs_key.cpp b/Telegram/SourceFiles/dialogs/dialogs_key.cpp index 1e5633fc01..f5c2e1b901 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_key.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_key.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "dialogs/dialogs_key.h" +#include "data/data_channel.h" #include "data/data_folder.h" #include "data/data_forum_topic.h" #include "data/data_saved_sublist.h" @@ -92,9 +93,13 @@ PeerData *Key::peer() const { } ChatSearchTab SearchState::defaultTabForMe() const { + const auto history = inChat.history(); + const auto channel = history ? history->peer->asChannel() : nullptr; return inChat.topic() ? ChatSearchTab::ThisTopic - : (inChat.history() || inChat.sublist()) + : (channel && channel->isCommunity()) + ? ChatSearchTab::ThisCommunity + : (history || inChat.sublist()) ? ChatSearchTab::ThisPeer : inChat.folder() ? ChatSearchTab::Archive diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index d4c1028d1e..c797633161 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -2978,6 +2978,9 @@ bool Widget::search(bool inCache, SearchRequestDelay delay) { _searchQueryFrom = fromPeer; _searchQueryTags = inTags; _searchQueryTab = tab; + _searchQueryCommunity = _openedCommunity + ? _openedCommunity->channel().get() + : nullptr; _searchQueryFilter = filter; process->nextRate = 0; process->full = false; @@ -2996,6 +2999,9 @@ bool Widget::search(bool inCache, SearchRequestDelay delay) { _searchQueryFrom = fromPeer; _searchQueryTags = inTags; _searchQueryTab = tab; + _searchQueryCommunity = _openedCommunity + ? _openedCommunity->channel().get() + : nullptr; _searchQueryFilter = filter; process->nextRate = 0; process->full = false; @@ -3358,7 +3364,10 @@ void Widget::requestMessages(bool fromStart) { .start = fromStart, }; using Flag = MTPmessages_SearchGlobal::Flag; - const auto flags = Flag::f_folder_id + const auto community = (_searchQueryTab == ChatSearchTab::ThisCommunity) + ? _searchQueryCommunity + : nullptr; + const auto flags = (community ? Flag::f_community : Flag::f_folder_id) | (_searchQueryFilter == ChatTypeFilter::Private ? Flag::f_users_only : _searchQueryFilter == ChatTypeFilter::Groups @@ -3373,7 +3382,7 @@ void Widget::requestMessages(bool fromStart) { MTPmessages_SearchGlobal( MTP_flags(flags), MTP_int(folderId), - MTPInputChannel(), + (community ? community->inputChannel() : MTPInputChannel()), MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), // min_date @@ -3915,16 +3924,23 @@ bool Widget::applySearchState(SearchState state) { ? ChatSearchTab::ThisPeer : _openedFolder ? ChatSearchTab::Archive + : _openedCommunity + ? ChatSearchTab::ThisCommunity : ChatSearchTab::MyMessages; } else if (!state.inChat && _searchHashOrCashtag == HashOrCashtag::None) { const auto archive = _openedFolder && ((folder == _openedFolder) || (state.tab == ChatSearchTab::Archive)); + const auto communityScope = _openedCommunity + && (community + || (state.tab == ChatSearchTab::ThisCommunity)); state.tab = (forum || _openedForum) ? ChatSearchTab::ThisPeer : archive ? ChatSearchTab::Archive + : communityScope + ? ChatSearchTab::ThisCommunity : ChatSearchTab::MyMessages; } if (!state.tags.empty()) { @@ -3975,6 +3991,8 @@ bool Widget::applySearchState(SearchState state) { && !_openedForum) || (state.tab == ChatSearchTab::Archive && (!_openedFolder || state.inChat)) + || (state.tab == ChatSearchTab::ThisCommunity + && (!_openedCommunity || state.inChat)) || (state.tab == ChatSearchTab::PublicPosts && _searchHashOrCashtag == HashOrCashtag::None)) { state.tab = state.inChat.topic() @@ -4674,7 +4692,8 @@ void Widget::cancelSearchRequest() { PeerData *Widget::searchInPeer() const { return (_searchState.tab == ChatSearchTab::MyMessages || _searchState.tab == ChatSearchTab::PublicPosts - || _searchState.tab == ChatSearchTab::Archive) + || _searchState.tab == ChatSearchTab::Archive + || _searchState.tab == ChatSearchTab::ThisCommunity) ? nullptr : _openedForum ? _openedForum->peer().get() @@ -4787,6 +4806,7 @@ bool Widget::cancelSearch(CancelSearchOptions options) { clearingInChat = true; } if ((updatedState.tab == ChatSearchTab::Archive + || updatedState.tab == ChatSearchTab::ThisCommunity || updatedState.tab == ChatSearchTab::PublicPosts) && (forceFullCancel || !clearingQuery)) { updatedState.tab = ChatSearchTab::MyMessages; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index a4330a2cb3..9d4c6c6721 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "api/api_single_message_search.h" +class ChannelData; + namespace MTP { class Error; } // namespace MTP @@ -417,6 +419,7 @@ private: PeerData *_searchQueryFrom = nullptr; std::vector _searchQueryTags; ChatSearchTab _searchQueryTab = {}; + ChannelData *_searchQueryCommunity = nullptr; ChatTypeFilter _searchQueryFilter = {}; Ui::Controls::SwipeBackResult _swipeBackData; diff --git a/Telegram/SourceFiles/dialogs/ui/chat_search_in.cpp b/Telegram/SourceFiles/dialogs/ui/chat_search_in.cpp index fcc34cc2f3..9707706284 100644 --- a/Telegram/SourceFiles/dialogs/ui/chat_search_in.cpp +++ b/Telegram/SourceFiles/dialogs/ui/chat_search_in.cpp @@ -81,6 +81,8 @@ private: return tr::lng_search_tab_public_posts(tr::now); case ChatSearchTab::Archive: return tr::lng_search_tab_archive(tr::now); + case ChatSearchTab::ThisCommunity: + return tr::lng_search_tab_this_community(tr::now); } Unexpected("Tab in Dialogs::TabLabel."); } diff --git a/Telegram/SourceFiles/dialogs/ui/chat_search_in.h b/Telegram/SourceFiles/dialogs/ui/chat_search_in.h index 198f2b6f20..0a258597c5 100644 --- a/Telegram/SourceFiles/dialogs/ui/chat_search_in.h +++ b/Telegram/SourceFiles/dialogs/ui/chat_search_in.h @@ -25,6 +25,7 @@ enum class ChatSearchTab : uchar { ThisPeer, PublicPosts, Archive, + ThisCommunity, }; enum class ChatSearchPeerTabType : uchar { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 2c55130007..4f6858cd8d 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -2041,7 +2041,8 @@ bool SessionController::uniqueChatsInSearchResults( const Dialogs::SearchState &state) const { const auto global = (state.tab == Dialogs::ChatSearchTab::MyMessages) || (state.tab == Dialogs::ChatSearchTab::PublicPosts) - || (state.tab == Dialogs::ChatSearchTab::Archive); + || (state.tab == Dialogs::ChatSearchTab::Archive) + || (state.tab == Dialogs::ChatSearchTab::ThisCommunity); return session().supportMode() && !session().settings().supportAllSearchResults() && (global || !state.inChat);