From 4e546ebf41addf3a17f0559ba86f3a5f26de77de Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 5 Nov 2021 21:57:24 +0300 Subject: [PATCH] Message List: Some fixes for navigation history --- src/config.ts | 1 + src/modules/actions/api/chats.ts | 19 ++++++++++--------- src/modules/reducers/messages.ts | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/config.ts b/src/config.ts index 6116c8921..4cab66207 100644 --- a/src/config.ts +++ b/src/config.ts @@ -88,6 +88,7 @@ export const MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH = 950; // px export const MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT = 450; // px export const LOCAL_MESSAGE_ID_BASE = 1e9; +export const TMP_CHAT_ID = '0'; export const ANIMATION_END_DELAY = 100; diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 59bb0cb7e..37ca3177e 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -13,7 +13,10 @@ import { TOP_CHAT_MESSAGES_PRELOAD_LIMIT, CHAT_LIST_LOAD_SLICE, TIPS_USERNAME, - LOCALIZED_TIPS, RE_TG_LINK, SERVICE_NOTIFICATIONS_USER_ID, + LOCALIZED_TIPS, + RE_TG_LINK, + SERVICE_NOTIFICATIONS_USER_ID, + TMP_CHAT_ID, } from '../../../config'; import { callApi } from '../../../api/gramjs'; import { @@ -47,8 +50,6 @@ import { processDeepLink } from '../../../util/deeplink'; const TOP_CHAT_MESSAGES_PRELOAD_INTERVAL = 100; const CHATS_PRELOAD_INTERVAL = 300; -// We expect this ID does not exist -const TMP_CHAT_ID = -1; const runThrottledForLoadChats = throttle((cb) => cb(), CHATS_PRELOAD_INTERVAL, true); const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true); @@ -158,17 +159,17 @@ addReducer('focusMessageInComments', (global, actions, payload) => { addReducer('openSupportChat', (global, actions) => { const chat = selectSupportChat(global); - - actions.openChat({ id: chat ? chat.id : TMP_CHAT_ID }); - if (chat) { + actions.openChat({ id: chat.id, shouldReplaceHistory: true }); return; } + actions.openChat({ id: TMP_CHAT_ID, shouldReplaceHistory: true }); + (async () => { const result = await callApi('fetchChat', { type: 'support' }); if (result) { - actions.openChat({ id: result.chatId }); + actions.openChat({ id: result.chatId, shouldReplaceHistory: true }); } })(); }); @@ -1071,7 +1072,7 @@ async function createChannel(title: string, users: ApiUser[], about?: string, ph }, }; setGlobal(global); - getDispatch().openChat({ id: channelId }); + getDispatch().openChat({ id: channelId, shouldReplaceHistory: true }); if (channelId && accessHash && photo) { await callApi('editChatPhoto', { chatId: channelId, accessHash, photo }); @@ -1103,7 +1104,7 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) { }, }; setGlobal(global); - getDispatch().openChat({ id: chatId }); + getDispatch().openChat({ id: chatId, shouldReplaceHistory: true }); if (chatId && photo) { await callApi('editChatPhoto', { chatId, photo }); diff --git a/src/modules/reducers/messages.ts b/src/modules/reducers/messages.ts index d49e95288..0d84b7421 100644 --- a/src/modules/reducers/messages.ts +++ b/src/modules/reducers/messages.ts @@ -4,7 +4,9 @@ import { import { ApiMessage, ApiThreadInfo, MAIN_THREAD_ID } from '../../api/types'; import { FocusDirection } from '../../types'; -import { IS_TEST, MESSAGE_LIST_SLICE, MESSAGE_LIST_VIEWPORT_LIMIT } from '../../config'; +import { + IS_TEST, MESSAGE_LIST_SLICE, MESSAGE_LIST_VIEWPORT_LIMIT, TMP_CHAT_ID, +} from '../../config'; import { selectListedIds, selectChatMessages, @@ -23,8 +25,6 @@ import { areSortedArraysEqual, omit, pickTruthy, unique, } from '../../util/iteratees'; -const TMP_CHAT_ID = '-1'; - type MessageStoreSections = { byId: Record; threadsById: Record;