Fixed counting of unread topics from unread state in filters.

This commit is contained in:
23rd 2024-11-27 08:47:39 +03:00
parent 96b5c1d3d3
commit 5934614edb
5 changed files with 40 additions and 8 deletions

View file

@ -902,6 +902,7 @@ Dialogs::UnreadState ForumTopic::unreadStateFor(
result.reactions = unreadReactions().has() ? 1 : 0; result.reactions = unreadReactions().has() ? 1 : 0;
result.messagesMuted = muted ? result.messages : 0; result.messagesMuted = muted ? result.messages : 0;
result.chatsMuted = muted ? result.chats : 0; result.chatsMuted = muted ? result.chats : 0;
result.chatsTopicMuted = muted ? result.chats : 0;
result.reactionsMuted = muted ? result.reactions : 0; result.reactionsMuted = muted ? result.reactions : 0;
result.known = known; result.known = known;
return result; return result;

View file

@ -75,10 +75,13 @@ struct UnreadState {
int chats = 0; int chats = 0;
int chatsMuted = 0; int chatsMuted = 0;
int chatsTopic = 0; int chatsTopic = 0;
int chatsTopicMuted = 0;
int marks = 0; int marks = 0;
int marksMuted = 0; int marksMuted = 0;
int reactions = 0; int reactions = 0;
int reactionsMuted = 0; int reactionsMuted = 0;
int forums = 0;
int forumsMuted = 0;
int mentions = 0; int mentions = 0;
bool known = false; bool known = false;
@ -88,10 +91,13 @@ struct UnreadState {
chats += other.chats; chats += other.chats;
chatsMuted += other.chatsMuted; chatsMuted += other.chatsMuted;
chatsTopic += other.chatsTopic; chatsTopic += other.chatsTopic;
chatsTopicMuted += other.chatsTopicMuted;
marks += other.marks; marks += other.marks;
marksMuted += other.marksMuted; marksMuted += other.marksMuted;
reactions += other.reactions; reactions += other.reactions;
reactionsMuted += other.reactionsMuted; reactionsMuted += other.reactionsMuted;
forums += other.forums;
forumsMuted += other.forumsMuted;
mentions += other.mentions; mentions += other.mentions;
return *this; return *this;
} }
@ -101,10 +107,13 @@ struct UnreadState {
chats -= other.chats; chats -= other.chats;
chatsMuted -= other.chatsMuted; chatsMuted -= other.chatsMuted;
chatsTopic -= other.chatsTopic; chatsTopic -= other.chatsTopic;
chatsTopicMuted -= other.chatsTopicMuted;
marks -= other.marks; marks -= other.marks;
marksMuted -= other.marksMuted; marksMuted -= other.marksMuted;
reactions -= other.reactions; reactions -= other.reactions;
reactionsMuted -= other.reactionsMuted; reactionsMuted -= other.reactionsMuted;
forums -= other.forums;
forumsMuted -= other.forumsMuted;
mentions -= other.mentions; mentions -= other.mentions;
return *this; return *this;
} }

View file

@ -81,6 +81,17 @@ using UpdateFlag = Data::HistoryUpdate::Flag;
return fields; return fields;
} }
[[nodiscard]] Dialogs::UnreadState AdjustedForumUnreadState(
Dialogs::UnreadState state) {
if (state.chatsTopic) {
state.forums = 1;
if (state.chatsTopic == state.chatsTopicMuted) {
state.forumsMuted = 1;
}
}
return state;
}
} // namespace } // namespace
History::History(not_null<Data::Session*> owner, PeerId peerId) History::History(not_null<Data::Session*> owner, PeerId peerId)
@ -2195,7 +2206,7 @@ History *History::migrateSibling() const {
Dialogs::UnreadState History::chatListUnreadState() const { Dialogs::UnreadState History::chatListUnreadState() const {
if (const auto forum = peer->forum()) { if (const auto forum = peer->forum()) {
return forum->topicsList()->unreadState(); return AdjustedForumUnreadState(forum->topicsList()->unreadState());
} }
return computeUnreadState(); return computeUnreadState();
} }
@ -2204,7 +2215,7 @@ Dialogs::BadgesState History::chatListBadgesState() const {
if (const auto forum = peer->forum()) { if (const auto forum = peer->forum()) {
return adjustBadgesStateByFolder( return adjustBadgesStateByFolder(
Dialogs::BadgesForUnread( Dialogs::BadgesForUnread(
forum->topicsList()->unreadState(), AdjustedForumUnreadState(forum->topicsList()->unreadState()),
Dialogs::CountInBadge::Chats, Dialogs::CountInBadge::Chats,
Dialogs::IncludeInBadge::UnmutedOrAll)); Dialogs::IncludeInBadge::UnmutedOrAll));
} }
@ -3068,7 +3079,7 @@ const Data::Thread *History::threadFor(MsgId topicRootId) const {
void History::forumChanged(Data::Forum *old) { void History::forumChanged(Data::Forum *old) {
if (inChatList()) { if (inChatList()) {
notifyUnreadStateChange(old notifyUnreadStateChange(old
? old->topicsList()->unreadState() ? AdjustedForumUnreadState(old->topicsList()->unreadState())
: computeUnreadState()); : computeUnreadState());
} }
@ -3078,7 +3089,8 @@ void History::forumChanged(Data::Forum *old) {
forum->topicsList()->unreadStateChanges( forum->topicsList()->unreadStateChanges(
) | rpl::filter([=] { ) | rpl::filter([=] {
return (_flags & Flag::IsForum) && inChatList(); return (_flags & Flag::IsForum) && inChatList();
}) | rpl::start_with_next([=](const Dialogs::UnreadState &old) { }) | rpl::map(AdjustedForumUnreadState
) | rpl::start_with_next([=](const Dialogs::UnreadState &old) {
notifyUnreadStateChange(old); notifyUnreadStateChange(old);
}, forum->lifetime()); }, forum->lifetime());

View file

@ -338,9 +338,14 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
const Dialogs::UnreadState &state, const Dialogs::UnreadState &state,
bool includeMuted) { bool includeMuted) {
const auto chats = state.chatsTopic const auto chats = state.chatsTopic
? (state.chats - state.chatsTopic + 1) ? (state.chats - state.chatsTopic + state.forums)
: state.chats; : state.chats;
const auto muted = (state.chatsMuted + state.marksMuted); const auto chatsMuted = state.chatsTopicMuted
? (state.chatsMuted
- state.chatsTopicMuted
+ state.forumsMuted)
: state.chatsMuted;
const auto muted = (chatsMuted + state.marksMuted);
const auto count = (chats + state.marks) const auto count = (chats + state.marks)
- (includeMuted ? 0 : muted); - (includeMuted ? 0 : muted);
const auto isMuted = includeMuted && (count == muted); const auto isMuted = includeMuted && (count == muted);

View file

@ -271,9 +271,14 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
const Dialogs::UnreadState &state, const Dialogs::UnreadState &state,
bool includeMuted) { bool includeMuted) {
const auto chats = state.chatsTopic const auto chats = state.chatsTopic
? (state.chats - state.chatsTopic + 1) ? (state.chats - state.chatsTopic + state.forums)
: state.chats; : state.chats;
const auto muted = (state.chatsMuted + state.marksMuted); const auto chatsMuted = state.chatsTopicMuted
? (state.chatsMuted
- state.chatsTopicMuted
+ state.forumsMuted)
: state.chatsMuted;
const auto muted = (chatsMuted + state.marksMuted);
const auto count = (chats + state.marks) const auto count = (chats + state.marks)
- (includeMuted ? 0 : muted); - (includeMuted ? 0 : muted);
const auto string = !count const auto string = !count