From bf51e911b8c1aa42aee0c93939a928fb9bf91f0d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Jul 2025 19:19:51 +0400 Subject: [PATCH] Fix unread counters with monoforums. Fixes #29544. --- .../SourceFiles/data/data_saved_messages.cpp | 11 --------- .../SourceFiles/data/data_saved_messages.h | 2 -- .../SourceFiles/dialogs/dialogs_main_list.cpp | 8 +++++++ Telegram/SourceFiles/history/history.cpp | 23 ++++++++++++++----- Telegram/SourceFiles/history/history.h | 2 ++ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/data/data_saved_messages.cpp b/Telegram/SourceFiles/data/data_saved_messages.cpp index 1cae8972db..12f3e870b9 100644 --- a/Telegram/SourceFiles/data/data_saved_messages.cpp +++ b/Telegram/SourceFiles/data/data_saved_messages.cpp @@ -96,17 +96,6 @@ Thread *SavedMessages::activeSubsectionThread() const { return _activeSubsectionSublist; } -Dialogs::UnreadState SavedMessages::unreadStateWithParentMuted() const { - auto result = _chatsList.unreadState(); - if (_owningHistory->muted()) { - result.chatsMuted = result.chats; - result.marksMuted = result.marks; - result.messagesMuted = result.messages; - result.reactionsMuted = result.reactions; - } - return result; -} - SavedMessages::~SavedMessages() { clear(); } diff --git a/Telegram/SourceFiles/data/data_saved_messages.h b/Telegram/SourceFiles/data/data_saved_messages.h index 65f0345c7b..fe77fbb232 100644 --- a/Telegram/SourceFiles/data/data_saved_messages.h +++ b/Telegram/SourceFiles/data/data_saved_messages.h @@ -84,8 +84,6 @@ public: void saveActiveSubsectionThread(not_null thread); Thread *activeSubsectionThread() const; - [[nodiscard]] Dialogs::UnreadState unreadStateWithParentMuted() const; - [[nodiscard]] rpl::lifetime &lifetime(); private: diff --git a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp index 5e525b5a2c..c38d844ef0 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp @@ -120,6 +120,10 @@ void MainList::unreadStateChanged( const auto notify = !useClouded || wasState.known; const auto notifier = unreadStateChangeNotifier(notify); _unreadState += nowState - wasState; + if (_unreadState.chatsMuted > _unreadState.chats + || _unreadState.messagesMuted > _unreadState.messages) { + [[maybe_unused]] int a = 0; + } if (updateCloudUnread) { Assert(nowState.known); _cloudUnreadState += nowState - wasState; @@ -145,6 +149,10 @@ void MainList::unreadEntryChanged( } else { _unreadState -= state; } + if (_unreadState.chatsMuted > _unreadState.chats + || _unreadState.messagesMuted > _unreadState.messages) { + [[maybe_unused]] int a = 0; + } if (updateCloudUnread) { if (added) { _cloudUnreadState += state; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index eb7d35e209..3c8c10098e 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2370,7 +2370,7 @@ Dialogs::UnreadState History::chatListUnreadState() const { return AdjustedForumUnreadState(forum->topicsList()->unreadState()); } else if (const auto monoforum = peer->monoforum()) { return AdjustedForumUnreadState( - monoforum->unreadStateWithParentMuted()); + withMyMuted(monoforum->chatsList()->unreadState()));; } return computeUnreadState(); } @@ -2385,7 +2385,7 @@ Dialogs::BadgesState History::chatListBadgesState() const { } else if (const auto monoforum = peer->monoforum()) { return adjustBadgesStateByFolder( Dialogs::BadgesForUnread( - monoforum->unreadStateWithParentMuted(), + withMyMuted(monoforum->chatsList()->unreadState()), Dialogs::CountInBadge::Chats, Dialogs::IncludeInBadge::All)); } @@ -2426,6 +2426,16 @@ Dialogs::UnreadState History::computeUnreadState() const { return result; } +Dialogs::UnreadState History::withMyMuted(Dialogs::UnreadState state) const { + if (muted()) { + state.chatsMuted = state.chats; + state.marksMuted = state.marks; + state.messagesMuted = state.messages; + state.reactionsMuted = state.reactions; + } + return state; +} + void History::allowChatListMessageResolve() { if (_flags & Flag::ResolveChatListMessage) { return; @@ -3354,7 +3364,8 @@ bool History::isForum() const { void History::monoforumChanged(Data::SavedMessages *old) { if (inChatList()) { notifyUnreadStateChange(old - ? AdjustedForumUnreadState(old->chatsList()->unreadState()) + ? AdjustedForumUnreadState( + withMyMuted(old->chatsList()->unreadState())) : computeUnreadState()); } @@ -3364,9 +3375,9 @@ void History::monoforumChanged(Data::SavedMessages *old) { monoforum->chatsList()->unreadStateChanges( ) | rpl::filter([=] { return (_flags & Flag::IsMonoforumAdmin) && inChatList(); - }) | rpl::map( - AdjustedForumUnreadState - ) | rpl::start_with_next([=](const Dialogs::UnreadState &old) { + }) | rpl::map([=](const Dialogs::UnreadState &was) { + return AdjustedForumUnreadState(withMyMuted(was)); + }) | rpl::start_with_next([=](const Dialogs::UnreadState &old) { notifyUnreadStateChange(old); }, monoforum->lifetime()); diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index a36d2000c6..7f556bbc71 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -602,6 +602,8 @@ private: [[nodiscard]] Dialogs::BadgesState adjustBadgesStateByFolder( Dialogs::BadgesState state) const; [[nodiscard]] Dialogs::UnreadState computeUnreadState() const; + [[nodiscard]] Dialogs::UnreadState withMyMuted( + Dialogs::UnreadState state) const; void setFolderPointer(Data::Folder *folder); void hasUnreadMentionChanged(bool has) override;