Comments: Fix opening invalid posts (#2915)

This commit is contained in:
Alexander Zinchuk 2023-04-06 08:20:02 +02:00
parent e070ffe8a0
commit 743715cdb1
3 changed files with 17 additions and 6 deletions

View File

@ -116,7 +116,7 @@ addActionHandler('preloadTopChatMessages', async (global, actions): Promise<void
addActionHandler('openChat', (global, actions, payload): ActionReturnType => {
const {
id, threadId = MAIN_THREAD_ID,
id, threadId = MAIN_THREAD_ID, noRequestThreadInfoUpdate,
} = payload;
if (!id) {
return;
@ -142,7 +142,7 @@ addActionHandler('openChat', (global, actions, payload): ActionReturnType => {
actions.requestChatUpdate({ chatId: id });
}
if (threadId !== MAIN_THREAD_ID) {
if (threadId !== MAIN_THREAD_ID && !noRequestThreadInfoUpdate) {
actions.requestThreadInfoUpdate({ chatId: id, threadId });
}
});
@ -160,7 +160,9 @@ addActionHandler('openComments', async (global, actions, payload): Promise<void>
return;
}
actions.openChat({ id, threadId, tabId });
actions.openChat({
id, threadId, tabId, noRequestThreadInfoUpdate: true,
});
const result = await callApi('requestThreadInfoUpdate', { chat, threadId, originChannelId });
if (!result) {
@ -176,9 +178,15 @@ addActionHandler('openComments', async (global, actions, payload): Promise<void>
threadId: result.topMessageId,
tabId,
shouldReplaceLast: true,
noRequestThreadInfoUpdate: true,
});
} else {
actions.openChat({ id, threadId: topMessageId, tabId });
actions.openChat({
id,
threadId: topMessageId,
tabId,
noRequestThreadInfoUpdate: true,
});
}
}
});

View File

@ -80,7 +80,7 @@ import {
selectSendAs,
selectSponsoredMessage,
selectTabState,
selectThreadIdFromMessage,
selectThreadIdFromMessage, selectThreadOriginChat,
selectThreadTopMessageId,
selectUser,
selectViewportIds,
@ -870,7 +870,9 @@ addActionHandler('requestThreadInfoUpdate', async (global, actions, payload): Pr
return;
}
const result = await callApi('requestThreadInfoUpdate', { chat, threadId });
const originChannelId = selectThreadOriginChat(global, chatId, threadId)?.id;
const result = await callApi('requestThreadInfoUpdate', { chat, threadId, originChannelId });
if (!result) return;
global = getGlobal();
global = addUsers(global, buildCollectionByKey(result.users, 'id'));

View File

@ -1606,6 +1606,7 @@ export interface ActionPayloads {
shouldReplaceHistory?: boolean;
shouldReplaceLast?: boolean;
noForumTopicPanel?: boolean;
noRequestThreadInfoUpdate?: boolean;
} & WithTabId;
openComments: {
id: string;