diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 0e3798cff..1c3735afa 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -160,7 +160,7 @@ addActionHandler('openComments', async (global, actions, payload): Promise return; } - actions.openChat({ id: TMP_CHAT_ID, tabId }); + actions.openChat({ id, threadId, tabId }); const result = await callApi('requestThreadInfoUpdate', { chat, threadId, originChannelId }); if (!result) { @@ -171,7 +171,12 @@ addActionHandler('openComments', async (global, actions, payload): Promise global = addUsers(global, buildCollectionByKey(result.users, 'id')); setGlobal(global); - actions.openChat({ id, threadId: result.topMessageId, tabId }); + actions.openChat({ + id, + threadId: result.topMessageId, + tabId, + shouldReplaceLast: true, + }); } else { actions.openChat({ id, threadId: topMessageId, tabId }); } diff --git a/src/global/actions/ui/chats.ts b/src/global/actions/ui/chats.ts index 3fe3b7526..65d593d8c 100644 --- a/src/global/actions/ui/chats.ts +++ b/src/global/actions/ui/chats.ts @@ -18,6 +18,7 @@ addActionHandler('openChat', (global, actions, payload): ActionReturnType => { threadId = MAIN_THREAD_ID, type = 'thread', shouldReplaceHistory = false, + shouldReplaceLast = false, noForumTopicPanel, tabId = getCurrentTabId(), } = payload; @@ -71,7 +72,7 @@ addActionHandler('openChat', (global, actions, payload): ActionReturnType => { actions.updatePageTitle({ tabId }); - return updateCurrentMessageList(global, id, threadId, type, shouldReplaceHistory, tabId); + return updateCurrentMessageList(global, id, threadId, type, shouldReplaceHistory, shouldReplaceLast, tabId); }); addActionHandler('openChatInNewTab', (global, actions, payload): ActionReturnType => { @@ -82,7 +83,7 @@ addActionHandler('openChatInNewTab', (global, actions, payload): ActionReturnTyp addActionHandler('openPreviousChat', (global, actions, payload): ActionReturnType => { const { tabId = getCurrentTabId() } = payload || {}; - return updateCurrentMessageList(global, undefined, undefined, undefined, undefined, tabId); + return updateCurrentMessageList(global, undefined, undefined, undefined, undefined, undefined, tabId); }); addActionHandler('openChatWithInfo', (global, actions, payload): ActionReturnType => { diff --git a/src/global/reducers/messages.ts b/src/global/reducers/messages.ts index e0c0bd0e4..9868b9053 100644 --- a/src/global/reducers/messages.ts +++ b/src/global/reducers/messages.ts @@ -45,6 +45,7 @@ export function updateCurrentMessageList( threadId: number = MAIN_THREAD_ID, type: MessageListType = 'thread', shouldReplaceHistory?: boolean, + shouldReplaceLast?: boolean, ...[tabId = getCurrentTabId()]: TabArgs ): T { const { messageLists } = selectTabState(global, tabId); @@ -54,7 +55,7 @@ export function updateCurrentMessageList( } else if (chatId) { const last = messageLists[messageLists.length - 1]; if (!last || last.chatId !== chatId || last.threadId !== threadId || last.type !== type) { - if (last && last.chatId === TMP_CHAT_ID) { + if (last && (last.chatId === TMP_CHAT_ID || shouldReplaceLast)) { newMessageLists = [...messageLists.slice(0, -1), { chatId, threadId, type }]; } else { newMessageLists = [...messageLists, { chatId, threadId, type }]; @@ -310,7 +311,7 @@ export function deleteChatMessages( const originalPost = selectChatMessage(global, fromChatId!, fromMessageId!); if (canDeleteCurrentThread && currentThreadId === fromMessageId) { - global = updateCurrentMessageList(global, chatId, undefined, undefined, undefined, tabId); + global = updateCurrentMessageList(global, chatId, undefined, undefined, undefined, undefined, tabId); } if (originalPost) { global = updateChatMessage(global, fromChatId!, fromMessageId!, { repliesThreadInfo: undefined }); diff --git a/src/global/types.ts b/src/global/types.ts index db7296f4a..7729c459f 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -1606,6 +1606,7 @@ export interface ActionPayloads { threadId?: number; type?: MessageListType; shouldReplaceHistory?: boolean; + shouldReplaceLast?: boolean; noForumTopicPanel?: boolean; } & WithTabId; openComments: {