From 17ff3b47a7f1ce1321a4a11c6b81f59ee6dd7f79 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 3 Mar 2023 16:35:19 +0100 Subject: [PATCH] Chat List: Fix update notification disappearing after sync (#2742) --- src/global/actions/api/chats.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 0e3d58086..e6fc7b930 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -1817,7 +1817,7 @@ async function loadChats( isFullDraftSync?: boolean, ) { global = getGlobal(); - const lastLocalServiceMessage = selectLastServiceNotification(global)?.message; + let lastLocalServiceMessage = selectLastServiceNotification(global)?.message; const result = await callApi('fetchChats', { limit: CHAT_LIST_LOAD_SLICE, offsetDate, @@ -1838,6 +1838,8 @@ async function loadChats( global = getGlobal(); + lastLocalServiceMessage = selectLastServiceNotification(global)?.message; + if (shouldReplace && listType === 'active') { // Always include service notifications chat if (!chatIds.includes(SERVICE_NOTIFICATIONS_USER_ID)) { @@ -1882,9 +1884,20 @@ async function loadChats( global = updateChats(global, buildCollectionByKey(result.chats, 'id')); global = replaceChatListIds(global, listType, chatIds); } else { + const newChats = buildCollectionByKey(result.chats, 'id'); + if (chatIds.includes(SERVICE_NOTIFICATIONS_USER_ID)) { + const notificationsChat = newChats[SERVICE_NOTIFICATIONS_USER_ID]; + if (notificationsChat && lastLocalServiceMessage) { + newChats[SERVICE_NOTIFICATIONS_USER_ID] = { + ...notificationsChat, + lastMessage: lastLocalServiceMessage, + }; + } + } + global = addUsers(global, buildCollectionByKey(result.users, 'id')); global = addUserStatuses(global, result.userStatusesById); - global = updateChats(global, buildCollectionByKey(result.chats, 'id')); + global = updateChats(global, newChats); global = updateChatListIds(global, listType, chatIds); }