From 726418887cb0b0537f49b2cdc1a42a6d1531be0d Mon Sep 17 00:00:00 2001 From: warrickct Date: Wed, 24 Nov 2021 09:32:07 +1100 Subject: [PATCH] Addressing PR comments --- ts/components/ConversationListItem.tsx | 8 ++- .../session/LeftPaneMessageSection.tsx | 50 +++++++++++-------- ts/receiver/configMessage.ts | 14 +++++- .../conversations/ConversationController.ts | 6 --- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 4cd52f7e8..9725cc20b 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -377,15 +377,13 @@ const ConversationListItem = (props: Props) => { - Block - + text={window.i18n('blockUser')} + /> + /> ) : null} diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index c12ea5843..2632409fd 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -221,6 +221,33 @@ export class LeftPaneMessageSection extends React.Component { this.handleToggleOverlay(SessionClosableOverlayType.MessageRequests); } + /** + * Blocks all message request conversations and synchronizes across linked devices + * @returns void + */ + private async handleBlockAllRequestsClick() { + // block all convo requests. Force sync if there were changes. + window?.log?.info('Blocking all conversations'); + const { conversationRequests } = this.props; + let syncRequired = false; + + if (!conversationRequests) { + window?.log?.info('No conversation requests to block.'); + return; + } + + await Promise.all( + conversationRequests.map(async convo => { + await BlockedNumberController.block(convo.id); + syncRequired = true; + }) + ); + + if (syncRequired) { + await forceSyncConfigurationNowIfNeeded(); + } + } + private renderClosableOverlay() { const { searchTerm, searchResults } = this.props; const { loading, overlay } = this.state; @@ -278,28 +305,7 @@ export class LeftPaneMessageSection extends React.Component { onCloseClick={() => { this.handleToggleOverlay(undefined); }} - onButtonClick={async () => { - // block all convo requests. Force sync if there were changes. - window?.log?.info('Blocking all conversations'); - const { conversationRequests } = this.props; - let syncRequired = false; - - if (!conversationRequests) { - window?.log?.info('No conversation requests to block.'); - return; - } - - await Promise.all( - conversationRequests.map(async convo => { - await BlockedNumberController.block(convo.id); - syncRequired = true; - }) - ); - - if (syncRequired) { - await forceSyncConfigurationNowIfNeeded(); - } - }} + onButtonClick={this.handleBlockAllRequestsClick} searchTerm={searchTerm} searchResults={searchResults} showSpinner={loading} diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index 86a0de634..362355306 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { createOrUpdateItem } from '../data/data'; +import { createOrUpdateItem, getItemById, hasSyncedInitialConfigurationItem } from '../data/data'; import { ConversationTypeEnum } from '../models/conversation'; import { joinOpenGroupV2WithUIEvents, @@ -59,6 +59,18 @@ async function handleGroupsAndContactsFromConfigMessage( value: true, }); + const didWeHandleAConfigurationMessageAlready = + (await getItemById(hasSyncedInitialConfigurationItem))?.value || false; + if (didWeHandleAConfigurationMessageAlready) { + window?.log?.info( + 'Dropping configuration groups change as we already handled one... Only handling contacts ' + ); + if (configMessage.contacts?.length) { + await Promise.all(configMessage.contacts.map(async c => handleContactReceived(c, envelope))); + } + return; + } + const numberClosedGroup = configMessage.closedGroups?.length || 0; window?.log?.info( diff --git a/ts/session/conversations/ConversationController.ts b/ts/session/conversations/ConversationController.ts index 629851540..0bb29e58c 100644 --- a/ts/session/conversations/ConversationController.ts +++ b/ts/session/conversations/ConversationController.ts @@ -266,12 +266,6 @@ export class ConversationController { return Array.from(this.conversations.models); } - public getConversationRequests(): Array { - return Array.from(this.conversations.models).filter( - conversation => conversation.isApproved() && !conversation.isBlocked - ); - } - public unsafeDelete(convo: ConversationModel) { this.conversations.remove(convo); }