Apply expireTimer to outgoing messages

This commit is contained in:
lilia 2016-09-28 16:54:05 -07:00
parent 2b2c6ab040
commit 824b7417e9
3 changed files with 33 additions and 8 deletions

View file

@ -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

View file

@ -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));
},

View file

@ -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