From d9c89376cbf2a9b82e307657c86b4a12a3d9abb0 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Tue, 23 Oct 2018 15:54:44 +1100 Subject: [PATCH] Added logic to pass tll into transmitMessage function, with default value of 24 hours. TODO: ensure that the target calculation for the PoW is adjusting appropriately for the different ttl values. --- libtextsecure/outgoing_message.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 665975f1b..0b6f4501c 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -148,9 +148,9 @@ OutgoingMessage.prototype = { return promise; }, - async transmitMessage(number, data, timestamp) { + // Default ttl to 24 hours if no value provided + async transmitMessage(number, data, timestamp, ttl = 24 * 60 * 60) { const pubKey = number; - const ttl = 2 * 24 * 60 * 60; try { const [response, status] = await this.lokiserver.sendMessage(pubKey, data, ttl); return response; @@ -263,13 +263,17 @@ OutgoingMessage.prototype = { }) ) .then(async outgoingObjects => { - let promises = []; - outgoingObjects.forEach(outgoingObject => { - promises.push(this.wrapInWebsocketMessage(outgoingObject)); - }); // TODO: handle multiple devices/messages per transmit - const socketMessages = await promises[0]; - await this.transmitMessage(number, socketMessages, this.timestamp); + const outgoingObject = outgoingObjects[0]; + const socketMessage = await this.wrapInWebsocketMessage(outgoingObject); + let ttl; + // TODO: Allow user to set ttl manually + if (outgoingObject.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { + ttl = 4 * 24 * 60 * 60; // 4 days for friend request message + } else { + ttl = 24 * 60 * 60; // 1 day default for any other message + } + await this.transmitMessage(number, socketMessage, this.timestamp, ttl); this.successfulNumbers[this.successfulNumbers.length] = number; this.numberCompleted(); }