From 47325b3d4801f3b41f2ea17db585078292cc861d Mon Sep 17 00:00:00 2001 From: morethanwords Date: Fri, 17 Dec 2021 20:28:38 +0400 Subject: [PATCH] Fix unread mentions count --- src/components/chat/input.ts | 2 +- src/lib/appManagers/appMessagesManager.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index aa23c5bd..4f36f827 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -859,7 +859,7 @@ export default class ChatInput { this.goDownUnreadBadge.classList.toggle('badge-gray', this.appNotificationsManager.isPeerLocalMuted(this.chat.peerId, true)); if(this.goMentionUnreadBadge && this.chat.type === 'chat') { - const hasMentions = !!dialog?.unread_mentions_count; + const hasMentions = !!(dialog?.unread_mentions_count && dialog.unread_count); this.goMentionUnreadBadge.innerText = hasMentions ? '' + (dialog.unread_mentions_count) : ''; this.goMentionBtn.classList.toggle('is-visible', hasMentions); } diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 9926dd7b..d31b43bc 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -4618,7 +4618,7 @@ export class AppMessagesManager { foundDialog.unread_count = setCount; } - if(newUnreadMentionsCount < 0) { + if(newUnreadMentionsCount < 0 || !foundDialog.unread_count) { foundDialog.unread_mentions_count = 0; } } @@ -4730,14 +4730,14 @@ export class AppMessagesManager { const affected = historyUpdated.unreadMentions || historyUpdated.unread; const releaseUnreadCount = affected && this.dialogsStorage.prepareDialogUnreadCountModifying(foundDialog); - if(historyUpdated.unreadMentions) { - foundDialog.unread_mentions_count = Math.max(0, foundDialog.unread_mentions_count - historyUpdated.unreadMentions); - } - if(historyUpdated.unread) { foundDialog.unread_count = Math.max(0, foundDialog.unread_count - historyUpdated.unread); } + if(historyUpdated.unreadMentions) { + foundDialog.unread_mentions_count = !foundDialog.unread_count ? 0 : Math.max(0, foundDialog.unread_mentions_count - historyUpdated.unreadMentions); + } + if(affected) { releaseUnreadCount(); rootScope.dispatchEvent('dialog_unread', {peerId});