Leave unread chats in filter until closed.

This commit is contained in:
John Preston 2020-03-20 19:19:55 +04:00
parent 1be6d968e0
commit 3ac33e4c1c
5 changed files with 29 additions and 1 deletions

View File

@ -199,7 +199,8 @@ bool ChatFilter::contains(not_null<History*> history) const {
&& (!(_flags & Flag::NoRead)
|| history->unreadCount()
|| history->unreadMark()
|| history->hasUnreadMentions())
|| history->hasUnreadMentions()
|| history->fakeUnreadWhileOpened())
&& (!(_flags & Flag::NoArchived)
|| (history->folderKnown() && !history->folder())))
|| _always.contains(history);

View File

@ -1837,6 +1837,23 @@ bool History::unreadMark() const {
return _unreadMark;
}
void History::setFakeUnreadWhileOpened(bool enabled) {
if (_fakeUnreadWhileOpened == enabled
|| (enabled
&& (!inChatList()
|| (!unreadCount()
&& !unreadMark()
&& !hasUnreadMentions())))) {
return;
}
_fakeUnreadWhileOpened = enabled;
owner().chatsFilters().refreshHistory(this);
}
[[nodiscard]] bool History::fakeUnreadWhileOpened() const {
return _fakeUnreadWhileOpened;
}
bool History::mute() const {
return _mute;
}

View File

@ -202,6 +202,8 @@ public:
void setUnreadCount(int newUnreadCount);
void setUnreadMark(bool unread);
[[nodiscard]] bool unreadMark() const;
void setFakeUnreadWhileOpened(bool enabled);
[[nodiscard]] bool fakeUnreadWhileOpened() const;
[[nodiscard]] int unreadCountForBadge() const; // unreadCount || unreadMark ? 1 : 0.
[[nodiscard]] bool mute() const;
bool changeMute(bool newMute);
@ -540,6 +542,7 @@ private:
std::optional<HistoryItem*> _chatListMessage;
bool _unreadMark = false;
bool _fakeUnreadWhileOpened = false;
// A pointer to the block that is currently being built.
// We hold this pointer so we can destroy it while building

View File

@ -1816,6 +1816,7 @@ void HistoryWidget::showHistory(
&& (!_history->loadedAtTop() || !_migrated->loadedAtBottom())) {
_migrated->clear(History::ClearType::Unload);
}
_history->setFakeUnreadWhileOpened(true);
_topBar->setActiveChat(
_history,

View File

@ -257,7 +257,13 @@ const rpl::variable<Data::Folder*> &SessionController::openedFolder() const {
}
void SessionController::setActiveChatEntry(Dialogs::RowDescriptor row) {
if (const auto history = _activeChatEntry.current().key.history()) {
history->setFakeUnreadWhileOpened(false);
}
_activeChatEntry = row;
if (const auto history = row.key.history()) {
history->setFakeUnreadWhileOpened(true);
}
if (session().supportMode()) {
pushToChatEntryHistory(row);
}