From 9eeb68a9a7d2ab9583feb608031032d2fe4e8ca7 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Tue, 1 Sep 2020 16:56:37 -0400 Subject: [PATCH] Blocking/Unblocking improvements for message requests --- js/background.js | 18 ++----- js/models/blockedNumbers.js | 48 +------------------ js/models/conversations.js | 29 ++++++++--- .../MessageRequestActionsConfirmation.tsx | 5 -- ts/util/lint/exceptions.json | 6 +-- 5 files changed, 33 insertions(+), 73 deletions(-) diff --git a/js/background.js b/js/background.js index 380b8dfc3d..77c7187a99 100644 --- a/js/background.js +++ b/js/background.js @@ -2101,18 +2101,10 @@ } if (typeof details.blocked !== 'undefined') { - const e164 = conversation.get('e164'); - if (details.blocked && e164) { - storage.addBlockedNumber(e164); + if (details.blocked) { + conversation.block(); } else { - storage.removeBlockedNumber(e164); - } - - const uuid = conversation.get('uuid'); - if (details.blocked && uuid) { - storage.addBlockedUuid(uuid); - } else { - storage.removeBlockedUuid(uuid); + conversation.unblock(); } } @@ -2233,9 +2225,9 @@ } if (details.blocked) { - storage.addBlockedGroup(id); + conversation.block(); } else { - storage.removeBlockedGroup(id); + conversation.unblock(); } conversation.set(updates); diff --git a/js/models/blockedNumbers.js b/js/models/blockedNumbers.js index 35ef61f22b..081f705f67 100644 --- a/js/models/blockedNumbers.js +++ b/js/models/blockedNumbers.js @@ -1,4 +1,4 @@ -/* global storage, _, ConversationController */ +/* global storage, _ */ // eslint-disable-next-line func-names (function() { @@ -53,7 +53,7 @@ } window.log.info('removing', uuid, 'from blocked list'); - storage.put(BLOCKED_NUMBERS_ID, _.without(numbers, uuid)); + storage.put(BLOCKED_UUIDS_ID, _.without(numbers, uuid)); }; storage.isGroupBlocked = groupId => { @@ -79,48 +79,4 @@ window.log.info(`removing group(${groupId} from blocked list`); storage.put(BLOCKED_GROUPS_ID, _.without(groupIds, groupId)); }; - - /** - * Optimistically adds a conversation to our local block list. - * @param {string} id - */ - storage.blockIdentifier = id => { - const conv = ConversationController.get(id); - if (conv) { - const uuid = conv.get('uuid'); - if (uuid) { - storage.addBlockedUuid(uuid); - } - const e164 = conv.get('e164'); - if (e164) { - storage.addBlockedNumber(e164); - } - const groupId = conv.get('groupId'); - if (groupId) { - storage.addBlockedGroup(groupId); - } - } - }; - - /** - * Optimistically removes a conversation from our local block list. - * @param {string} id - */ - storage.unblockIdentifier = id => { - const conv = ConversationController.get(id); - if (conv) { - const uuid = conv.get('uuid'); - if (uuid) { - storage.removeBlockedUuid(uuid); - } - const e164 = conv.get('e164'); - if (e164) { - storage.removeBlockedNumber(e164); - } - const groupId = conv.get('groupId'); - if (groupId) { - storage.removeBlockedGroup(groupId); - } - } - }; })(); diff --git a/js/models/conversations.js b/js/models/conversations.js index 2b61a4d93c..d1223d7d68 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -203,20 +203,37 @@ return false; }, - unblock() { + block() { const uuid = this.get('uuid'); if (uuid) { - return window.storage.removeBlockedUuid(uuid); + window.storage.addBlockedUuid(uuid); } const e164 = this.get('e164'); if (e164) { - return window.storage.removeBlockedNumber(e164); + window.storage.addBlockedNumber(e164); } const groupId = this.get('groupId'); if (groupId) { - return window.storage.removeBlockedGroup(groupId); + window.storage.addBlockedGroup(groupId); + } + }, + + unblock() { + const uuid = this.get('uuid'); + if (uuid) { + window.storage.removeBlockedUuid(uuid); + } + + const e164 = this.get('e164'); + if (e164) { + window.storage.removeBlockedNumber(e164); + } + + const groupId = this.get('groupId'); + if (groupId) { + window.storage.removeBlockedGroup(groupId); } return false; @@ -632,7 +649,7 @@ } } else if (response === this.messageRequestEnum.BLOCK) { // Block locally, other devices should block upon receiving the sync message - window.storage.blockIdentifier(this.get('id')); + this.block(); this.disableProfileSharing(); } else if (response === this.messageRequestEnum.DELETE) { // Delete messages locally, other devices should delete upon receiving @@ -650,7 +667,7 @@ this.disableProfileSharing(); this.updateLastMessage(); // Block locally, other devices should block upon receiving the sync message - window.storage.blockIdentifier(this.get('id')); + this.block(); // Leave group if this was a local action if (!fromSync) { this.leaveGroup(); diff --git a/ts/components/conversation/MessageRequestActionsConfirmation.tsx b/ts/components/conversation/MessageRequestActionsConfirmation.tsx index a17a3e857b..1f6df769e9 100644 --- a/ts/components/conversation/MessageRequestActionsConfirmation.tsx +++ b/ts/components/conversation/MessageRequestActionsConfirmation.tsx @@ -110,11 +110,6 @@ export const MessageRequestActionsConfirmation = ({ action: onUnblock, style: 'affirmative', }, - { - text: i18n('MessageRequests--delete'), - action: onDelete, - style: 'negative', - }, ]} > {i18n(`MessageRequests--unblock-${conversationType}-confirm-body`)} diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 8274dbac89..7b9950f546 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -207,7 +207,7 @@ "rule": "jQuery-load(", "path": "js/models/conversations.js", "line": " // but the full ConversationController.load() sequence isn't complete. So, we", - "lineNumber": 448, + "lineNumber": 465, "reasonCategory": "exampleCode", "updated": "2020-08-11T21:28:50.868Z" }, @@ -215,7 +215,7 @@ "rule": "jQuery-load(", "path": "js/models/conversations.js", "line": " // don't cache props on create, but we do later when load() calls generateProps()", - "lineNumber": 449, + "lineNumber": 466, "reasonCategory": "exampleCode", "updated": "2020-08-11T21:28:50.868Z" }, @@ -223,7 +223,7 @@ "rule": "jQuery-wrap(", "path": "js/models/conversations.js", "line": " await wrap(", - "lineNumber": 674, + "lineNumber": 691, "reasonCategory": "falseMatch", "updated": "2020-06-09T20:26:46.515Z" },