Correctly handle cloud archive unread state.

This commit is contained in:
John Preston 2019-04-25 14:01:09 +04:00
parent accb20a571
commit cb3e649e61
2 changed files with 18 additions and 12 deletions

View File

@ -337,22 +337,31 @@ void Folder::applyDialog(const MTPDdialogFolder &data) {
void Folder::updateCloudUnread(const MTPDdialogFolder &data) { void Folder::updateCloudUnread(const MTPDdialogFolder &data) {
const auto notifier = unreadStateChangeNotifier(!_chatsList.loaded()); const auto notifier = unreadStateChangeNotifier(!_chatsList.loaded());
_cloudUnread.messagesMuted = data.vunread_muted_messages_count.v; _cloudUnread.messages = data.vunread_muted_messages_count.v
_cloudUnread.messages = _cloudUnread.messagesMuted
+ data.vunread_unmuted_messages_count.v; + data.vunread_unmuted_messages_count.v;
_cloudUnread.chatsMuted = data.vunread_muted_peers_count.v; _cloudUnread.chats = data.vunread_muted_peers_count.v
_cloudUnread.chats = _cloudUnread.chatsMuted + data.vunread_unmuted_peers_count.v;
+ data.vunread_unmuted_peers_count.v; finalizeCloudUnread();
_cloudUnread.known = true; _cloudUnread.known = true;
} }
void Folder::finalizeCloudUnread() {
// Cloud state for archive folder always counts everything as muted.
_cloudUnread.messagesMuted = _cloudUnread.messages;
_cloudUnread.chatsMuted = _cloudUnread.chats;
// We don't know the real value of marked chats counts in _cloudUnread.
_cloudUnread.marksMuted = _cloudUnread.marks = 0;
}
Dialogs::UnreadState Folder::chatListUnreadState() const { Dialogs::UnreadState Folder::chatListUnreadState() const {
const auto localUnread = _chatsList.unreadState(); const auto localUnread = _chatsList.unreadState();
auto result = _chatsList.loaded() ? localUnread : _cloudUnread; auto result = _chatsList.loaded() ? localUnread : _cloudUnread;
result.messagesMuted = result.messages; result.messagesMuted = result.messages;
result.chatsMuted = result.chats; result.chatsMuted = result.chats;
// We don't know the real value of marked chats counts. // We don't know the real value of marked chats counts in _cloudUnread.
result.marksMuted = result.marks = localUnread.marks; result.marksMuted = result.marks = localUnread.marks;
return result; return result;
@ -386,9 +395,7 @@ void Folder::unreadStateChanged(
if (updateCloudUnread) { if (updateCloudUnread) {
Assert(nowState.known); Assert(nowState.known);
_cloudUnread += nowState - wasState; _cloudUnread += nowState - wasState;
finalizeCloudUnread();
// We don't know the real value of marked chats counts.
_cloudUnread.marks = _cloudUnread.marksMuted = 0;
} }
} }
@ -417,9 +424,7 @@ void Folder::unreadEntryChanged(
} else { } else {
_cloudUnread -= state; _cloudUnread -= state;
} }
finalizeCloudUnread();
// We don't know the real value of marked chats counts.
_cloudUnread.marks = _cloudUnread.marksMuted = 0;
} }
} }

View File

@ -92,6 +92,7 @@ private:
void addUnreadHistory(not_null<History*> history); void addUnreadHistory(not_null<History*> history);
void removeUnreadHistory(not_null<History*> history); void removeUnreadHistory(not_null<History*> history);
void reorderUnreadHistories(); void reorderUnreadHistories();
void finalizeCloudUnread();
FolderId _id = 0; FolderId _id = 0;
Dialogs::MainList _chatsList; Dialogs::MainList _chatsList;