2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-01 15:05:56 +00:00

Count unread messages in Dialogs::MainList.

This commit is contained in:
John Preston
2020-03-16 14:20:18 +04:00
parent 9636617798
commit 38a744fe5b
13 changed files with 257 additions and 208 deletions

View File

@@ -72,6 +72,22 @@ Folder::Folder(not_null<Data::Session*> owner, FolderId id)
}
}
}, _lifetime);
_chatsList.setAllAreMuted(true);
_chatsList.unreadStateChanges(
) | rpl::filter([=] {
return inChatList();
}) | rpl::start_with_next([=](const Dialogs::UnreadState &old) {
++_chatListViewVersion;
notifyUnreadStateChange(old);
updateChatListEntry();
}, _lifetime);
_chatsList.fullSize().changes(
) | rpl::start_with_next([=] {
updateChatListEntry();
}, _lifetime);
}
FolderId Folder::id() const {
@@ -108,7 +124,7 @@ void Folder::indexNameParts() {
void Folder::registerOne(not_null<History*> history) {
if (_chatsList.indexed()->size() == 1) {
updateChatListSortPosition();
if (!_cloudUnread.known) {
if (!_chatsList.cloudUnreadKnown()) {
owner().histories().requestDialogEntry(this);
}
} else {
@@ -291,29 +307,6 @@ void Folder::paintUserpic(
//}
}
bool Folder::chatsListLoaded() const {
return _chatsList.loaded();
}
void Folder::setChatsListLoaded(bool loaded) {
if (_chatsList.loaded() == loaded) {
return;
}
const auto notifier = unreadStateChangeNotifier(true);
_chatsList.setLoaded(loaded);
}
void Folder::setCloudChatsListSize(int size) {
_cloudChatsListSize = size;
updateChatListEntry();
}
int Folder::chatsListSize() const {
return std::max(
_chatsList.indexed()->size(),
_chatsList.loaded() ? 0 : _cloudChatsListSize);
}
const std::vector<not_null<History*>> &Folder::lastHistories() const {
return _lastHistories;
}
@@ -333,7 +326,7 @@ TimeId Folder::adjustedChatListTimeId() const {
}
void Folder::applyDialog(const MTPDdialogFolder &data) {
updateCloudUnread(data);
_chatsList.updateCloudUnread(data);
if (const auto peerId = peerFromMTP(data.vpeer())) {
const auto history = owner().history(peerId);
const auto fullId = FullMsgId(
@@ -349,39 +342,6 @@ void Folder::applyDialog(const MTPDdialogFolder &data) {
}
}
void Folder::updateCloudUnread(const MTPDdialogFolder &data) {
const auto notifier = unreadStateChangeNotifier(!_chatsList.loaded());
_cloudUnread.messages = data.vunread_muted_messages_count().v
+ data.vunread_unmuted_messages_count().v;
_cloudUnread.chats = data.vunread_muted_peers_count().v
+ data.vunread_unmuted_peers_count().v;
finalizeCloudUnread();
_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 {
const auto localUnread = _chatsList.unreadState();
auto result = _chatsList.loaded() ? localUnread : _cloudUnread;
result.messagesMuted = result.messages;
result.chatsMuted = result.chats;
// We don't know the real value of marked chats counts in _cloudUnread.
result.marksMuted = result.marks = localUnread.marks;
return result;
}
void Folder::applyPinnedUpdate(const MTPDupdateDialogPinned &data) {
const auto folderId = data.vfolder_id().value_or_empty();
if (folderId != 0) {
@@ -390,48 +350,6 @@ void Folder::applyPinnedUpdate(const MTPDupdateDialogPinned &data) {
owner().setChatPinned(this, data.is_pinned());
}
void Folder::unreadStateChanged(
const Dialogs::Key &key,
const Dialogs::UnreadState &wasState,
const Dialogs::UnreadState &nowState) {
if (const auto history = key.history()) {
if (wasState.empty() != nowState.empty()) {
++_chatListViewVersion;
updateChatListEntry();
}
}
const auto updateCloudUnread = _cloudUnread.known && wasState.known;
const auto notify = _chatsList.loaded() || updateCloudUnread;
const auto notifier = unreadStateChangeNotifier(notify);
_chatsList.unreadStateChanged(wasState, nowState);
if (updateCloudUnread) {
Assert(nowState.known);
_cloudUnread += nowState - wasState;
finalizeCloudUnread();
}
}
void Folder::unreadEntryChanged(
const Dialogs::Key &key,
const Dialogs::UnreadState &state,
bool added) {
const auto updateCloudUnread = _cloudUnread.known && state.known;
const auto notify = _chatsList.loaded() || updateCloudUnread;
const auto notifier = unreadStateChangeNotifier(notify);
_chatsList.unreadEntryChanged(state, added);
if (updateCloudUnread) {
if (added) {
_cloudUnread += state;
} else {
_cloudUnread -= state;
}
finalizeCloudUnread();
}
}
// #feed
//MessagePosition Folder::unreadPosition() const {
// return _unreadPosition.current();
@@ -457,6 +375,10 @@ int Folder::chatListUnreadCount() const {
: state.chats);
}
Dialogs::UnreadState Folder::chatListUnreadState() const {
return _chatsList.unreadState();
}
bool Folder::chatListUnreadMark() const {
return false; // #feed unread mark
}