From 4a13b1e6bbafb1f3b59b4391f0e94fb314a2e48a Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 8 Jul 2020 15:25:18 +1000 Subject: [PATCH] attemptConnection-complete --- js/background.js | 22 ++++++++++++++++------ ts/session/types/OpenGroup.ts | 1 - ts/state/selectors/conversations.ts | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/js/background.js b/js/background.js index 243715932..fb132b982 100644 --- a/js/background.js +++ b/js/background.js @@ -1092,12 +1092,22 @@ // Attempts a connection to an open group server window.attemptConnection = async (serverURL, channelId) => { - let rawserverURL = serverURL + let completeServerURL = serverURL.toLowerCase(); + const valid = window.libsession.Types.OpenGroup.validate(completeServerURL); + if (!valid) { + return new Promise((_resolve, reject) => { + reject(window.i18n('connectToServerFail')); + }); + } + + // Add http or https prefix to server + completeServerURL = window.libsession.Types.OpenGroup.prefixify(completeServerURL); + + const rawServerURL = serverURL .replace(/^https?:\/\//i, '') .replace(/[/\\]+$/i, ''); - rawserverURL = rawserverURL.toLowerCase(); - const sslServerURL = `https://${rawserverURL}`; - const conversationId = `publicChat:${channelId}@${rawserverURL}`; + + const conversationId = `publicChat:${channelId}@${rawServerURL}`; // Quickly peak to make sure we don't already have it const conversationExists = window.ConversationController.get( @@ -1112,7 +1122,7 @@ // Get server const serverAPI = await window.lokiPublicChatAPI.findOrCreateServer( - sslServerURL + completeServerURL ); // SSL certificate failure or offline if (!serverAPI) { @@ -1129,7 +1139,7 @@ ); // Convert conversation to a public one - await conversation.setPublicSource(sslServerURL, channelId); + await conversation.setPublicSource(completeServerURL, channelId); // and finally activate it conversation.getPublicSendData(); // may want "await" if you want to use the API diff --git a/ts/session/types/OpenGroup.ts b/ts/session/types/OpenGroup.ts index 23822eb55..52026d048 100644 --- a/ts/session/types/OpenGroup.ts +++ b/ts/session/types/OpenGroup.ts @@ -1,4 +1,3 @@ - interface OpenGroupParams { server: string; channel: number; diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 729a2f772..3f28c7851 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -137,7 +137,8 @@ export const _getLeftPaneLists = ( }; } - // Remove all invalid conversations and conversatons of devices associated with cancelled attempted links + // Remove all invalid conversations and conversatons of devices associated + // with cancelled attempted links if (!conversation.isPublic && !conversation.timestamp) { continue; }