From 4b2c83b5bac58b538b8ce42124e5dbf0ec952ebd Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 8 Feb 2023 00:47:57 +0100 Subject: [PATCH] Forums: Update topic message counter on server update (#2524) --- src/api/gramjs/updater.ts | 9 +++++++++ src/global/actions/apiUpdaters/messages.ts | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/api/gramjs/updater.ts b/src/api/gramjs/updater.ts index 6bbec5b09..6c36480a0 100644 --- a/src/api/gramjs/updater.ts +++ b/src/api/gramjs/updater.ts @@ -594,6 +594,15 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) { lastReadOutboxMessageId: update.maxId, }, }); + } else if (update instanceof GramJs.UpdateReadChannelDiscussionInbox) { + onUpdate({ + '@type': 'updateThreadInfo', + chatId: buildApiPeerId(update.channelId, 'channel'), + threadId: update.topMsgId, + threadInfo: { + lastReadInboxMessageId: update.readMaxId, + }, + }); } else if ( update instanceof GramJs.UpdateDialogPinned && update.peer instanceof GramJs.DialogPeer diff --git a/src/global/actions/apiUpdaters/messages.ts b/src/global/actions/apiUpdaters/messages.ts index b83d1727a..782e38c8a 100644 --- a/src/global/actions/apiUpdaters/messages.ts +++ b/src/global/actions/apiUpdaters/messages.ts @@ -361,6 +361,11 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { global = replaceThreadParam(global, chatId, threadId, 'firstMessageId', firstMessageId); } + const chat = selectChat(global, chatId); + if (chat?.isForum && threadInfo.lastReadInboxMessageId !== currentThreadInfo?.lastReadInboxMessageId) { + actions.loadTopicById({ chatId, topicId: threadId }); + } + setGlobal(global); break;