diff --git a/js/models/conversations.js b/js/models/conversations.js index aa7c5472..89b2f9f6 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -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'); diff --git a/js/models/messages.js b/js/models/messages.js index 6abdbf5e..ac3c3564 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -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')); } } diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 65825b0e..0f7be381 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -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() ); }