From d5dbbd566f342e27d42fecef892364fc35a814d3 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 21 Nov 2024 04:46:13 +0300 Subject: [PATCH] Fixed display tags with NoRead flag while history has fake unread state. --- .../SourceFiles/data/data_chat_filters.cpp | 6 +++-- Telegram/SourceFiles/data/data_chat_filters.h | 4 +++- .../SourceFiles/dialogs/dialogs_entry.cpp | 24 +++++++++++++++++++ .../dialogs/dialogs_inner_widget.cpp | 6 +++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index acc36d10e..e8c5db062 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -283,7 +283,9 @@ const base::flat_set> &ChatFilter::never() const { return _never; } -bool ChatFilter::contains(not_null history) const { +bool ChatFilter::contains( + not_null history, + bool ignoreFakeUnread) const { const auto flag = [&] { const auto peer = history->peer; if (const auto user = peer->asUser()) { @@ -320,7 +322,7 @@ bool ChatFilter::contains(not_null history) const { && (!(_flags & Flag::NoRead) || state.unread || state.mention - || history->fakeUnreadWhileOpened()) + || (!ignoreFakeUnread && history->fakeUnreadWhileOpened())) && (!(_flags & Flag::NoArchived) || (history->folderKnown() && !history->folder()))) || _always.contains(history); diff --git a/Telegram/SourceFiles/data/data_chat_filters.h b/Telegram/SourceFiles/data/data_chat_filters.h index b18cda973..5f876de24 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.h +++ b/Telegram/SourceFiles/data/data_chat_filters.h @@ -81,7 +81,9 @@ public: [[nodiscard]] const std::vector> &pinned() const; [[nodiscard]] const base::flat_set> &never() const; - [[nodiscard]] bool contains(not_null history) const; + [[nodiscard]] bool contains( + not_null history, + bool ignoreFakeUnread = false) const; private: FilterId _id = 0; diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index 81b42c14d..501883a41 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -254,7 +254,31 @@ void Entry::notifyUnreadStateChange(const UnreadState &wasState) { return state.messages || state.marks || state.mentions; }; if (isForFilters(wasState) != isForFilters(nowState)) { + const auto wasTags = _tagColors.size(); owner().chatsFilters().refreshHistory(history); + + // Hack for History::fakeUnreadWhileOpened(). + if (!isForFilters(nowState) + && (wasTags > 0) + && (wasTags == _tagColors.size())) { + auto updateRequested = false; + for (const auto &filter : filters.list()) { + if (!(filter.flags() & Data::ChatFilter::Flag::NoRead) + || !_chatListLinks.contains(filter.id()) + || filter.contains(history, true)) { + continue; + } + const auto wasTagsCount = _tagColors.size(); + setColorIndexForFilterId(filter.id(), std::nullopt); + updateRequested |= (wasTagsCount != _tagColors.size()); + } + if (updateRequested) { + updateChatListEntryHeight(); + session().changes().peerUpdated( + history->peer, + Data::PeerUpdate::Flag::Name); + } + } } } updateChatListEntryPostponed(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index b9735045a..f3490d7f9 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -803,6 +803,12 @@ void InnerWidget::paintEvent(QPaintEvent *e) { || (filter.id() == context.filter)) { continue; } + if (active + && (filter.flags() & Data::ChatFilter::Flag::NoRead) + && !filter.contains(key.history(), true)) { + // Hack for History::fakeUnreadWhileOpened(). + continue; + } if (const auto tag = cacheChatsFilterTag(filter.id(), 0, a)) { if (more) { more++;