Message List: Navigate back when opening chat that is previous in the stack

This commit is contained in:
Alexander Zinchuk 2024-09-24 14:48:38 +02:00
parent bceec156b5
commit e731712b74

View File

@ -17,8 +17,7 @@ import {
} from '../../util/iteratees';
import { isLocalMessageId, type MessageKey } from '../../util/keys/messageKey';
import {
hasMessageTtl, isMediaLoadableInViewer,
mergeIdRanges, orderHistoryIds, orderPinnedIds,
hasMessageTtl, isMediaLoadableInViewer, mergeIdRanges, orderHistoryIds, orderPinnedIds,
} from '../helpers';
import {
selectChatMessage,
@ -58,10 +57,18 @@ export function updateCurrentMessageList<T extends GlobalState>(
if (shouldReplaceHistory || (IS_TEST && !IS_MOCKED_CLIENT)) {
newMessageLists = chatId ? [{ chatId, threadId, type }] : [];
} 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 || shouldReplaceLast)) {
newMessageLists = [...messageLists.slice(0, -1), { chatId, threadId, type }];
const current = messageLists[messageLists.length - 1];
if (current?.chatId === chatId && current.threadId === threadId && current.type === type) {
return global;
}
if (current && (current.chatId === TMP_CHAT_ID || shouldReplaceLast)) {
newMessageLists = [...messageLists.slice(0, -1), { chatId, threadId, type }];
} else {
const previous = messageLists[messageLists.length - 2];
if (previous?.chatId === chatId && previous.threadId === threadId && previous.type === type) {
newMessageLists = messageLists.slice(0, -1);
} else {
newMessageLists = [...messageLists, { chatId, threadId, type }];
}
@ -599,10 +606,12 @@ export function updateThreadInfos<T extends GlobalState>(
global: T, updates: Partial<ApiThreadInfo>[],
): T {
updates.forEach((update) => {
global = updateThreadInfo(global,
global = updateThreadInfo(
global,
update.isCommentsInfo ? update.originChannelId! : update.chatId!,
update.isCommentsInfo ? update.originMessageId! : update.threadId!,
update);
update,
);
});
return global;
@ -645,26 +654,28 @@ export function updateQuickReplyMessages<T extends GlobalState>(
};
}
export function updateFocusedMessage<T extends GlobalState>({
global,
chatId,
messageId,
threadId = MAIN_THREAD_ID,
noHighlight = false,
isResizingContainer = false,
quote,
scrollTargetPosition,
}: {
global: T;
chatId?: string;
messageId?: number;
threadId?: ThreadId;
noHighlight?: boolean;
isResizingContainer?: boolean;
quote?: string;
scrollTargetPosition?: ScrollTargetPosition;
},
...[tabId = getCurrentTabId()]: TabArgs<T>): T {
export function updateFocusedMessage<T extends GlobalState>(
{
global,
chatId,
messageId,
threadId = MAIN_THREAD_ID,
noHighlight = false,
isResizingContainer = false,
quote,
scrollTargetPosition,
}: {
global: T;
chatId?: string;
messageId?: number;
threadId?: ThreadId;
noHighlight?: boolean;
isResizingContainer?: boolean;
quote?: string;
scrollTargetPosition?: ScrollTargetPosition;
},
...[tabId = getCurrentTabId()]: TabArgs<T>
): T {
return updateTabState(global, {
focusedMessage: {
...selectTabState(global, tabId).focusedMessage,