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

View file

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