Comments: Fix header blink when opening (#2831)

This commit is contained in:
Alexander Zinchuk 2023-03-19 22:33:40 -05:00
parent 55d711e683
commit a7fb1958a1
4 changed files with 14 additions and 6 deletions

View File

@ -160,7 +160,7 @@ addActionHandler('openComments', async (global, actions, payload): Promise<void>
return; return;
} }
actions.openChat({ id: TMP_CHAT_ID, tabId }); actions.openChat({ id, threadId, tabId });
const result = await callApi('requestThreadInfoUpdate', { chat, threadId, originChannelId }); const result = await callApi('requestThreadInfoUpdate', { chat, threadId, originChannelId });
if (!result) { if (!result) {
@ -171,7 +171,12 @@ addActionHandler('openComments', async (global, actions, payload): Promise<void>
global = addUsers(global, buildCollectionByKey(result.users, 'id')); global = addUsers(global, buildCollectionByKey(result.users, 'id'));
setGlobal(global); setGlobal(global);
actions.openChat({ id, threadId: result.topMessageId, tabId }); actions.openChat({
id,
threadId: result.topMessageId,
tabId,
shouldReplaceLast: true,
});
} else { } else {
actions.openChat({ id, threadId: topMessageId, tabId }); actions.openChat({ id, threadId: topMessageId, tabId });
} }

View File

@ -18,6 +18,7 @@ addActionHandler('openChat', (global, actions, payload): ActionReturnType => {
threadId = MAIN_THREAD_ID, threadId = MAIN_THREAD_ID,
type = 'thread', type = 'thread',
shouldReplaceHistory = false, shouldReplaceHistory = false,
shouldReplaceLast = false,
noForumTopicPanel, noForumTopicPanel,
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload; } = payload;
@ -71,7 +72,7 @@ addActionHandler('openChat', (global, actions, payload): ActionReturnType => {
actions.updatePageTitle({ tabId }); 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 => { addActionHandler('openChatInNewTab', (global, actions, payload): ActionReturnType => {
@ -82,7 +83,7 @@ addActionHandler('openChatInNewTab', (global, actions, payload): ActionReturnTyp
addActionHandler('openPreviousChat', (global, actions, payload): ActionReturnType => { addActionHandler('openPreviousChat', (global, actions, payload): ActionReturnType => {
const { tabId = getCurrentTabId() } = payload || {}; 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 => { addActionHandler('openChatWithInfo', (global, actions, payload): ActionReturnType => {

View File

@ -45,6 +45,7 @@ export function updateCurrentMessageList<T extends GlobalState>(
threadId: number = MAIN_THREAD_ID, threadId: number = MAIN_THREAD_ID,
type: MessageListType = 'thread', type: MessageListType = 'thread',
shouldReplaceHistory?: boolean, shouldReplaceHistory?: boolean,
shouldReplaceLast?: boolean,
...[tabId = getCurrentTabId()]: TabArgs<T> ...[tabId = getCurrentTabId()]: TabArgs<T>
): T { ): T {
const { messageLists } = selectTabState(global, tabId); const { messageLists } = selectTabState(global, tabId);
@ -54,7 +55,7 @@ export function updateCurrentMessageList<T extends GlobalState>(
} else if (chatId) { } else if (chatId) {
const last = messageLists[messageLists.length - 1]; const last = messageLists[messageLists.length - 1];
if (!last || last.chatId !== chatId || last.threadId !== threadId || last.type !== type) { 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 }]; newMessageLists = [...messageLists.slice(0, -1), { chatId, threadId, type }];
} else { } else {
newMessageLists = [...messageLists, { chatId, threadId, type }]; newMessageLists = [...messageLists, { chatId, threadId, type }];
@ -310,7 +311,7 @@ export function deleteChatMessages<T extends GlobalState>(
const originalPost = selectChatMessage(global, fromChatId!, fromMessageId!); const originalPost = selectChatMessage(global, fromChatId!, fromMessageId!);
if (canDeleteCurrentThread && currentThreadId === fromMessageId) { if (canDeleteCurrentThread && currentThreadId === fromMessageId) {
global = updateCurrentMessageList(global, chatId, undefined, undefined, undefined, tabId); global = updateCurrentMessageList(global, chatId, undefined, undefined, undefined, undefined, tabId);
} }
if (originalPost) { if (originalPost) {
global = updateChatMessage(global, fromChatId!, fromMessageId!, { repliesThreadInfo: undefined }); global = updateChatMessage(global, fromChatId!, fromMessageId!, { repliesThreadInfo: undefined });

View File

@ -1606,6 +1606,7 @@ export interface ActionPayloads {
threadId?: number; threadId?: number;
type?: MessageListType; type?: MessageListType;
shouldReplaceHistory?: boolean; shouldReplaceHistory?: boolean;
shouldReplaceLast?: boolean;
noForumTopicPanel?: boolean; noForumTopicPanel?: boolean;
} & WithTabId; } & WithTabId;
openComments: { openComments: {