diff --git a/js/modules/data.js b/js/modules/data.js index d8100bb4a..b86131a8a 100644 --- a/js/modules/data.js +++ b/js/modules/data.js @@ -110,6 +110,7 @@ module.exports = { removeAllSessions, getSwarmNodesByPubkey, + saveSwarmNodesForPubKey, getConversationCount, saveConversation, @@ -674,6 +675,16 @@ async function getSwarmNodesByPubkey(pubkey) { return channels.getSwarmNodesByPubkey(pubkey); } +async function saveSwarmNodesForPubKey(pubKey, swarmNodes, { Conversation }) { + const conversation = await getConversationById(pubKey, { Conversation }); + conversation.set({ swarmNodes }); + await updateConversation( + conversation.id, + conversation.attributes, + { Conversation } + ); +} + async function getConversationCount() { return channels.getConversationCount(); } diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index 7c9a8721b..a4415aa73 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-loop-func */ -/* global log, dcodeIO, window, callWorker */ +/* global log, dcodeIO, window, callWorker, Whisper */ const fetch = require('node-fetch'); const _ = require('lodash'); @@ -105,7 +105,7 @@ class LokiMessageAPI { throw HTTPError('sendMessage: error response', response.status, result); }; - let swarmNodes = await window.LokiSnodeAPI.getSwarmNodesByPubkey(pubKey); + let swarmNodes = await window.Signal.Data.getSwarmNodesByPubkey(pubKey); while (successfulRequests < MINIMUM_SUCCESSFUL_REQUESTS) { if (!canResolve) { throw new window.textsecure.DNSResolutionError('Sending messages'); @@ -123,7 +123,11 @@ class LokiMessageAPI { new Error('Ran out of swarm nodes to query') ); } - await window.LokiSnodeAPI.saveSwarmNodes(pubKey, swarmNodes); + await window.Signal.Data.saveSwarmNodesForPubkey( + pubKey, + swarmNodes, + { Conversation: Whisper.Conversation } + ); } const remainingRequests = MINIMUM_SUCCESSFUL_REQUESTS - completedNodes.length; diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index cc18abaa0..78dfb1c67 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -106,23 +106,6 @@ class LokiSnodeAPI { return this.ourSwarmNodes; } - async getSwarmNodesByPubkey(pubKey) { - const swarmNodes = await window.Signal.Data.getSwarmNodesByPubkey(pubKey); - return swarmNodes; - } - - async saveSwarmNodes(pubKey, swarmNodes) { - const conversation = window.ConversationController.get(pubKey); - conversation.set({ swarmNodes }); - await window.Signal.Data.updateConversation( - conversation.id, - conversation.attributes, - { - Conversation: Whisper.Conversation, - } - ); - } - async getFreshSwarmNodes(pubKey) { if (!(pubKey in this.swarmsPendingReplenish)) { this.swarmsPendingReplenish[pubKey] = new Promise(async resolve => { diff --git a/libloki/api.js b/libloki/api.js index 838ffdfb6..ae7834a58 100644 --- a/libloki/api.js +++ b/libloki/api.js @@ -12,9 +12,13 @@ const friendKeys = await window.Signal.Data.getPubKeysWithFriendStatus( window.friends.friendRequestStatusEnum.friends ); - friendKeys.forEach(pubKey => { - sendOnlineBroadcastMessage(pubKey); - }); + await Promise.all(friendKeys.map(async pubKey => { + try { + await sendOnlineBroadcastMessage(pubKey); + } catch(e) { + log.warn(`Failed to send online broadcast message to ${pubKey}`); + } + })); } async function sendOnlineBroadcastMessage(pubKey) {