Fix unread counters with monoforums.

Fixes #29544.
This commit is contained in:
John Preston 2025-07-11 19:19:51 +04:00
parent 4039d7ab71
commit bf51e911b8
5 changed files with 27 additions and 19 deletions

View file

@ -96,17 +96,6 @@ Thread *SavedMessages::activeSubsectionThread() const {
return _activeSubsectionSublist; 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() { SavedMessages::~SavedMessages() {
clear(); clear();
} }

View file

@ -84,8 +84,6 @@ public:
void saveActiveSubsectionThread(not_null<Thread*> thread); void saveActiveSubsectionThread(not_null<Thread*> thread);
Thread *activeSubsectionThread() const; Thread *activeSubsectionThread() const;
[[nodiscard]] Dialogs::UnreadState unreadStateWithParentMuted() const;
[[nodiscard]] rpl::lifetime &lifetime(); [[nodiscard]] rpl::lifetime &lifetime();
private: private:

View file

@ -120,6 +120,10 @@ void MainList::unreadStateChanged(
const auto notify = !useClouded || wasState.known; const auto notify = !useClouded || wasState.known;
const auto notifier = unreadStateChangeNotifier(notify); const auto notifier = unreadStateChangeNotifier(notify);
_unreadState += nowState - wasState; _unreadState += nowState - wasState;
if (_unreadState.chatsMuted > _unreadState.chats
|| _unreadState.messagesMuted > _unreadState.messages) {
[[maybe_unused]] int a = 0;
}
if (updateCloudUnread) { if (updateCloudUnread) {
Assert(nowState.known); Assert(nowState.known);
_cloudUnreadState += nowState - wasState; _cloudUnreadState += nowState - wasState;
@ -145,6 +149,10 @@ void MainList::unreadEntryChanged(
} else { } else {
_unreadState -= state; _unreadState -= state;
} }
if (_unreadState.chatsMuted > _unreadState.chats
|| _unreadState.messagesMuted > _unreadState.messages) {
[[maybe_unused]] int a = 0;
}
if (updateCloudUnread) { if (updateCloudUnread) {
if (added) { if (added) {
_cloudUnreadState += state; _cloudUnreadState += state;

View file

@ -2370,7 +2370,7 @@ Dialogs::UnreadState History::chatListUnreadState() const {
return AdjustedForumUnreadState(forum->topicsList()->unreadState()); return AdjustedForumUnreadState(forum->topicsList()->unreadState());
} else if (const auto monoforum = peer->monoforum()) { } else if (const auto monoforum = peer->monoforum()) {
return AdjustedForumUnreadState( return AdjustedForumUnreadState(
monoforum->unreadStateWithParentMuted()); withMyMuted(monoforum->chatsList()->unreadState()));;
} }
return computeUnreadState(); return computeUnreadState();
} }
@ -2385,7 +2385,7 @@ Dialogs::BadgesState History::chatListBadgesState() const {
} else if (const auto monoforum = peer->monoforum()) { } else if (const auto monoforum = peer->monoforum()) {
return adjustBadgesStateByFolder( return adjustBadgesStateByFolder(
Dialogs::BadgesForUnread( Dialogs::BadgesForUnread(
monoforum->unreadStateWithParentMuted(), withMyMuted(monoforum->chatsList()->unreadState()),
Dialogs::CountInBadge::Chats, Dialogs::CountInBadge::Chats,
Dialogs::IncludeInBadge::All)); Dialogs::IncludeInBadge::All));
} }
@ -2426,6 +2426,16 @@ Dialogs::UnreadState History::computeUnreadState() const {
return result; 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() { void History::allowChatListMessageResolve() {
if (_flags & Flag::ResolveChatListMessage) { if (_flags & Flag::ResolveChatListMessage) {
return; return;
@ -3354,7 +3364,8 @@ bool History::isForum() const {
void History::monoforumChanged(Data::SavedMessages *old) { void History::monoforumChanged(Data::SavedMessages *old) {
if (inChatList()) { if (inChatList()) {
notifyUnreadStateChange(old notifyUnreadStateChange(old
? AdjustedForumUnreadState(old->chatsList()->unreadState()) ? AdjustedForumUnreadState(
withMyMuted(old->chatsList()->unreadState()))
: computeUnreadState()); : computeUnreadState());
} }
@ -3364,9 +3375,9 @@ void History::monoforumChanged(Data::SavedMessages *old) {
monoforum->chatsList()->unreadStateChanges( monoforum->chatsList()->unreadStateChanges(
) | rpl::filter([=] { ) | rpl::filter([=] {
return (_flags & Flag::IsMonoforumAdmin) && inChatList(); return (_flags & Flag::IsMonoforumAdmin) && inChatList();
}) | rpl::map( }) | rpl::map([=](const Dialogs::UnreadState &was) {
AdjustedForumUnreadState return AdjustedForumUnreadState(withMyMuted(was));
) | rpl::start_with_next([=](const Dialogs::UnreadState &old) { }) | rpl::start_with_next([=](const Dialogs::UnreadState &old) {
notifyUnreadStateChange(old); notifyUnreadStateChange(old);
}, monoforum->lifetime()); }, monoforum->lifetime());

View file

@ -602,6 +602,8 @@ private:
[[nodiscard]] Dialogs::BadgesState adjustBadgesStateByFolder( [[nodiscard]] Dialogs::BadgesState adjustBadgesStateByFolder(
Dialogs::BadgesState state) const; Dialogs::BadgesState state) const;
[[nodiscard]] Dialogs::UnreadState computeUnreadState() const; [[nodiscard]] Dialogs::UnreadState computeUnreadState() const;
[[nodiscard]] Dialogs::UnreadState withMyMuted(
Dialogs::UnreadState state) const;
void setFolderPointer(Data::Folder *folder); void setFolderPointer(Data::Folder *folder);
void hasUnreadMentionChanged(bool has) override; void hasUnreadMentionChanged(bool has) override;