Merge pull request #987 from loki-project/open-group-fix

Fix messages not being created properly in open groups
pull/991/head
Vince 5 years ago committed by GitHub
commit 0f06046247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1946,6 +1946,10 @@
}) { }) {
return async event => { return async event => {
const { data, confirm } = event; const { data, confirm } = event;
if (!data) {
window.log.warn('Invalid data passed to createMessageHandler.', event);
return confirm();
}
const messageDescriptor = getMessageDescriptor(data); const messageDescriptor = getMessageDescriptor(data);
@ -1968,36 +1972,38 @@
messageDescriptor.id messageDescriptor.id
); );
let message; 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' && messageDescriptor.type === 'group' &&
descriptorId.match(/^publicChat:/) descriptorId.match(/^publicChat:/);
) { if (isPublicChatMessage && isOurDevice) {
// Note: This only works currently because we have a 1 device limit // Public chat messages from ourselves should be outgoing
// When we change that, the check below needs to change too message = await createSentMessage(data);
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);
}
} else { } else {
message = await createMessage(data); message = await createMessage(data);
} }
const isDuplicate = await isMessageDuplicate(message); const isDuplicate = await isMessageDuplicate(message);
if (isDuplicate) { if (isDuplicate) {
// RSS expects duplciates, so squelch log // RSS expects duplciates, so squelch log
if (!descriptorId.match(/^rss:/)) { if (!descriptorId.match(/^rss:/)) {
window.log.warn('Received duplicate message', message.idForLogging()); window.log.warn('Received duplicate message', message.idForLogging());
} }
return event.confirm(); return confirm();
} }
await ConversationController.getOrCreateAndWait( await ConversationController.getOrCreateAndWait(
messageDescriptor.id, messageDescriptor.id,
messageDescriptor.type messageDescriptor.type
); );
return message.handleDataMessage(data.message, event.confirm, { return message.handleDataMessage(data.message, confirm, {
initialLoadComplete, initialLoadComplete,
}); });
}; };

@ -103,8 +103,11 @@ class LokiFileServerInstance {
if (!Array.isArray(authorisations)) { if (!Array.isArray(authorisations)) {
return; return;
} }
const validAuthorisations = authorisations.filter(
a => a && typeof auth === 'object'
);
await Promise.all( await Promise.all(
authorisations.map(async auth => { validAuthorisations.map(async auth => {
// only skip, if in secondary search mode // only skip, if in secondary search mode
if (isRequest && auth.secondaryDevicePubKey !== user.username) { if (isRequest && auth.secondaryDevicePubKey !== user.username) {
// this is not the authorization we're looking for // this is not the authorization we're looking for

@ -147,7 +147,9 @@
({ authorisations } = primaryDeviceMapping); ({ authorisations } = primaryDeviceMapping);
} }
} }
return authorisations || [];
// filter out any invalid authorisations
return authorisations.filter(a => a && typeof a === 'object') || [];
} }
// if the device is a secondary device, // if the device is a secondary device,
@ -168,6 +170,10 @@
} }
async function savePairingAuthorisation(authorisation) { async function savePairingAuthorisation(authorisation) {
if (!authorisation) {
return;
}
// Ensure that we have a conversation for all the devices // Ensure that we have a conversation for all the devices
const conversation = await ConversationController.getOrCreateAndWait( const conversation = await ConversationController.getOrCreateAndWait(
authorisation.secondaryDevicePubKey, authorisation.secondaryDevicePubKey,

Loading…
Cancel
Save