2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 22:46:10 +00:00

Track forum unread state by topics inside.

This commit is contained in:
John Preston
2022-10-19 17:55:33 +04:00
parent a292f8a34e
commit 08ba277327
12 changed files with 116 additions and 30 deletions

View File

@@ -2067,6 +2067,13 @@ History *History::migrateSibling() const {
}
int History::chatListUnreadCount() const {
if (peer->isForum()) {
const auto state = chatListUnreadState();
return state.marks
+ (Core::App().settings().countUnreadMessages()
? state.messages
: state.chats);
}
const auto result = unreadCount();
if (const auto migrated = migrateSibling()) {
return result + migrated->unreadCount();
@@ -2084,10 +2091,24 @@ bool History::chatListUnreadMark() const {
}
bool History::chatListMutedBadge() const {
if (const auto forum = peer->forum()) {
const auto state = forum->topicsList()->unreadState();
return (state.marksMuted >= state.marks)
&& (Core::App().settings().countUnreadMessages()
? (state.messagesMuted >= state.messages)
: (state.chatsMuted >= state.chats));
}
return muted();
}
Dialogs::UnreadState History::chatListUnreadState() const {
if (const auto forum = peer->forum()) {
return forum->topicsList()->unreadState();
}
return computeUnreadState();
}
Dialogs::UnreadState History::computeUnreadState() const {
auto result = Dialogs::UnreadState();
const auto count = _unreadCount.value_or(0);
const auto mark = !count && unreadMark();
@@ -2639,6 +2660,10 @@ void History::applyDialog(
draft->c_draftMessage());
}
owner().histories().dialogEntryApplied(this);
if (const auto forum = inChatList() ? peer->forum() : nullptr) {
forum->preloadTopics();
}
}
void History::dialogEntryApplied() {
@@ -2868,6 +2893,28 @@ const Data::Thread *History::threadFor(MsgId topicRootId) const {
return const_cast<History*>(this)->threadFor(topicRootId);
}
void History::forumChanged(Data::Forum *old) {
if (inChatList()) {
notifyUnreadStateChange(old
? old->topicsList()->unreadState()
: computeUnreadState());
}
if (const auto forum = peer->forum()) {
_flags |= Flag::IsForum;
forum->topicsList()->unreadStateChanges(
) | rpl::filter([=] {
return (_flags & Flag::IsForum) && inChatList();
}) | rpl::start_with_next([=](const Dialogs::UnreadState &old) {
notifyUnreadStateChange(old);
updateChatListEntryPostponed();
}, forum->lifetime());
} else {
_flags &= ~Flag::IsForum;
}
}
not_null<History*> History::migrateToOrMe() const {
if (const auto to = peer->migrateTo()) {
return owner().history(to);