From 7de0a0ae65b1384553b51a1e0d744823b9adf026 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 30 Jul 2020 16:49:11 +0200 Subject: [PATCH 1/8] Add Subscreen for blocked Users --- .../session/LeftPaneSettingSection.tsx | 5 +++ .../session/settings/SessionSettings.tsx | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ts/components/session/LeftPaneSettingSection.tsx b/ts/components/session/LeftPaneSettingSection.tsx index 7d729e498..1cfde2986 100644 --- a/ts/components/session/LeftPaneSettingSection.tsx +++ b/ts/components/session/LeftPaneSettingSection.tsx @@ -212,6 +212,11 @@ export class LeftPaneSettingSection extends React.Component { title: window.i18n('privacySettingsTitle'), hidden: false, }, + { + id: SessionSettingCategory.Blocked, + title: window.i18n('settingsUnblockHeader'), + hidden: isSecondaryDevice, + }, { id: SessionSettingCategory.Permissions, title: window.i18n('permissionSettingsTitle'), diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 3b4076da0..ed2ece37b 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -103,6 +103,9 @@ export class SettingsView extends React.Component { if (category === SessionSettingCategory.Devices) { // special case for linked devices settings = this.getLinkedDeviceSettings(); + } else if(category === SessionSettingCategory.Blocked) { + // special case for blocked user + settings = this.getBlockedUserSettings(); } else { // Grab initial values from database on startup // ID corresponds to installGetter parameters in preload.js @@ -589,6 +592,44 @@ export class SettingsView extends React.Component { ]; } + private getBlockedUserSettings(): Array { + const results: Array = []; + const model = window.getConversations(); + + for (const currentModel of model.models) { + let displayName = currentModel.id; + + if (currentModel.attributes.profile && currentModel.attributes.profile.displayName) { + displayName = currentModel.attributes.profile.displayName + } + + if(currentModel.isBlocked()) { + results.push({ + id: currentModel.id, + title: displayName, + description: currentModel.id, + type: SessionSettingType.Button, + category: SessionSettingCategory.Blocked, + content: { + buttonColor: SessionButtonColor.Danger, + buttonText: window.i18n('unblockUser'), + }, + comparisonValue: undefined, + setFn: () => { + currentModel.unblock() + }, + hidden: false, + onClick: undefined, + confirmationDialogParams: undefined, + }); + } + } + + console.log(results); + + return results; + } + private getLinkedDeviceSettings(): Array { const { linkedPubKeys } = this.state; const { isSecondaryDevice } = this.props; From e800e5509b4c9c73858944a0f3673cc9a124a580 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 31 Jul 2020 09:23:56 +0200 Subject: [PATCH 2/8] Placeholder for no DisplayName-Contacts in blocked --- ts/components/session/settings/SessionSettings.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index ed2ece37b..625e122e2 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -597,7 +597,7 @@ export class SettingsView extends React.Component { const model = window.getConversations(); for (const currentModel of model.models) { - let displayName = currentModel.id; + let displayName = 'User (...' + currentModel.id.substr(-6) + ')'; if (currentModel.attributes.profile && currentModel.attributes.profile.displayName) { displayName = currentModel.attributes.profile.displayName @@ -625,8 +625,6 @@ export class SettingsView extends React.Component { } } - console.log(results); - return results; } From fde67235845fc60523eaf6c6a793caa685e406e5 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Wed, 5 Aug 2020 09:42:12 +0200 Subject: [PATCH 3/8] Fix Lint problem --- ts/components/session/settings/SessionSettings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 625e122e2..1330664d8 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -597,7 +597,7 @@ export class SettingsView extends React.Component { const model = window.getConversations(); for (const currentModel of model.models) { - let displayName = 'User (...' + currentModel.id.substr(-6) + ')'; + let displayName = `User (...${currentModel.id.toString().substr(-6)})`; if (currentModel.attributes.profile && currentModel.attributes.profile.displayName) { displayName = currentModel.attributes.profile.displayName From 7e0d4dfa28292b9089926fa34422cae95469fd26 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 6 Aug 2020 08:25:17 +0200 Subject: [PATCH 4/8] Update ts/components/session/LeftPaneSettingSection.tsx Co-authored-by: Audric Ackermann --- ts/components/session/LeftPaneSettingSection.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/components/session/LeftPaneSettingSection.tsx b/ts/components/session/LeftPaneSettingSection.tsx index 1cfde2986..e4b90ac3f 100644 --- a/ts/components/session/LeftPaneSettingSection.tsx +++ b/ts/components/session/LeftPaneSettingSection.tsx @@ -215,7 +215,7 @@ export class LeftPaneSettingSection extends React.Component { { id: SessionSettingCategory.Blocked, title: window.i18n('settingsUnblockHeader'), - hidden: isSecondaryDevice, + hidden: false, }, { id: SessionSettingCategory.Permissions, From 46f447ef7c8d9210b2e4ccc731117505e573a57a Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 6 Aug 2020 08:25:57 +0200 Subject: [PATCH 5/8] Update ts/components/session/settings/SessionSettings.tsx Co-authored-by: Audric Ackermann --- ts/components/session/settings/SessionSettings.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 1330664d8..0b7eeed8c 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -597,13 +597,12 @@ export class SettingsView extends React.Component { const model = window.getConversations(); for (const currentModel of model.models) { - let displayName = `User (...${currentModel.id.toString().substr(-6)})`; - - if (currentModel.attributes.profile && currentModel.attributes.profile.displayName) { - displayName = currentModel.attributes.profile.displayName - } - if(currentModel.isBlocked()) { + let displayName = `User (...${currentModel.id.toString().substr(-6)})`; + + if (currentModel.attributes.profile && currentModel.attributes.profile.displayName) { + displayName = currentModel.attributes.profile.displayName + } results.push({ id: currentModel.id, title: displayName, From b430848c5310ffb381283c5853a301246b494d4d Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 6 Aug 2020 09:08:18 +0200 Subject: [PATCH 6/8] Get only blocked SessionIDs even if conv is gone --- .../session/LeftPaneSettingSection.tsx | 2 +- .../session/settings/SessionSettings.tsx | 60 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/ts/components/session/LeftPaneSettingSection.tsx b/ts/components/session/LeftPaneSettingSection.tsx index 1cfde2986..e4b90ac3f 100644 --- a/ts/components/session/LeftPaneSettingSection.tsx +++ b/ts/components/session/LeftPaneSettingSection.tsx @@ -215,7 +215,7 @@ export class LeftPaneSettingSection extends React.Component { { id: SessionSettingCategory.Blocked, title: window.i18n('settingsUnblockHeader'), - hidden: isSecondaryDevice, + hidden: false, }, { id: SessionSettingCategory.Permissions, diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 1330664d8..83d332d19 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -7,7 +7,7 @@ import { SessionButtonColor, SessionButtonType, } from '../SessionButton'; -import { UserUtil } from '../../../util'; +import { UserUtil, BlockedNumberController } from '../../../util'; import { MultiDeviceProtocol } from '../../../session/protocols'; import { PubKey } from '../../../session/types'; import { NumberUtils } from '../../../session/utils'; @@ -594,37 +594,41 @@ export class SettingsView extends React.Component { private getBlockedUserSettings(): Array { const results: Array = []; - const model = window.getConversations(); - - for (const currentModel of model.models) { - let displayName = `User (...${currentModel.id.toString().substr(-6)})`; - - if (currentModel.attributes.profile && currentModel.attributes.profile.displayName) { + const blockedNumbers = BlockedNumberController.getBlockedNumbers(); + + for (const blockedNumber of blockedNumbers) { + + let displayName = `User (...${blockedNumber.substr(-6)})`; + + let currentModel = window.ConversationController.get(blockedNumber); + if ( + currentModel && + currentModel.attributes.profile && + currentModel.attributes.profile.displayName + ) { displayName = currentModel.attributes.profile.displayName } - if(currentModel.isBlocked()) { - results.push({ - id: currentModel.id, - title: displayName, - description: currentModel.id, - type: SessionSettingType.Button, - category: SessionSettingCategory.Blocked, - content: { - buttonColor: SessionButtonColor.Danger, - buttonText: window.i18n('unblockUser'), - }, - comparisonValue: undefined, - setFn: () => { - currentModel.unblock() - }, - hidden: false, - onClick: undefined, - confirmationDialogParams: undefined, - }); - } - } + results.push({ + id: blockedNumber, + title: displayName, + description: blockedNumber, + type: SessionSettingType.Button, + category: SessionSettingCategory.Blocked, + content: { + buttonColor: SessionButtonColor.Danger, + buttonText: window.i18n('unblockUser'), + }, + comparisonValue: undefined, + setFn: () => { + BlockedNumberController.unblock(blockedNumber) + }, + hidden: false, + onClick: undefined, + confirmationDialogParams: undefined, + }); + } return results; } From 7ec263f27356ef9f9d117a395e4aa78e312828fd Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 6 Aug 2020 09:35:01 +0200 Subject: [PATCH 7/8] fixed transaltion key --- _locales/en/messages.json | 2 +- ts/components/session/LeftPaneSettingSection.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e47117dd9..dd513a86d 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1910,7 +1910,7 @@ "unblockUser": { "message": "Unblock User" }, - "settingsUnblockHeader": { + "blockedSettingsTitle": { "message": "Blocked Users", "description": "Shown in the settings page as the heading for the blocked user settings" }, diff --git a/ts/components/session/LeftPaneSettingSection.tsx b/ts/components/session/LeftPaneSettingSection.tsx index e4b90ac3f..6bc707951 100644 --- a/ts/components/session/LeftPaneSettingSection.tsx +++ b/ts/components/session/LeftPaneSettingSection.tsx @@ -214,7 +214,7 @@ export class LeftPaneSettingSection extends React.Component { }, { id: SessionSettingCategory.Blocked, - title: window.i18n('settingsUnblockHeader'), + title: window.i18n('blockedSettingsTitle'), hidden: false, }, { From 380d533da8c087ab28fe56cd9a8c34b856776739 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 6 Aug 2020 10:30:22 +0200 Subject: [PATCH 8/8] fix lint --- ts/components/session/settings/SessionSettings.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 83d332d19..9a665a8c6 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -7,7 +7,7 @@ import { SessionButtonColor, SessionButtonType, } from '../SessionButton'; -import { UserUtil, BlockedNumberController } from '../../../util'; +import { BlockedNumberController, UserUtil } from '../../../util'; import { MultiDeviceProtocol } from '../../../session/protocols'; import { PubKey } from '../../../session/types'; import { NumberUtils } from '../../../session/utils'; @@ -600,7 +600,7 @@ export class SettingsView extends React.Component { let displayName = `User (...${blockedNumber.substr(-6)})`; - let currentModel = window.ConversationController.get(blockedNumber); + const currentModel = window.ConversationController.get(blockedNumber); if ( currentModel && currentModel.attributes.profile && @@ -609,7 +609,6 @@ export class SettingsView extends React.Component { displayName = currentModel.attributes.profile.displayName } - results.push({ id: blockedNumber, title: displayName, @@ -621,8 +620,8 @@ export class SettingsView extends React.Component { buttonText: window.i18n('unblockUser'), }, comparisonValue: undefined, - setFn: () => { - BlockedNumberController.unblock(blockedNumber) + setFn: async () => { + await BlockedNumberController.unblock(blockedNumber) }, hidden: false, onClick: undefined,