Merge timer update functions
This commit is contained in:
parent
f2bdafc7e9
commit
05ed7c3822
3 changed files with 19 additions and 19 deletions
|
@ -194,14 +194,15 @@
|
|||
}
|
||||
},
|
||||
|
||||
addExpirationTimerUpdate: function(expireTimer, source, received_at) {
|
||||
received_at = received_at || Date.now();
|
||||
updateExpirationTimer: function(expireTimer, source, received_at) {
|
||||
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 : 'outgoing',
|
||||
sent_at : received_at,
|
||||
received_at : received_at,
|
||||
sent_at : timestamp,
|
||||
received_at : timestamp,
|
||||
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
||||
expirationTimerUpdate : {
|
||||
expireTimer : expireTimer,
|
||||
|
@ -212,19 +213,18 @@
|
|||
message.set({destination: this.id});
|
||||
}
|
||||
message.save();
|
||||
if (!received_at) { // outgoing update, send it to the number/group
|
||||
var sendFunc;
|
||||
if (this.get('type') == 'private') {
|
||||
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToNumber;
|
||||
}
|
||||
else {
|
||||
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToGroup;
|
||||
}
|
||||
message.send(sendFunc(this.get('id'), this.get('expireTimer'), message.get('sent_at')));
|
||||
}
|
||||
return message;
|
||||
},
|
||||
sendExpirationTimerUpdate: function(time) {
|
||||
var message = this.addExpirationTimerUpdate(time, textsecure.storage.user.getNumber());
|
||||
var sendFunc;
|
||||
if (this.get('type') == 'private') {
|
||||
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToNumber;
|
||||
}
|
||||
else {
|
||||
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToGroup;
|
||||
}
|
||||
message.send(sendFunc(this.get('id'), this.get('expireTimer'), message.get('sent_at')));
|
||||
},
|
||||
|
||||
isSearchable: function() {
|
||||
return !this.get('left') || !!this.get('lastMessage');
|
||||
|
|
|
@ -398,12 +398,12 @@
|
|||
if (!message.isEndSession()) {
|
||||
if (dataMessage.expireTimer) {
|
||||
if (dataMessage.expireTimer !== conversation.get('expireTimer')) {
|
||||
conversation.addExpirationTimerUpdate(
|
||||
conversation.updateExpirationTimer(
|
||||
dataMessage.expireTimer, source,
|
||||
message.get('received_at'));
|
||||
}
|
||||
} else if (conversation.get('expireTimer')) {
|
||||
conversation.addExpirationTimerUpdate(0, source,
|
||||
conversation.updateExpirationTimer(0, source,
|
||||
message.get('received_at'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
setTimer: function(e) {
|
||||
var seconds = this.$(e.target).data().seconds;
|
||||
if (seconds >= 0) {
|
||||
this.model.sendExpirationTimerUpdate(seconds);
|
||||
this.model.updateExpirationTimer(seconds);
|
||||
}
|
||||
},
|
||||
render: function() {
|
||||
|
@ -154,7 +154,7 @@
|
|||
},
|
||||
enableDisappearingMessages: function() {
|
||||
if (!this.model.get('expireTimer')) {
|
||||
this.model.sendExpirationTimerUpdate(
|
||||
this.model.updateExpirationTimer(
|
||||
moment.duration(1, 'day').asSeconds()
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue