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.recipients = options.recipients;
this.timestamp = options.timestamp; this.timestamp = options.timestamp;
this.needsSync = options.needsSync; this.needsSync = options.needsSync;
this.expireTimer = options.expireTimer;
if (!(this.recipients instanceof Array) || this.recipients.length < 1) { if (!(this.recipients instanceof Array) || this.recipients.length < 1) {
throw new Error('Invalid recipient list'); throw new Error('Invalid recipient list');
@@ -38828,6 +38829,12 @@ function Message(options) {
throw new Error('Invalid timestamp'); 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) {
if (!(this.attachments instanceof Array)) { if (!(this.attachments instanceof Array)) {
throw new Error('Invalid message attachments'); throw new Error('Invalid message attachments');
@@ -38876,6 +38883,9 @@ Message.prototype = {
proto.group.id = stringToArrayBuffer(this.group.id); proto.group.id = stringToArrayBuffer(this.group.id);
proto.group.type = this.group.type proto.group.type = this.group.type
} }
if (this.expireTimer) {
proto.expireTimer = this.expireTimer;
}
this.dataMessage = proto; this.dataMessage = proto;
return proto; return proto;
@@ -39072,13 +39082,14 @@ MessageSender.prototype = {
}.bind(this)); }.bind(this));
}, },
sendMessageToNumber: function(number, messageText, attachments, timestamp) { sendMessageToNumber: function(number, messageText, attachments, timestamp, expireTimer) {
return this.sendMessage({ return this.sendMessage({
recipients : [number], recipients : [number],
body : messageText, body : messageText,
timestamp : timestamp, timestamp : timestamp,
attachments : attachments, 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) { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
if (numbers === undefined) if (numbers === undefined)
return Promise.reject(new Error("Unknown Group")); return Promise.reject(new Error("Unknown Group"));
@@ -39118,6 +39129,7 @@ MessageSender.prototype = {
timestamp : timestamp, timestamp : timestamp,
attachments : attachments, attachments : attachments,
needsSync : true, needsSync : true,
expireTimer : expireTimer,
group: { group: {
id: groupId, id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER type: textsecure.protobuf.GroupContext.Type.DELIVER

View File

@@ -141,7 +141,8 @@
type : 'outgoing', type : 'outgoing',
attachments : attachments, attachments : attachments,
sent_at : now, sent_at : now,
received_at : now received_at : now,
expireTimer : this.get('expireTimer')
}); });
if (this.isPrivate()) { if (this.isPrivate()) {
message.set({destination: this.id}); message.set({destination: this.id});
@@ -162,7 +163,7 @@
else { else {
sendFunc = textsecure.messaging.sendMessageToGroup; 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)); }.bind(this));
}, },

View File

@@ -22,6 +22,7 @@ function Message(options) {
this.recipients = options.recipients; this.recipients = options.recipients;
this.timestamp = options.timestamp; this.timestamp = options.timestamp;
this.needsSync = options.needsSync; this.needsSync = options.needsSync;
this.expireTimer = options.expireTimer;
if (!(this.recipients instanceof Array) || this.recipients.length < 1) { if (!(this.recipients instanceof Array) || this.recipients.length < 1) {
throw new Error('Invalid recipient list'); throw new Error('Invalid recipient list');
@@ -35,6 +36,12 @@ function Message(options) {
throw new Error('Invalid timestamp'); 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) {
if (!(this.attachments instanceof Array)) { if (!(this.attachments instanceof Array)) {
throw new Error('Invalid message attachments'); throw new Error('Invalid message attachments');
@@ -83,6 +90,9 @@ Message.prototype = {
proto.group.id = stringToArrayBuffer(this.group.id); proto.group.id = stringToArrayBuffer(this.group.id);
proto.group.type = this.group.type proto.group.type = this.group.type
} }
if (this.expireTimer) {
proto.expireTimer = this.expireTimer;
}
this.dataMessage = proto; this.dataMessage = proto;
return proto; return proto;
@@ -279,13 +289,14 @@ MessageSender.prototype = {
}.bind(this)); }.bind(this));
}, },
sendMessageToNumber: function(number, messageText, attachments, timestamp) { sendMessageToNumber: function(number, messageText, attachments, timestamp, expireTimer) {
return this.sendMessage({ return this.sendMessage({
recipients : [number], recipients : [number],
body : messageText, body : messageText,
timestamp : timestamp, timestamp : timestamp,
attachments : attachments, 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) { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
if (numbers === undefined) if (numbers === undefined)
return Promise.reject(new Error("Unknown Group")); return Promise.reject(new Error("Unknown Group"));
@@ -325,6 +336,7 @@ MessageSender.prototype = {
timestamp : timestamp, timestamp : timestamp,
attachments : attachments, attachments : attachments,
needsSync : true, needsSync : true,
expireTimer : expireTimer,
group: { group: {
id: groupId, id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER type: textsecure.protobuf.GroupContext.Type.DELIVER