Don't wait for file server to return tokens when establishing home connection.

pull/797/head
Mikunj Varsani 5 years ago
parent 8b1e24fc44
commit c37650c45d

@ -238,30 +238,20 @@
specialConvInited = true; specialConvInited = true;
}; };
const initLokiMessageAPIs = () => { const initAPIs = () => {
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 () => {
if (window.initialisedAPI) { if (window.initialisedAPI) {
return; return;
} }
const ourKey = textsecure.storage.user.getNumber(); 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 // singleton to interface the File server
// If already exists we registered as a secondary device // If already exists we registered as a secondary device
if (!window.lokiFileServerAPI) { if (!window.lokiFileServerAPI) {
window.lokiFileServerAPIFactory = new window.LokiFileServerAPI(ourKey); window.lokiFileServerAPIFactory = new window.LokiFileServerAPI(ourKey);
window.lokiFileServerAPI = await window.lokiFileServerAPIFactory.establishHomeConnection( window.lokiFileServerAPI = window.lokiFileServerAPIFactory.establishHomeConnection(
window.getDefaultFileServer() window.getDefaultFileServer()
); );
} }
@ -1478,7 +1468,7 @@
const ourKey = textsecure.storage.user.getNumber(); const ourKey = textsecure.storage.user.getNumber();
window.lokiMessageAPI = new window.LokiMessageAPI(ourKey); window.lokiMessageAPI = new window.LokiMessageAPI(ourKey);
window.lokiFileServerAPIFactory = new window.LokiFileServerAPI(ourKey); window.lokiFileServerAPIFactory = new window.LokiFileServerAPI(ourKey);
window.lokiFileServerAPI = await window.lokiFileServerAPIFactory.establishHomeConnection( window.lokiFileServerAPI = window.lokiFileServerAPIFactory.establishHomeConnection(
window.getDefaultFileServer() window.getDefaultFileServer()
); );
window.lokiPublicChatAPI = null; window.lokiPublicChatAPI = null;
@ -1498,8 +1488,8 @@
return; return;
} }
initLokiMessageAPIs(); initAPIs();
await initSpecialConversations();
messageReceiver = new textsecure.MessageReceiver( messageReceiver = new textsecure.MessageReceiver(
USERNAME, USERNAME,
PASSWORD, PASSWORD,
@ -1535,9 +1525,6 @@
PASSWORD PASSWORD
); );
await initAPIs();
await initSpecialConversations();
// On startup after upgrading to a new version, request a contact sync // On startup after upgrading to a new version, request a contact sync
// (but only if we're not the primary device) // (but only if we're not the primary device)
if ( if (

@ -291,14 +291,14 @@ class LokiFileServerFactoryAPI {
this.servers = []; this.servers = [];
} }
async establishHomeConnection(serverUrl) { establishHomeConnection(serverUrl) {
let thisServer = this.servers.find( let thisServer = this.servers.find(
server => server._server.baseServerUrl === serverUrl server => server._server.baseServerUrl === serverUrl
); );
if (!thisServer) { if (!thisServer) {
thisServer = new LokiHomeServerInstance(this.ourKey); thisServer = new LokiHomeServerInstance(this.ourKey);
log.info(`Registering HomeServer ${serverUrl}`); log.info(`Registering HomeServer ${serverUrl}`);
await thisServer.establishConnection(serverUrl); thisServer.establishConnection(serverUrl);
this.servers.push(thisServer); this.servers.push(thisServer);
} }
return thisServer; return thisServer;

Loading…
Cancel
Save