Add support for syncing blocked numbers

// FREEBIE
This commit is contained in:
lilia 2016-09-06 17:12:45 -07:00
parent 53f20640af
commit f610233ef6
7 changed files with 56 additions and 2 deletions

View file

@ -324,5 +324,9 @@
"timestampFormat_M": {
"description": "Timestamp format string for displaying month and day (but not the year) of a date within the current year, ex: use 'MMM D' for 'Aug 8', or 'D MMM' for '8 Aug'.",
"message": "MMM D"
},
"unblockToSend": {
"message": "Unblock this contact to send a message.",
"description": "Brief message shown when trying to message a blocked number"
}
}

View file

@ -479,6 +479,7 @@
<script type='text/javascript' src='js/libphonenumber-util.js'></script>
<script type='text/javascript' src='js/models/messages.js'></script>
<script type='text/javascript' src='js/models/conversations.js'></script>
<script type='text/javascript' src='js/models/blockedNumbers.js'></script>
<script type='text/javascript' src='js/chromium.js'></script>
<script type='text/javascript' src='js/expire.js'></script>

View file

@ -38100,7 +38100,10 @@ MessageReceiver.prototype.extend({
// fault, and we should handle them gracefully and tell the
// user they received an invalid message
request.respond(200, 'OK');
this.queueEnvelope(envelope);
if (!this.isBlocked(envelope.source)) {
this.queueEnvelope(envelope);
}
}.bind(this)).catch(function(e) {
request.respond(500, 'Bad encrypted websocket message');
@ -38272,6 +38275,8 @@ MessageReceiver.prototype.extend({
this.handleContacts(syncMessage.contacts);
} else if (syncMessage.groups) {
this.handleGroups(syncMessage.groups);
} else if (syncMessage.blocked) {
this.handleBlocked(syncMessage.blocked);
} else if (syncMessage.request) {
console.log('Got SyncMessage Request');
} else if (syncMessage.read) {
@ -38348,6 +38353,12 @@ MessageReceiver.prototype.extend({
});
});
},
handleBlocked: function(blocked) {
textsecure.storage.put('blocked', blocked.numbers);
},
isBlocked: function(number) {
return textsecure.storage.get('blocked', []).indexOf(number) >= 0;
},
handleAttachment: function(attachment) {
function decryptAttachment(encrypted) {
return textsecure.crypto.decryptAttachment(

View file

@ -0,0 +1,10 @@
/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
storage.isBlocked = function(number) {
return storage.get('blocked', []).indexOf(number) >= 0;
};
})();

View file

@ -10,6 +10,11 @@
return { toastMessage: i18n('expiredWarning') };
}
});
Whisper.BlockedToast = Whisper.ToastView.extend({
render_attributes: function() {
return { toastMessage: i18n('unblockToSend') };
}
});
Whisper.ConversationView = Whisper.View.extend({
className: function() {
@ -276,6 +281,12 @@
toast.render();
return;
}
if (this.model.isPrivate() && storage.isBlocked(this.model.id)) {
var toast = new Whisper.BlockedToast();
toast.$el.insertAfter(this.$el);
toast.render();
return;
}
e.preventDefault();
var input = this.$messageField;
var message = this.replace_colons(input.val()).trim();

View file

@ -70,7 +70,10 @@ MessageReceiver.prototype.extend({
// fault, and we should handle them gracefully and tell the
// user they received an invalid message
request.respond(200, 'OK');
this.queueEnvelope(envelope);
if (!this.isBlocked(envelope.source)) {
this.queueEnvelope(envelope);
}
}.bind(this)).catch(function(e) {
request.respond(500, 'Bad encrypted websocket message');
@ -242,6 +245,8 @@ MessageReceiver.prototype.extend({
this.handleContacts(syncMessage.contacts);
} else if (syncMessage.groups) {
this.handleGroups(syncMessage.groups);
} else if (syncMessage.blocked) {
this.handleBlocked(syncMessage.blocked);
} else if (syncMessage.request) {
console.log('Got SyncMessage Request');
} else if (syncMessage.read) {
@ -318,6 +323,12 @@ MessageReceiver.prototype.extend({
});
});
},
handleBlocked: function(blocked) {
textsecure.storage.put('blocked', blocked.numbers);
},
isBlocked: function(number) {
return textsecure.storage.get('blocked', []).indexOf(number) >= 0;
},
handleAttachment: function(attachment) {
function decryptAttachment(encrypted) {
return textsecure.crypto.decryptAttachment(

View file

@ -52,11 +52,16 @@ message SyncMessage {
optional AttachmentPointer blob = 1;
}
message Blocked {
repeated string numbers = 1;
}
message Request {
enum Type {
UNKNOWN = 0;
CONTACTS = 1;
GROUPS = 2;
BLOCKED = 3;
}
optional Type type = 1;
}
@ -70,6 +75,7 @@ message SyncMessage {
optional Groups groups = 3;
optional Request request = 4;
repeated Read read = 5;
optional Blocked blocked = 6;
}
message AttachmentPointer {