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) {
|
updateExpirationTimer: function(expireTimer, source, received_at) {
|
||||||
received_at = received_at || Date.now();
|
source = source || textsecure.storage.user.getNumber();
|
||||||
|
var timestamp = received_at || Date.now();
|
||||||
this.save({ expireTimer: expireTimer });
|
this.save({ expireTimer: expireTimer });
|
||||||
var message = this.messageCollection.add({
|
var message = this.messageCollection.add({
|
||||||
conversationId : this.id,
|
conversationId : this.id,
|
||||||
type : 'outgoing',
|
type : 'outgoing',
|
||||||
sent_at : received_at,
|
sent_at : timestamp,
|
||||||
received_at : received_at,
|
received_at : timestamp,
|
||||||
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
flags : textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
||||||
expirationTimerUpdate : {
|
expirationTimerUpdate : {
|
||||||
expireTimer : expireTimer,
|
expireTimer : expireTimer,
|
||||||
|
@ -212,19 +213,18 @@
|
||||||
message.set({destination: this.id});
|
message.set({destination: this.id});
|
||||||
}
|
}
|
||||||
message.save();
|
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;
|
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() {
|
isSearchable: function() {
|
||||||
return !this.get('left') || !!this.get('lastMessage');
|
return !this.get('left') || !!this.get('lastMessage');
|
||||||
|
|
|
@ -398,12 +398,12 @@
|
||||||
if (!message.isEndSession()) {
|
if (!message.isEndSession()) {
|
||||||
if (dataMessage.expireTimer) {
|
if (dataMessage.expireTimer) {
|
||||||
if (dataMessage.expireTimer !== conversation.get('expireTimer')) {
|
if (dataMessage.expireTimer !== conversation.get('expireTimer')) {
|
||||||
conversation.addExpirationTimerUpdate(
|
conversation.updateExpirationTimer(
|
||||||
dataMessage.expireTimer, source,
|
dataMessage.expireTimer, source,
|
||||||
message.get('received_at'));
|
message.get('received_at'));
|
||||||
}
|
}
|
||||||
} else if (conversation.get('expireTimer')) {
|
} else if (conversation.get('expireTimer')) {
|
||||||
conversation.addExpirationTimerUpdate(0, source,
|
conversation.updateExpirationTimer(0, source,
|
||||||
message.get('received_at'));
|
message.get('received_at'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
setTimer: function(e) {
|
setTimer: function(e) {
|
||||||
var seconds = this.$(e.target).data().seconds;
|
var seconds = this.$(e.target).data().seconds;
|
||||||
if (seconds >= 0) {
|
if (seconds >= 0) {
|
||||||
this.model.sendExpirationTimerUpdate(seconds);
|
this.model.updateExpirationTimer(seconds);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
@ -154,7 +154,7 @@
|
||||||
},
|
},
|
||||||
enableDisappearingMessages: function() {
|
enableDisappearingMessages: function() {
|
||||||
if (!this.model.get('expireTimer')) {
|
if (!this.model.get('expireTimer')) {
|
||||||
this.model.sendExpirationTimerUpdate(
|
this.model.updateExpirationTimer(
|
||||||
moment.duration(1, 'day').asSeconds()
|
moment.duration(1, 'day').asSeconds()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue