Support for blocking groups on mobile, via group/blocked syncs

This commit is contained in:
Scott Nonnenberg 2018-09-13 12:57:07 -07:00
parent cfe561b3eb
commit 9c399624cc
8 changed files with 89 additions and 15 deletions

View file

@ -727,6 +727,16 @@ MessageReceiver.prototype.extend({
}
return p.then(() =>
this.processDecrypted(envelope, msg, this.number).then(message => {
const groupId = message.group && message.group.id;
if (groupId && this.isGroupBlocked(groupId)) {
window.log.warn(
`Message ${this.getEnvelopeId(
envelope
)} ignored; destined for blocked group`
);
return this.removeFromCache(envelope);
}
const ev = new Event('sent');
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = {
@ -751,6 +761,16 @@ MessageReceiver.prototype.extend({
}
return p.then(() =>
this.processDecrypted(envelope, msg, envelope.source).then(message => {
const groupId = message.group && message.group.id;
if (groupId && this.isGroupBlocked(groupId)) {
window.log.warn(
`Message ${this.getEnvelopeId(
envelope
)} ignored; destined for blocked group`
);
return this.removeFromCache(envelope);
}
const ev = new Event('message');
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = {
@ -991,10 +1011,22 @@ MessageReceiver.prototype.extend({
handleBlocked(envelope, blocked) {
window.log.info('Setting these numbers as blocked:', blocked.numbers);
textsecure.storage.put('blocked', blocked.numbers);
const groupIds = _.map(blocked.groupIds, groupId => groupId.toBinary());
window.log.info(
'Setting these groups as blocked:',
groupIds.map(groupId => `group(${groupId})`)
);
textsecure.storage.put('blocked-groups', groupIds);
return this.removeFromCache(envelope);
},
isBlocked(number) {
return textsecure.storage.get('blocked', []).indexOf(number) >= 0;
},
isGroupBlocked(groupId) {
return textsecure.storage.get('blocked-groups', []).indexOf(groupId) >= 0;
},
handleAttachment(attachment) {
// eslint-disable-next-line no-param-reassign
attachment.id = attachment.id.toString();