From cd79d5aca5972e65a63dea85247fac84e3d2104e Mon Sep 17 00:00:00 2001 From: Beaudan Date: Mon, 4 Feb 2019 15:37:55 +1100 Subject: [PATCH] Fixed and simplified some logic for the handling of loki address messages --- js/modules/loki_p2p_api.js | 20 +++++++------------- libtextsecure/message_receiver.js | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/js/modules/loki_p2p_api.js b/js/modules/loki_p2p_api.js index 5cbbbdacd..6fc18f10d 100644 --- a/js/modules/loki_p2p_api.js +++ b/js/modules/loki_p2p_api.js @@ -8,7 +8,7 @@ class LokiP2pAPI extends EventEmitter { this.contactP2pDetails = {}; } - addContactP2pDetails(pubKey, address, port, resetTimer = false) { + updateContactP2pDetails(pubKey, address, port, fromP2p = false) { // Stagger the timers so the friends don't ping each other at the same time this.ourKey = this.ourKey || window.textsecure.storage.user.getNumber(); const timerDuration = @@ -16,12 +16,10 @@ class LokiP2pAPI extends EventEmitter { ? 60 * 1000 // 1 minute : 2 * 60 * 1000; // 2 minutes - if ( - this.contactP2pDetails[pubKey] && - this.contactP2pDetails[pubKey].pingTimer - ) { + if (this.contactP2pDetails[pubKey]) { clearTimeout(this.contactP2pDetails[pubKey].pingTimer); } + this.contactP2pDetails[pubKey] = { address, port, @@ -29,16 +27,12 @@ class LokiP2pAPI extends EventEmitter { isOnline: false, pingTimer: null, }; - if (resetTimer) { - // If this contact is simply sharing the same details with us - // then we just reset our timer - this.contactP2pDetails[pubKey].pingTimer = setTimeout( - this.pingContact.bind(this), - this.contactP2pDetails[pubKey].timerDuration, - pubKey - ); + + if (fromP2p) { + this.setContactOnline(pubKey); return; } + this.pingContact(pubKey); } diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 72667842c..7c784b410 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -908,7 +908,7 @@ MessageReceiver.prototype.extend({ }, async handleLokiAddressMessage(envelope, lokiAddressMessage) { const { p2pAddress, p2pPort } = lokiAddressMessage; - lokiP2pAPI.addContactP2pDetails( + lokiP2pAPI.updateContactP2pDetails( envelope.source, p2pAddress, p2pPort,