diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 7b9410ff..e1d44a8d 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38815,6 +38815,7 @@ function Message(options) { this.recipients = options.recipients; this.timestamp = options.timestamp; this.needsSync = options.needsSync; + this.expireTimer = options.expireTimer; if (!(this.recipients instanceof Array) || this.recipients.length < 1) { throw new Error('Invalid recipient list'); @@ -38828,6 +38829,12 @@ function Message(options) { throw new Error('Invalid timestamp'); } + if (this.expireTimer !== undefined) { + if (typeof this.expireTimer !== 'number' || !(this.expireTimer >= 0)) { + throw new Error('Invalid expireTimer'); + } + } + if (this.attachments) { if (!(this.attachments instanceof Array)) { throw new Error('Invalid message attachments'); @@ -38876,6 +38883,9 @@ Message.prototype = { proto.group.id = stringToArrayBuffer(this.group.id); proto.group.type = this.group.type } + if (this.expireTimer) { + proto.expireTimer = this.expireTimer; + } this.dataMessage = proto; return proto; @@ -39072,13 +39082,14 @@ MessageSender.prototype = { }.bind(this)); }, - sendMessageToNumber: function(number, messageText, attachments, timestamp) { + sendMessageToNumber: function(number, messageText, attachments, timestamp, expireTimer) { return this.sendMessage({ recipients : [number], body : messageText, timestamp : timestamp, attachments : attachments, - needsSync : true + needsSync : true, + expireTimer : expireTimer }); }, @@ -39101,7 +39112,7 @@ MessageSender.prototype = { }); }, - sendMessageToGroup: function(groupId, messageText, attachments, timestamp) { + sendMessageToGroup: function(groupId, messageText, attachments, timestamp, expireTimer) { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) return Promise.reject(new Error("Unknown Group")); @@ -39118,6 +39129,7 @@ MessageSender.prototype = { timestamp : timestamp, attachments : attachments, needsSync : true, + expireTimer : expireTimer, group: { id: groupId, type: textsecure.protobuf.GroupContext.Type.DELIVER diff --git a/js/models/conversations.js b/js/models/conversations.js index 49f8c6be..8d9c999c 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -141,7 +141,8 @@ type : 'outgoing', attachments : attachments, sent_at : now, - received_at : now + received_at : now, + expireTimer : this.get('expireTimer') }); if (this.isPrivate()) { message.set({destination: this.id}); @@ -162,7 +163,7 @@ else { sendFunc = textsecure.messaging.sendMessageToGroup; } - message.send(sendFunc(this.get('id'), body, attachments, now)); + message.send(sendFunc(this.get('id'), body, attachments, now, this.get('expireTimer'))); }.bind(this)); }, diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 33f6cac5..eed65cfe 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -22,6 +22,7 @@ function Message(options) { this.recipients = options.recipients; this.timestamp = options.timestamp; this.needsSync = options.needsSync; + this.expireTimer = options.expireTimer; if (!(this.recipients instanceof Array) || this.recipients.length < 1) { throw new Error('Invalid recipient list'); @@ -35,6 +36,12 @@ function Message(options) { throw new Error('Invalid timestamp'); } + if (this.expireTimer !== undefined) { + if (typeof this.expireTimer !== 'number' || !(this.expireTimer >= 0)) { + throw new Error('Invalid expireTimer'); + } + } + if (this.attachments) { if (!(this.attachments instanceof Array)) { throw new Error('Invalid message attachments'); @@ -83,6 +90,9 @@ Message.prototype = { proto.group.id = stringToArrayBuffer(this.group.id); proto.group.type = this.group.type } + if (this.expireTimer) { + proto.expireTimer = this.expireTimer; + } this.dataMessage = proto; return proto; @@ -279,13 +289,14 @@ MessageSender.prototype = { }.bind(this)); }, - sendMessageToNumber: function(number, messageText, attachments, timestamp) { + sendMessageToNumber: function(number, messageText, attachments, timestamp, expireTimer) { return this.sendMessage({ recipients : [number], body : messageText, timestamp : timestamp, attachments : attachments, - needsSync : true + needsSync : true, + expireTimer : expireTimer }); }, @@ -308,7 +319,7 @@ MessageSender.prototype = { }); }, - sendMessageToGroup: function(groupId, messageText, attachments, timestamp) { + sendMessageToGroup: function(groupId, messageText, attachments, timestamp, expireTimer) { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) return Promise.reject(new Error("Unknown Group")); @@ -325,6 +336,7 @@ MessageSender.prototype = { timestamp : timestamp, attachments : attachments, needsSync : true, + expireTimer : expireTimer, group: { id: groupId, type: textsecure.protobuf.GroupContext.Type.DELIVER