From c37650c45d66f266c92c7bbd9be61908c15f38fa Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Thu, 6 Feb 2020 14:51:00 +1100 Subject: [PATCH] Don't wait for file server to return tokens when establishing home connection. --- js/background.js | 31 +++++++++--------------------- js/modules/loki_file_server_api.js | 4 ++-- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/js/background.js b/js/background.js index 375338e89..85f040d99 100644 --- a/js/background.js +++ b/js/background.js @@ -238,30 +238,20 @@ specialConvInited = true; }; - const initLokiMessageAPIs = () => { - const ourKey = textsecure.storage.user.getNumber(); - if (!window.lokiMessageAPI) { - window.feeds = []; - window.lokiMessageAPI = new window.LokiMessageAPI(ourKey); - } - - if (!window.lokiPublicChatAPI) { - // singleton to relay events to libtextsecure/message_receiver - window.lokiPublicChatAPI = new window.LokiPublicChatAPI(ourKey); - } - }; - - const initAPIs = async () => { + const initAPIs = () => { if (window.initialisedAPI) { return; } const ourKey = textsecure.storage.user.getNumber(); - + window.feeds = []; + window.lokiMessageAPI = new window.LokiMessageAPI(ourKey); + // singleton to relay events to libtextsecure/message_receiver + window.lokiPublicChatAPI = new window.LokiPublicChatAPI(ourKey); // singleton to interface the File server // If already exists we registered as a secondary device if (!window.lokiFileServerAPI) { window.lokiFileServerAPIFactory = new window.LokiFileServerAPI(ourKey); - window.lokiFileServerAPI = await window.lokiFileServerAPIFactory.establishHomeConnection( + window.lokiFileServerAPI = window.lokiFileServerAPIFactory.establishHomeConnection( window.getDefaultFileServer() ); } @@ -1478,7 +1468,7 @@ const ourKey = textsecure.storage.user.getNumber(); window.lokiMessageAPI = new window.LokiMessageAPI(ourKey); window.lokiFileServerAPIFactory = new window.LokiFileServerAPI(ourKey); - window.lokiFileServerAPI = await window.lokiFileServerAPIFactory.establishHomeConnection( + window.lokiFileServerAPI = window.lokiFileServerAPIFactory.establishHomeConnection( window.getDefaultFileServer() ); window.lokiPublicChatAPI = null; @@ -1498,8 +1488,8 @@ return; } - initLokiMessageAPIs(); - + initAPIs(); + await initSpecialConversations(); messageReceiver = new textsecure.MessageReceiver( USERNAME, PASSWORD, @@ -1535,9 +1525,6 @@ PASSWORD ); - await initAPIs(); - await initSpecialConversations(); - // On startup after upgrading to a new version, request a contact sync // (but only if we're not the primary device) if ( diff --git a/js/modules/loki_file_server_api.js b/js/modules/loki_file_server_api.js index 601ab2e9a..c38609467 100644 --- a/js/modules/loki_file_server_api.js +++ b/js/modules/loki_file_server_api.js @@ -291,14 +291,14 @@ class LokiFileServerFactoryAPI { this.servers = []; } - async establishHomeConnection(serverUrl) { + establishHomeConnection(serverUrl) { let thisServer = this.servers.find( server => server._server.baseServerUrl === serverUrl ); if (!thisServer) { thisServer = new LokiHomeServerInstance(this.ourKey); log.info(`Registering HomeServer ${serverUrl}`); - await thisServer.establishConnection(serverUrl); + thisServer.establishConnection(serverUrl); this.servers.push(thisServer); } return thisServer;