From 6ba7fb20b8e0e7bb7ad0e3fd26371c1d7fda7396 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Wed, 30 Jan 2019 17:06:38 +1100 Subject: [PATCH] Fixed UI blocking when creating conversation, more review comments --- js/conversation_controller.js | 3 +-- js/modules/data.js | 8 +++----- js/modules/loki_message_api.js | 8 +++----- js/modules/loki_snode_api.js | 7 +++++++ libloki/api.js | 16 +++++++++------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 5d85fd143..8decd5151 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -182,11 +182,10 @@ } try { - const swarmNodes = await window.LokiSnodeAPI.getFreshSwarmNodes(id); - conversation.set({ swarmNodes }); await window.Signal.Data.saveConversation(conversation.attributes, { Conversation: Whisper.Conversation, }); + window.LokiSnodeAPI.refreshSwarmNodesForPubKey(id); } catch (error) { window.log.error( 'Conversation save failed! ', diff --git a/js/modules/data.js b/js/modules/data.js index b86131a8a..d4e2fb58e 100644 --- a/js/modules/data.js +++ b/js/modules/data.js @@ -678,11 +678,9 @@ async function getSwarmNodesByPubkey(pubkey) { async function saveSwarmNodesForPubKey(pubKey, swarmNodes, { Conversation }) { const conversation = await getConversationById(pubKey, { Conversation }); conversation.set({ swarmNodes }); - await updateConversation( - conversation.id, - conversation.attributes, - { Conversation } - ); + await updateConversation(conversation.id, conversation.attributes, { + Conversation, + }); } async function getConversationCount() { diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index a4415aa73..ddd565548 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -123,11 +123,9 @@ class LokiMessageAPI { new Error('Ran out of swarm nodes to query') ); } - await window.Signal.Data.saveSwarmNodesForPubkey( - pubKey, - swarmNodes, - { Conversation: Whisper.Conversation } - ); + 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 78dfb1c67..8d1dc501b 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -106,6 +106,13 @@ class LokiSnodeAPI { return this.ourSwarmNodes; } + async refreshSwarmNodesForPubKey(pubKey) { + const newNodes = await this.getFreshSwarmNodes(pubKey); + await window.Signal.Data.saveSwarmNodesForPubKey(pubKey, newNodes, { + 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 ae7834a58..876cd15e2 100644 --- a/libloki/api.js +++ b/libloki/api.js @@ -12,13 +12,15 @@ const friendKeys = await window.Signal.Data.getPubKeysWithFriendStatus( window.friends.friendRequestStatusEnum.friends ); - await Promise.all(friendKeys.map(async pubKey => { - try { - await sendOnlineBroadcastMessage(pubKey); - } catch(e) { - log.warn(`Failed to send online broadcast message to ${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) {