diff --git a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp index ee552a265..168dcb7e2 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_main_list.cpp @@ -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 &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; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index a908dfbb6..6da131959 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -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; }