From 0f67f75bed0cc12f354450ffd032e8bdeaa4f15a Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 13 Dec 2018 16:31:03 +0400 Subject: [PATCH] Version 1.5.2: Fix unread mentions in workmode. --- .../dialogs/dialogs_inner_widget.cpp | 2 +- Telegram/SourceFiles/history/history.cpp | 18 +++++++++++++----- Telegram/SourceFiles/history/history.h | 4 +--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index dbcd82ab0..8ca192448 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -2031,7 +2031,7 @@ void DialogsInner::userIsContactUpdated(not_null user) { void DialogsInner::notify_historyMuteUpdated(History *history) { if (!_dialogsImportant || !history->inChatList(Dialogs::Mode::All)) return; - if (history->mute()) { + if (!history->toImportant()) { if (Global::DialogsMode() == Dialogs::Mode::Important) { if (_selected && _selected->history() == history) { _selected = nullptr; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index af3962a83..879a2e562 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -947,11 +947,17 @@ not_null History::addNewGame( } void History::setUnreadMentionsCount(int count) { + const auto had = _unreadMentionsCount && (*_unreadMentionsCount > 0); if (_unreadMentions.size() > count) { LOG(("API Warning: real mentions count is greater than received mentions count")); count = _unreadMentions.size(); } _unreadMentionsCount = count; + const auto has = (count > 0); + if (has != had && Global::DialogsModeEnabled()) { + Notify::historyMuteUpdated(this); + updateChatListEntry(); + } } bool History::addToUnreadMentions( @@ -965,8 +971,8 @@ bool History::addToUnreadMentions( : false; if (allLoaded) { if (type == UnreadMentionType::New) { - ++*_unreadMentionsCount; _unreadMentions.insert(msgId); + setUnreadMentionsCount(*_unreadMentionsCount + 1); return true; } } else if (!_unreadMentions.empty() && type != UnreadMentionType::New) { @@ -978,10 +984,8 @@ bool History::addToUnreadMentions( void History::eraseFromUnreadMentions(MsgId msgId) { _unreadMentions.remove(msgId); - if (_unreadMentionsCount) { - if (*_unreadMentionsCount > 0) { - --*_unreadMentionsCount; - } + if (_unreadMentionsCount && *_unreadMentionsCount > 0) { + setUnreadMentionsCount(*_unreadMentionsCount - 1); } Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::UnreadMentionsChanged); } @@ -2362,6 +2366,10 @@ bool History::shouldBeInChatList() const { return true; } +bool History::toImportant() const { + return !mute() || hasUnreadMentions(); +} + void History::unknownMessageDeleted(MsgId messageId) { if (_inboxReadBefore && messageId >= *_inboxReadBefore) { changeUnreadCount(-1); diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index a4fc1e869..8b794eb31 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -348,9 +348,7 @@ public: bool useProxyPromotion() const override; void updateChatListExistence() override; bool shouldBeInChatList() const override; - bool toImportant() const override { - return !mute(); - } + bool toImportant() const override; int chatListUnreadCount() const override; bool chatListUnreadMark() const override; bool chatListMutedBadge() const override;