From c5c62077727aa3fb4627aa699a1f6f8db28185e8 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 8 Sep 2023 18:39:12 +0200 Subject: [PATCH] Forums: Fix displaying as muted (#3808) --- src/components/left/main/ChatBadge.tsx | 2 +- src/global/actions/apiUpdaters/chats.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/left/main/ChatBadge.tsx b/src/components/left/main/ChatBadge.tsx index e915fe76c..92ba32821 100644 --- a/src/components/left/main/ChatBadge.tsx +++ b/src/components/left/main/ChatBadge.tsx @@ -48,7 +48,7 @@ const ChatBadge: FC = ({ const shouldBeMuted = useMemo(() => { const hasUnmutedUnreadTopics = chat.topics - && Object.values(chat.topics).some((acc) => acc.isMuted && acc.unreadCount); + && Object.values(chat.topics).some((acc) => !acc.isMuted && acc.unreadCount); return isMuted || (chat.topics && !hasUnmutedUnreadTopics); }, [chat, isMuted]); diff --git a/src/global/actions/apiUpdaters/chats.ts b/src/global/actions/apiUpdaters/chats.ts index dd26166c3..67676e97a 100644 --- a/src/global/actions/apiUpdaters/chats.ts +++ b/src/global/actions/apiUpdaters/chats.ts @@ -1,6 +1,6 @@ import { addActionHandler, getGlobal, setGlobal } from '../../index'; -import type { ApiUpdateChat } from '../../../api/types'; +import type { ApiMessage, ApiUpdateChat } from '../../../api/types'; import type { ActionReturnType } from '../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; @@ -25,6 +25,7 @@ import { selectThreadParam, selectChatFullInfo, selectTabState, + selectTopicFromMessage, } from '../../selectors'; import { updateUnreadReactions } from '../../reducers/reactions'; import { updateTabState } from '../../reducers/tabs'; @@ -143,6 +144,13 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { }); } + const topic = chat.isForum ? selectTopicFromMessage(global, message as ApiMessage) : undefined; + if (topic) { + global = updateTopic(global, update.chatId, topic.id, { + unreadCount: topic.unreadCount ? topic.unreadCount + 1 : 1, + }); + } + setGlobal(global); notifyAboutMessage({