From d8b982e1949e35451649e4e4b81f907162fe4ab1 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Wed, 18 Mar 2020 16:14:17 +1100 Subject: [PATCH 1/2] Fix messages not being created properly in open groups --- js/background.js | 6 +++++- js/modules/loki_file_server_api.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index 105e8e71f..b2ff36189 100644 --- a/js/background.js +++ b/js/background.js @@ -1981,9 +1981,13 @@ // Public chat messages from ourselves should be outgoing message = await createSentMessage(data); } - } else { + } + + // All other messages should be incoming + if (!message) { message = await createMessage(data); } + const isDuplicate = await isMessageDuplicate(message); if (isDuplicate) { // RSS expects duplciates, so squelch log diff --git a/js/modules/loki_file_server_api.js b/js/modules/loki_file_server_api.js index 1bd5fbc51..571a8016b 100644 --- a/js/modules/loki_file_server_api.js +++ b/js/modules/loki_file_server_api.js @@ -105,6 +105,10 @@ class LokiFileServerInstance { } await Promise.all( authorisations.map(async auth => { + if (typeof auth !== 'object') { + return; + } + // only skip, if in secondary search mode if (isRequest && auth.secondaryDevicePubKey !== user.username) { // this is not the authorization we're looking for From 33925d69e9ab5bb56c181a220f9f1b4ef846f5f6 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 19 Mar 2020 09:12:06 +1100 Subject: [PATCH 2/2] Cleanup --- js/background.js | 38 ++++++++++++++++-------------- js/modules/loki_file_server_api.js | 9 ++++--- libloki/storage.js | 8 ++++++- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/js/background.js b/js/background.js index b2ff36189..64b4a0f66 100644 --- a/js/background.js +++ b/js/background.js @@ -1946,6 +1946,10 @@ }) { return async event => { const { data, confirm } = event; + if (!data) { + window.log.warn('Invalid data passed to createMessageHandler.', event); + return confirm(); + } const messageDescriptor = getMessageDescriptor(data); @@ -1968,23 +1972,21 @@ messageDescriptor.id ); let message; - if ( + const { source } = data; + + // Note: This only works currently because we have a 1 device limit + // When we change that, the check below needs to change too + const ourNumber = textsecure.storage.user.getNumber(); + const primaryDevice = window.storage.get('primaryDevicePubKey'); + const isOurDevice = + source && (source === ourNumber || source === primaryDevice); + const isPublicChatMessage = messageDescriptor.type === 'group' && - descriptorId.match(/^publicChat:/) - ) { - // Note: This only works currently because we have a 1 device limit - // When we change that, the check below needs to change too - const ourNumber = textsecure.storage.user.getNumber(); - const primaryDevice = window.storage.get('primaryDevicePubKey'); - const { source } = data; - if (source && (source === ourNumber || source === primaryDevice)) { - // Public chat messages from ourselves should be outgoing - message = await createSentMessage(data); - } - } - - // All other messages should be incoming - if (!message) { + descriptorId.match(/^publicChat:/); + if (isPublicChatMessage && isOurDevice) { + // Public chat messages from ourselves should be outgoing + message = await createSentMessage(data); + } else { message = await createMessage(data); } @@ -1994,14 +1996,14 @@ if (!descriptorId.match(/^rss:/)) { window.log.warn('Received duplicate message', message.idForLogging()); } - return event.confirm(); + return confirm(); } await ConversationController.getOrCreateAndWait( messageDescriptor.id, messageDescriptor.type ); - return message.handleDataMessage(data.message, event.confirm, { + return message.handleDataMessage(data.message, confirm, { initialLoadComplete, }); }; diff --git a/js/modules/loki_file_server_api.js b/js/modules/loki_file_server_api.js index 571a8016b..5d3dfdde5 100644 --- a/js/modules/loki_file_server_api.js +++ b/js/modules/loki_file_server_api.js @@ -103,12 +103,11 @@ class LokiFileServerInstance { if (!Array.isArray(authorisations)) { return; } + const validAuthorisations = authorisations.filter( + a => a && typeof auth === 'object' + ); await Promise.all( - authorisations.map(async auth => { - if (typeof auth !== 'object') { - return; - } - + validAuthorisations.map(async auth => { // only skip, if in secondary search mode if (isRequest && auth.secondaryDevicePubKey !== user.username) { // this is not the authorization we're looking for diff --git a/libloki/storage.js b/libloki/storage.js index 0e4cd3dda..ff52e52c5 100644 --- a/libloki/storage.js +++ b/libloki/storage.js @@ -147,7 +147,9 @@ ({ authorisations } = primaryDeviceMapping); } } - return authorisations || []; + + // filter out any invalid authorisations + return authorisations.filter(a => a && typeof a === 'object') || []; } // if the device is a secondary device, @@ -168,6 +170,10 @@ } async function savePairingAuthorisation(authorisation) { + if (!authorisation) { + return; + } + // Ensure that we have a conversation for all the devices const conversation = await ConversationController.getOrCreateAndWait( authorisation.secondaryDevicePubKey,