Blocking/Unblocking improvements for message requests

This commit is contained in:
Josh Perez 2020-09-01 16:56:37 -04:00 committed by Josh Perez
parent 91ea69133b
commit 9eeb68a9a7
5 changed files with 33 additions and 73 deletions

View file

@ -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);
}
}
};
})();

View file

@ -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();