mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-06 03:42:56 +00:00
Add This Community tab to message search scopes
This commit is contained in:
@@ -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.";
|
||||
|
||||
@@ -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<Ui::PopupMenu*> 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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Data::ReactionId> _searchQueryTags;
|
||||
ChatSearchTab _searchQueryTab = {};
|
||||
ChannelData *_searchQueryCommunity = nullptr;
|
||||
ChatTypeFilter _searchQueryFilter = {};
|
||||
|
||||
Ui::Controls::SwipeBackResult _swipeBackData;
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ enum class ChatSearchTab : uchar {
|
||||
ThisPeer,
|
||||
PublicPosts,
|
||||
Archive,
|
||||
ThisCommunity,
|
||||
};
|
||||
|
||||
enum class ChatSearchPeerTabType : uchar {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user