From 342a3d92dab675aab9893381e6b0d492856fbe8b Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 6 Sep 2024 15:43:25 +0200 Subject: [PATCH] Messages: Fix deleting in the selected messages modal (#4927) --- .../middle/DeleteSelectedMessageModal.tsx | 5 ++- src/global/actions/api/messages.ts | 44 ++++++++++--------- src/global/selectors/messages.ts | 2 +- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/components/middle/DeleteSelectedMessageModal.tsx b/src/components/middle/DeleteSelectedMessageModal.tsx index 46886129a..d05732dcd 100644 --- a/src/components/middle/DeleteSelectedMessageModal.tsx +++ b/src/components/middle/DeleteSelectedMessageModal.tsx @@ -20,13 +20,13 @@ import { isUserId, } from '../../global/helpers'; import { + getSendersFromSelectedMessages, selectCanDeleteSelectedMessages, selectChatFullInfo, selectCurrentChat, selectCurrentMessageIds, selectCurrentMessageList, selectSenderFromMessage, - selectSendersFromSelectedMessages, selectTabState, selectUser, } from '../../global/selectors'; @@ -119,7 +119,8 @@ const DeleteSelectedMessageModal: FC = ({ if (isChannel) { return undefined; } - return selectSendersFromSelectedMessages(getGlobal(), chat); + const senderArray = getSendersFromSelectedMessages(getGlobal(), chat); + return senderArray?.filter(Boolean); // eslint-disable-next-line react-hooks-static-deps/exhaustive-deps }, [chat, isChannel, isOpen]); diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index 71d2f804f..bc1513275 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -213,30 +213,32 @@ addActionHandler('loadViewportMessages', (global, actions, payload): ActionRetur const isOutlying = Boolean(listedIds && !listedIds.includes(offsetId)); const historyIds = (isOutlying ? selectOutlyingListByMessageId(global, chatId, threadId, offsetId) : listedIds)!; - const { - newViewportIds, areSomeLocal, areAllLocal, - } = getViewportSlice(historyIds, offsetId, direction); + if (historyIds?.length) { + const { + newViewportIds, areSomeLocal, areAllLocal, + } = getViewportSlice(historyIds, offsetId, direction); - if (areSomeLocal) { - global = safeReplaceViewportIds(global, chatId, threadId, newViewportIds, tabId); + if (areSomeLocal) { + global = safeReplaceViewportIds(global, chatId, threadId, newViewportIds, tabId); + } + + onTickEnd(() => { + void loadWithBudget( + global, + actions, + areAllLocal, + isOutlying, + isBudgetPreload, + chat, + threadId!, + direction, + offsetId, + onLoaded, + tabId, + ); + }); } - onTickEnd(() => { - void loadWithBudget( - global, - actions, - areAllLocal, - isOutlying, - isBudgetPreload, - chat, - threadId!, - direction, - offsetId, - onLoaded, - tabId, - ); - }); - if (isBudgetPreload) { return; } diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index 43a1619eb..efab30444 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -420,7 +420,7 @@ export function selectSender(global: T, message: ApiMessa return selectPeer(global, senderId); } -export function selectSendersFromSelectedMessages( +export function getSendersFromSelectedMessages( global: T, chat: ApiChat | undefined, ...[tabId = getCurrentTabId()]: TabArgs