Fix filters unread counters.

This commit is contained in:
John Preston 2020-03-18 17:39:08 +04:00
parent 36b9911995
commit f0322cd107
2 changed files with 34 additions and 29 deletions

View file

@ -45,9 +45,11 @@ void MainList::setLoaded(bool loaded) {
if (_loaded == loaded) {
return;
}
const auto recomputer = gsl::finally([&] {
recomputeFullListSize();
});
const auto notifier = unreadStateChangeNotifier(true);
_loaded = loaded;
recomputeFullListSize();
}
void MainList::setAllAreMuted(bool allAreMuted) {
@ -71,6 +73,9 @@ const rpl::variable<int> &MainList::fullSize() const {
}
void MainList::clear() {
const auto recomputer = gsl::finally([&] {
recomputeFullListSize();
});
const auto notifier = unreadStateChangeNotifier(true);
_all.clear();
_unreadState = UnreadState();
@ -78,7 +83,6 @@ void MainList::clear() {
_unreadState.known = true;
_cloudUnreadState.known = true;
_cloudListSize = 0;
recomputeFullListSize();
}
RowsByLetter MainList::addEntry(const Key &key) {
@ -125,7 +129,7 @@ void MainList::unreadEntryChanged(
return;
}
const auto updateCloudUnread = _cloudUnreadState.known && state.known;
const auto notify = loaded() || updateCloudUnread;
const auto notify = !_cloudUnreadState.known || loaded() || state.known;
const auto notifier = unreadStateChangeNotifier(notify);
if (added) {
_unreadState += state;

View file

@ -1781,13 +1781,17 @@ void History::setUnreadCount(int newUnreadCount) {
if (_unreadCount == newUnreadCount) {
return;
}
const auto notifier = unreadStateChangeNotifier(true);
const auto wasForBadge = (unreadCountForBadge() > 0);
const auto refresher = gsl::finally([&] {
if (wasForBadge != (unreadCountForBadge() > 0)) {
owner().chatsFilters().refreshHistory(this);
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::UnreadViewChanged);
});
const auto notifier = unreadStateChangeNotifier(true);
_unreadCount = newUnreadCount;
if (wasForBadge != (unreadCountForBadge() > 0)) {
owner().chatsFilters().refreshHistory(this);
}
if (newUnreadCount == 1) {
if (loadedAtBottom()) {
@ -1806,9 +1810,6 @@ void History::setUnreadCount(int newUnreadCount) {
} else if (!_firstUnreadView && !_unreadBarView && loadedAtBottom()) {
calculateFirstUnreadMessage();
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::UnreadViewChanged);
}
void History::setUnreadMark(bool unread) {
@ -1819,17 +1820,17 @@ void History::setUnreadMark(bool unread) {
return;
}
const auto noUnreadMessages = !unreadCount();
const auto refresher = gsl::finally([&] {
if (inChatList() && noUnreadMessages) {
owner().chatsFilters().refreshHistory(this);
updateChatListEntry();
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::UnreadViewChanged);
});
const auto notifier = unreadStateChangeNotifier(noUnreadMessages);
_unreadMark = unread;
if (inChatList() && noUnreadMessages) {
owner().chatsFilters().refreshHistory(this);
updateChatListEntry();
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::UnreadViewChanged);
}
bool History::unreadMark() const {
@ -1844,18 +1845,18 @@ bool History::changeMute(bool newMute) {
if (_mute == newMute) {
return false;
}
const auto refresher = gsl::finally([&] {
if (inChatList()) {
owner().chatsFilters().refreshHistory(this);
updateChatListEntry();
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::NotificationsEnabled);
});
const auto notify = (unreadCountForBadge() > 0);
const auto notifier = unreadStateChangeNotifier(notify);
_mute = newMute;
if (inChatList()) {
owner().chatsFilters().refreshHistory(this);
updateChatListEntry();
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::NotificationsEnabled);
return true;
}