From 18a739b05b501a3505ac7b0893c4ea3df4d32b0f Mon Sep 17 00:00:00 2001 From: warrickct Date: Tue, 22 Feb 2022 11:41:29 +1100 Subject: [PATCH] update local UI for blocking all conversations. Removing some unused vars --- .../composition/CompositionBox.tsx | 9 +---- .../overlay/OverlayMessageRequest.tsx | 38 +++++++++---------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/ts/components/conversation/composition/CompositionBox.tsx b/ts/components/conversation/composition/CompositionBox.tsx index 76ce49ea6..70f09a1fa 100644 --- a/ts/components/conversation/composition/CompositionBox.tsx +++ b/ts/components/conversation/composition/CompositionBox.tsx @@ -420,14 +420,7 @@ class CompositionBoxInner extends React.Component { return i18n('sendMessage'); }; - const { - isKickedFromGroup, - left, - isPrivate, - isBlocked, - didApproveMe, - isApproved, - } = this.props.selectedConversation; + const { isKickedFromGroup, left, isPrivate, isBlocked } = this.props.selectedConversation; const messagePlaceHolder = makeMessagePlaceHolderText(); const { typingEnabled } = this.props; const neverMatchingRegex = /($a)/; diff --git a/ts/components/leftpane/overlay/OverlayMessageRequest.tsx b/ts/components/leftpane/overlay/OverlayMessageRequest.tsx index b1a635d7c..a98705737 100644 --- a/ts/components/leftpane/overlay/OverlayMessageRequest.tsx +++ b/ts/components/leftpane/overlay/OverlayMessageRequest.tsx @@ -12,36 +12,31 @@ import { getConversationController } from '../../../session/conversations'; import { forceSyncConfigurationNowIfNeeded } from '../../../session/utils/syncUtils'; import { BlockedNumberController } from '../../../util'; import useKey from 'react-use/lib/useKey'; +import { ReduxConversationType } from '../../../state/ducks/conversations'; /** * Blocks all message request conversations and synchronizes across linked devices * @returns void */ -async function handleBlockAllRequestsClick() { - // block all convo requests. Force sync if there were changes. +async function handleBlockAllRequestsClick(convoRequests: Array) { window?.log?.info('Blocking all conversations'); - const conversations = getConversationController().getConversations(); - - if (!conversations) { - window?.log?.info('No message requests to block.'); - return; - } - - const convoRequestsToBlock = conversations.filter( - c => c.isPrivate() && c.get('active_at') && c.get('isApproved') - ); - - let syncRequired = false; - - if (!convoRequestsToBlock) { + if (!convoRequests) { window?.log?.info('No conversation requests to block.'); return; } + let syncRequired = false; + const convoController = getConversationController(); await Promise.all( - convoRequestsToBlock.map(async convo => { - await BlockedNumberController.block(convo.id); - await convo.setIsApproved(false); + convoRequests.map(async convo => { + const { id } = convo; + const convoModel = convoController.get(id); + if (!convoModel.isBlocked()) { + await BlockedNumberController.block(id); + convoModel.commit(); + } + await convoModel.setIsApproved(false); + syncRequired = true; }) ); @@ -58,6 +53,7 @@ export const OverlayMessageRequest = () => { dispatch(setOverlayMode(undefined)); } const hasRequests = useSelector(getConversationRequests).length > 0; + const messageRequests = useSelector(getConversationRequests); const buttonText = window.i18n('clearAll'); @@ -71,8 +67,8 @@ export const OverlayMessageRequest = () => { buttonColor={SessionButtonColor.Danger} buttonType={SessionButtonType.BrandOutline} text={buttonText} - onClick={() => { - void handleBlockAllRequestsClick(); + onClick={async () => { + await handleBlockAllRequestsClick(messageRequests); }} />