From b00a0cb699201bae36a52175b08d2465280fff99 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Thu, 14 Feb 2019 14:49:24 +1100 Subject: [PATCH] Rename isOnline to isPing for clarity, and reduce the ttl for online broadcast messages to 1 min --- js/background.js | 4 ++-- js/modules/loki_message_api.js | 4 ++-- js/modules/loki_p2p_api.js | 4 ++-- libloki/api.js | 4 ++-- libtextsecure/outgoing_message.js | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/js/background.js b/js/background.js index 64fabbd0b..e5c6b6972 100644 --- a/js/background.js +++ b/js/background.js @@ -223,8 +223,8 @@ textsecure.storage.user.getNumber() ); window.lokiP2pAPI.on('pingContact', pubKey => { - const forceP2p = true; - window.libloki.api.sendOnlineBroadcastMessage(pubKey, forceP2p); + const isPing = true; + window.libloki.api.sendOnlineBroadcastMessage(pubKey, isPing); }); // These make key operations available to IPC handlers created in preload.js diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index 8aa1a387d..8034ff688 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -63,11 +63,11 @@ class LokiMessageAPI { this.messageServerPort = messageServerPort ? `:${messageServerPort}` : ''; } - async sendMessage(pubKey, data, messageTimeStamp, ttl, forceP2p = false) { + async sendMessage(pubKey, data, messageTimeStamp, ttl, isPing = false) { const data64 = dcodeIO.ByteBuffer.wrap(data).toString('base64'); const timestamp = Math.floor(Date.now() / 1000); const p2pDetails = lokiP2pAPI.getContactP2pDetails(pubKey); - if (p2pDetails && (forceP2p || p2pDetails.isOnline)) { + if (p2pDetails && (isPing || p2pDetails.isOnline)) { try { const port = p2pDetails.port ? `:${p2pDetails.port}` : ''; const url = `${p2pDetails.address}${port}/store`; diff --git a/js/modules/loki_p2p_api.js b/js/modules/loki_p2p_api.js index 349517c6b..aa7d8f726 100644 --- a/js/modules/loki_p2p_api.js +++ b/js/modules/loki_p2p_api.js @@ -16,7 +16,7 @@ class LokiP2pAPI extends EventEmitter { }); } - updateContactP2pDetails(pubKey, address, port, isOnline = false) { + updateContactP2pDetails(pubKey, address, port, isPing = false) { // Stagger the timers so the friends don't ping each other at the same time const timerDuration = pubKey < this.ourKey @@ -35,7 +35,7 @@ class LokiP2pAPI extends EventEmitter { pingTimer: null, }; - if (isOnline) { + if (isPing) { this.setContactOnline(pubKey); return; } diff --git a/libloki/api.js b/libloki/api.js index 2521fded3..e9c6dcc96 100644 --- a/libloki/api.js +++ b/libloki/api.js @@ -23,7 +23,7 @@ ); } - async function sendOnlineBroadcastMessage(pubKey, forceP2p = false) { + async function sendOnlineBroadcastMessage(pubKey, isPing = false) { const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress(); const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({ p2pAddress: `http://${myLokiAddress}`, @@ -41,7 +41,7 @@ log.info('Online broadcast message sent successfully'); } }; - const options = { messageType: 'onlineBroadcast', forceP2p }; + const options = { messageType: 'onlineBroadcast', isPing }; // Send a empty message with information about how to contact us directly const outgoingMessage = new textsecure.OutgoingMessage( null, // server diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index edf1c5fc9..4d940ae9c 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -42,13 +42,13 @@ function OutgoingMessage( this.failoverNumbers = []; this.unidentifiedDeliveries = []; - const { numberInfo, senderCertificate, online, messageType, forceP2p } = + const { numberInfo, senderCertificate, online, messageType, isPing } = options || {}; this.numberInfo = numberInfo; this.senderCertificate = senderCertificate; this.online = online; this.messageType = messageType || 'outgoing'; - this.forceP2p = forceP2p || false; + this.isPing = isPing || false; } OutgoingMessage.prototype = { @@ -192,7 +192,7 @@ OutgoingMessage.prototype = { data, timestamp, ttl, - this.forceP2p + this.isPing ); } catch (e) { if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) { @@ -347,7 +347,7 @@ OutgoingMessage.prototype = { if (this.messageType === 'friend-request') { ttl = 4 * 24 * 60 * 60; // 4 days for friend request message } else if (this.messageType === 'onlineBroadcast') { - ttl = 10 * 60; // 10 minutes for online broadcast message + ttl = 60; // 1 minute for online broadcast message } else { const hours = window.getMessageTTL() || 24; // 1 day default for any other message ttl = hours * 60 * 60;