From d5dbde0a246e072ed896ba25e8c73bf7ba02ab0d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 20 Nov 2024 07:49:32 +0300 Subject: [PATCH] Added ability to cache filter colors in dialog entries. --- .../SourceFiles/dialogs/dialogs_entry.cpp | 28 +++++++++++++++++++ Telegram/SourceFiles/dialogs/dialogs_entry.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index 6d227c69a..957e7f4f5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -338,6 +338,17 @@ not_null Entry::addToChatList( if (const auto main = maybeMainChatListLink(filterId)) { return main; } + if (filterId) { + const auto &list = owner().chatsFilters().list(); + const auto it = ranges::find(list, filterId, &Data::ChatFilter::id); + if (it != end(list) && it->colorIndex()) { + _tagColors[filterId] = *(it->colorIndex()); + } else { + if (it != end(list)) { + } + _tagColors.remove(filterId); + } + } return _chatListLinks.emplace( filterId, list->addEntry(this) @@ -350,6 +361,12 @@ void Entry::removeFromChatList( if (isPinnedDialog(filterId)) { owner().setChatPinned(this, filterId, false); } + if (filterId) { + const auto it = _tagColors.find(filterId); + if (it != end(_tagColors)) { + _tagColors.erase(it); + } + } const auto i = _chatListLinks.find(filterId); if (i == end(_chatListLinks)) { @@ -397,4 +414,15 @@ void Entry::updateChatListEntryHeight() { session().changes().entryUpdated(this, Data::EntryUpdate::Flag::Height); } +[[nodiscard]] bool Entry::hasChatsFilterTags(FilterId exclude) const { + if (exclude) { + if (_tagColors.size() == 1) { + if (_tagColors.begin()->first == exclude) { + return false; + } + } + } + return !_tagColors.empty(); +} + } // namespace Dialogs diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.h b/Telegram/SourceFiles/dialogs/dialogs_entry.h index ec61c0378..cb6ac728f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.h +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.h @@ -254,6 +254,7 @@ public: return _chatListPeerBadge; } + [[nodiscard]] bool hasChatsFilterTags(FilterId exclude) const; protected: void notifyUnreadStateChange(const UnreadState &wasState); inline auto unreadStateChangeNotifier(bool required); @@ -284,6 +285,7 @@ private: uint64 _sortKeyInChatList = 0; uint64 _sortKeyByDate = 0; base::flat_map _pinnedIndex; + base::flat_map _tagColors; mutable Ui::PeerBadge _chatListPeerBadge; mutable Ui::Text::String _chatListNameText; mutable int _chatListNameVersion = 0;