Skip to content

Commit

Permalink
Fixed display tags with NoRead flag while history has fake unread state.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Nov 21, 2024
1 parent af7f192 commit 4b448a8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Telegram/SourceFiles/data/data_chat_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ const base::flat_set<not_null<History*>> &ChatFilter::never() const {
return _never;
}

bool ChatFilter::contains(not_null<History*> history) const {
bool ChatFilter::contains(
not_null<History*> history,
bool ignoreFakeUnread) const {
const auto flag = [&] {
const auto peer = history->peer;
if (const auto user = peer->asUser()) {
Expand Down Expand Up @@ -320,7 +322,7 @@ bool ChatFilter::contains(not_null<History*> history) const {
&& (!(_flags & Flag::NoRead)
|| state.unread
|| state.mention
|| history->fakeUnreadWhileOpened())
|| (!ignoreFakeUnread && history->fakeUnreadWhileOpened()))
&& (!(_flags & Flag::NoArchived)
|| (history->folderKnown() && !history->folder())))
|| _always.contains(history);
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/data/data_chat_filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class ChatFilter final {
[[nodiscard]] const std::vector<not_null<History*>> &pinned() const;
[[nodiscard]] const base::flat_set<not_null<History*>> &never() const;

[[nodiscard]] bool contains(not_null<History*> history) const;
[[nodiscard]] bool contains(
not_null<History*> history,
bool ignoreFakeUnread = false) const;

private:
FilterId _id = 0;
Expand Down
24 changes: 24 additions & 0 deletions Telegram/SourceFiles/dialogs/dialogs_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit 4b448a8

Please sign in to comment.