Add support for syncing blocked numbers
// FREEBIE
This commit is contained in:
@@ -324,5 +324,9 @@
|
|||||||
"timestampFormat_M": {
|
"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'.",
|
"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"
|
"message": "MMM D"
|
||||||
|
},
|
||||||
|
"unblockToSend": {
|
||||||
|
"message": "Unblock this contact to send a message.",
|
||||||
|
"description": "Brief message shown when trying to message a blocked number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -479,6 +479,7 @@
|
|||||||
<script type='text/javascript' src='js/libphonenumber-util.js'></script>
|
<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/messages.js'></script>
|
||||||
<script type='text/javascript' src='js/models/conversations.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/chromium.js'></script>
|
||||||
<script type='text/javascript' src='js/expire.js'></script>
|
<script type='text/javascript' src='js/expire.js'></script>
|
||||||
|
@@ -38100,7 +38100,10 @@ MessageReceiver.prototype.extend({
|
|||||||
// fault, and we should handle them gracefully and tell the
|
// fault, and we should handle them gracefully and tell the
|
||||||
// user they received an invalid message
|
// user they received an invalid message
|
||||||
request.respond(200, 'OK');
|
request.respond(200, 'OK');
|
||||||
this.queueEnvelope(envelope);
|
|
||||||
|
if (!this.isBlocked(envelope.source)) {
|
||||||
|
this.queueEnvelope(envelope);
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)).catch(function(e) {
|
}.bind(this)).catch(function(e) {
|
||||||
request.respond(500, 'Bad encrypted websocket message');
|
request.respond(500, 'Bad encrypted websocket message');
|
||||||
@@ -38272,6 +38275,8 @@ MessageReceiver.prototype.extend({
|
|||||||
this.handleContacts(syncMessage.contacts);
|
this.handleContacts(syncMessage.contacts);
|
||||||
} else if (syncMessage.groups) {
|
} else if (syncMessage.groups) {
|
||||||
this.handleGroups(syncMessage.groups);
|
this.handleGroups(syncMessage.groups);
|
||||||
|
} else if (syncMessage.blocked) {
|
||||||
|
this.handleBlocked(syncMessage.blocked);
|
||||||
} else if (syncMessage.request) {
|
} else if (syncMessage.request) {
|
||||||
console.log('Got SyncMessage Request');
|
console.log('Got SyncMessage Request');
|
||||||
} else if (syncMessage.read) {
|
} 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) {
|
handleAttachment: function(attachment) {
|
||||||
function decryptAttachment(encrypted) {
|
function decryptAttachment(encrypted) {
|
||||||
return textsecure.crypto.decryptAttachment(
|
return textsecure.crypto.decryptAttachment(
|
||||||
|
10
js/models/blockedNumbers.js
Normal file
10
js/models/blockedNumbers.js
Normal 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;
|
||||||
|
};
|
||||||
|
})();
|
@@ -10,6 +10,11 @@
|
|||||||
return { toastMessage: i18n('expiredWarning') };
|
return { toastMessage: i18n('expiredWarning') };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Whisper.BlockedToast = Whisper.ToastView.extend({
|
||||||
|
render_attributes: function() {
|
||||||
|
return { toastMessage: i18n('unblockToSend') };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Whisper.ConversationView = Whisper.View.extend({
|
Whisper.ConversationView = Whisper.View.extend({
|
||||||
className: function() {
|
className: function() {
|
||||||
@@ -276,6 +281,12 @@
|
|||||||
toast.render();
|
toast.render();
|
||||||
return;
|
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();
|
e.preventDefault();
|
||||||
var input = this.$messageField;
|
var input = this.$messageField;
|
||||||
var message = this.replace_colons(input.val()).trim();
|
var message = this.replace_colons(input.val()).trim();
|
||||||
|
@@ -70,7 +70,10 @@ MessageReceiver.prototype.extend({
|
|||||||
// fault, and we should handle them gracefully and tell the
|
// fault, and we should handle them gracefully and tell the
|
||||||
// user they received an invalid message
|
// user they received an invalid message
|
||||||
request.respond(200, 'OK');
|
request.respond(200, 'OK');
|
||||||
this.queueEnvelope(envelope);
|
|
||||||
|
if (!this.isBlocked(envelope.source)) {
|
||||||
|
this.queueEnvelope(envelope);
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)).catch(function(e) {
|
}.bind(this)).catch(function(e) {
|
||||||
request.respond(500, 'Bad encrypted websocket message');
|
request.respond(500, 'Bad encrypted websocket message');
|
||||||
@@ -242,6 +245,8 @@ MessageReceiver.prototype.extend({
|
|||||||
this.handleContacts(syncMessage.contacts);
|
this.handleContacts(syncMessage.contacts);
|
||||||
} else if (syncMessage.groups) {
|
} else if (syncMessage.groups) {
|
||||||
this.handleGroups(syncMessage.groups);
|
this.handleGroups(syncMessage.groups);
|
||||||
|
} else if (syncMessage.blocked) {
|
||||||
|
this.handleBlocked(syncMessage.blocked);
|
||||||
} else if (syncMessage.request) {
|
} else if (syncMessage.request) {
|
||||||
console.log('Got SyncMessage Request');
|
console.log('Got SyncMessage Request');
|
||||||
} else if (syncMessage.read) {
|
} 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) {
|
handleAttachment: function(attachment) {
|
||||||
function decryptAttachment(encrypted) {
|
function decryptAttachment(encrypted) {
|
||||||
return textsecure.crypto.decryptAttachment(
|
return textsecure.crypto.decryptAttachment(
|
||||||
|
@@ -52,11 +52,16 @@ message SyncMessage {
|
|||||||
optional AttachmentPointer blob = 1;
|
optional AttachmentPointer blob = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message Blocked {
|
||||||
|
repeated string numbers = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message Request {
|
message Request {
|
||||||
enum Type {
|
enum Type {
|
||||||
UNKNOWN = 0;
|
UNKNOWN = 0;
|
||||||
CONTACTS = 1;
|
CONTACTS = 1;
|
||||||
GROUPS = 2;
|
GROUPS = 2;
|
||||||
|
BLOCKED = 3;
|
||||||
}
|
}
|
||||||
optional Type type = 1;
|
optional Type type = 1;
|
||||||
}
|
}
|
||||||
@@ -70,6 +75,7 @@ message SyncMessage {
|
|||||||
optional Groups groups = 3;
|
optional Groups groups = 3;
|
||||||
optional Request request = 4;
|
optional Request request = 4;
|
||||||
repeated Read read = 5;
|
repeated Read read = 5;
|
||||||
|
optional Blocked blocked = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AttachmentPointer {
|
message AttachmentPointer {
|
||||||
|
Reference in New Issue
Block a user