Added ability to cache filter colors in dialog entries.

This commit is contained in:
23rd 2024-11-20 07:49:32 +03:00
parent f888008dc1
commit d5dbde0a24
2 changed files with 30 additions and 0 deletions

View file

@ -338,6 +338,17 @@ not_null<Row*> 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

View file

@ -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<FilterId, int> _pinnedIndex;
base::flat_map<FilterId, uint8> _tagColors;
mutable Ui::PeerBadge _chatListPeerBadge;
mutable Ui::Text::String _chatListNameText;
mutable int _chatListNameVersion = 0;