Process expireTimer and block status along with contact/group sync (#1980)
* Mark group as left = false if it is active in contact sync * Handle expireTimer + blocked state along with contact/group sync
This commit is contained in:
parent
3f0354f09e
commit
72b7e4ec34
6 changed files with 162 additions and 54 deletions
|
@ -3,8 +3,27 @@
|
|||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
window.Whisper = window.Whisper || {};
|
||||
storage.isBlocked = function(number) {
|
||||
return storage.get('blocked', []).indexOf(number) >= 0;
|
||||
var numbers = storage.get('blocked', []);
|
||||
|
||||
return _.include(numbers, number);
|
||||
};
|
||||
storage.addBlockedNumber = function(number) {
|
||||
var numbers = storage.get('blocked', []);
|
||||
if (_.include(numbers, number)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('adding', number, 'to blocked list');
|
||||
storage.put('blocked', numbers.concat(number));
|
||||
};
|
||||
storage.removeBlockedNumber = function(number) {
|
||||
var numbers = storage.get('blocked', []);
|
||||
if (!_.include(numbers, number)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('removing', number, 'from blocked list');
|
||||
storage.put('blocked', _.without(numbers, number));
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -668,11 +668,28 @@
|
|||
}.bind(this));
|
||||
},
|
||||
|
||||
updateExpirationTimer: function(expireTimer, source, received_at) {
|
||||
if (!expireTimer) { expireTimer = null; }
|
||||
updateExpirationTimer: function(expireTimer, source, received_at, options) {
|
||||
options = options || {};
|
||||
_.defaults(options, {fromSync: false});
|
||||
|
||||
if (!expireTimer) {
|
||||
expireTimer = null;
|
||||
}
|
||||
if (this.get('expireTimer') === expireTimer
|
||||
|| (!expireTimer && !this.get('expireTimer'))) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(
|
||||
'Updating expireTimer for conversation',
|
||||
this.idForLogging(),
|
||||
'via',
|
||||
source
|
||||
);
|
||||
source = source || textsecure.storage.user.getNumber();
|
||||
var timestamp = received_at || Date.now();
|
||||
this.save({ expireTimer: expireTimer });
|
||||
|
||||
var message = this.messageCollection.add({
|
||||
conversationId : this.id,
|
||||
type : received_at ? 'incoming' : 'outgoing',
|
||||
|
@ -681,7 +698,8 @@
|
|||
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
||||
expirationTimerUpdate : {
|
||||
expireTimer : expireTimer,
|
||||
source : source
|
||||
source : source,
|
||||
fromSync : options.fromSync,
|
||||
}
|
||||
});
|
||||
if (this.isPrivate()) {
|
||||
|
@ -690,8 +708,16 @@
|
|||
if (message.isOutgoing()) {
|
||||
message.set({recipients: this.getRecipients() });
|
||||
}
|
||||
message.save();
|
||||
if (message.isOutgoing()) { // outgoing update, send it to the number/group
|
||||
|
||||
return Promise.all([
|
||||
wrapDeferred(message.save()),
|
||||
wrapDeferred(this.save({ expireTimer: expireTimer })),
|
||||
]).then(function() {
|
||||
if (message.isIncoming()) {
|
||||
return message;
|
||||
}
|
||||
|
||||
// change was made locally, send it to the number/group
|
||||
var sendFunc;
|
||||
if (this.get('type') == 'private') {
|
||||
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToNumber;
|
||||
|
@ -703,9 +729,16 @@
|
|||
if (this.get('profileSharing')) {
|
||||
profileKey = storage.get('profileKey');
|
||||
}
|
||||
message.send(sendFunc(this.get('id'), this.get('expireTimer'), message.get('sent_at'), profileKey));
|
||||
}
|
||||
return message;
|
||||
var promise = sendFunc(this.get('id'),
|
||||
this.get('expireTimer'),
|
||||
message.get('sent_at'),
|
||||
profileKey
|
||||
);
|
||||
|
||||
return message.send(promise).then(function() {
|
||||
return message;
|
||||
});
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
isSearchable: function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue