From 8123508b51660652e201cb9b33e82fc86a485d5e Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 17 Sep 2020 19:36:46 +1000 Subject: [PATCH] fix avatar closed group and pubkey for medium mobile groups --- ts/components/Avatar.tsx | 5 +- ts/components/ConversationListItem.tsx | 2 +- .../usingClosedConversationDetails.tsx | 11 +- ts/receiver/contentMessage.ts | 132 +++++++++--------- ts/session/types/PubKey.ts | 23 ++- 5 files changed, 94 insertions(+), 79 deletions(-) diff --git a/ts/components/Avatar.tsx b/ts/components/Avatar.tsx index 8c8226c2f..6fdbbcb0a 100644 --- a/ts/components/Avatar.tsx +++ b/ts/components/Avatar.tsx @@ -91,9 +91,10 @@ export class Avatar extends React.PureComponent { } public render() { - const { avatarPath, size } = this.props; + const { avatarPath, size, memberAvatars } = this.props; const { imageBroken } = this.state; - const hasImage = avatarPath && !imageBroken; + const isClosedGroupAvatar = memberAvatars && memberAvatars.length; + const hasImage = avatarPath && !imageBroken && !isClosedGroupAvatar; if ( size !== 28 && diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 1f7db35c3..3bcc26d29 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -312,7 +312,7 @@ class ConversationListItem extends React.PureComponent { const triggerId = `conversation-item-${phoneNumber}-ctxmenu`; return ( -
+
window.ConversationController.getOrCreateAndWait(m.key, 'private') @@ -79,10 +79,9 @@ export function usingClosedConversationDetails(WrappedComponent: any) { name: m.get('name') || m.get('profileName') || m.id, }; }); - - if (!_.isEqual(memberAvatars, this.state.memberAvatars)) { - this.setState({ memberAvatars }); - } + this.setState({ memberAvatars }); + } else { + this.setState({ memberAvatars: undefined }); } } }; diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 7c125267c..b37df76d2 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -388,81 +388,83 @@ export async function innerHandleContentMessage( plaintext: ArrayBuffer ): Promise { const { ConversationController } = window; - - const content = SignalService.Content.decode(new Uint8Array(plaintext)); - - const blocked = await isBlocked(envelope.source); - if (blocked) { - // We want to allow a blocked user message if that's a control message for a known group and the group is not blocked - if (shouldDropBlockedUserMessage(content)) { - window.log.info('Dropping blocked user message'); - return; - } else { - window.log.info('Allowing group-control message only from blocked user'); + try { + const content = SignalService.Content.decode(new Uint8Array(plaintext)); + + const blocked = await isBlocked(envelope.source); + if (blocked) { + // We want to allow a blocked user message if that's a control message for a known group and the group is not blocked + if (shouldDropBlockedUserMessage(content)) { + window.log.info('Dropping blocked user message'); + return; + } else { + window.log.info( + 'Allowing group-control message only from blocked user' + ); + } } - } - - const { FALLBACK_MESSAGE } = SignalService.Envelope.Type; + const { FALLBACK_MESSAGE } = SignalService.Envelope.Type; - await ConversationController.getOrCreateAndWait(envelope.source, 'private'); + await ConversationController.getOrCreateAndWait(envelope.source, 'private'); - if (content.preKeyBundleMessage) { - await handleSessionRequestMessage(envelope, content.preKeyBundleMessage); - } else if (envelope.type !== FALLBACK_MESSAGE) { - const device = new PubKey(envelope.source); + if (content.preKeyBundleMessage) { + await handleSessionRequestMessage(envelope, content.preKeyBundleMessage); + } else if (envelope.type !== FALLBACK_MESSAGE) { + const device = new PubKey(envelope.source); - await SessionProtocol.onSessionEstablished(device); - await libsession.getMessageQueue().processPending(device); - } + await SessionProtocol.onSessionEstablished(device); + await libsession.getMessageQueue().processPending(device); + } - if (content.pairingAuthorisation) { - await handlePairingAuthorisationMessage( - envelope, - content.pairingAuthorisation, - content.dataMessage - ); - return; - } + if (content.pairingAuthorisation) { + await handlePairingAuthorisationMessage( + envelope, + content.pairingAuthorisation, + content.dataMessage + ); + return; + } - if (content.syncMessage) { - await handleSyncMessage(envelope, content.syncMessage); - return; - } + if (content.syncMessage) { + await handleSyncMessage(envelope, content.syncMessage); + return; + } - if (content.dataMessage) { - if ( - content.dataMessage.profileKey && - content.dataMessage.profileKey.length === 0 - ) { - content.dataMessage.profileKey = null; + if (content.dataMessage) { + if ( + content.dataMessage.profileKey && + content.dataMessage.profileKey.length === 0 + ) { + content.dataMessage.profileKey = null; + } + await handleDataMessage(envelope, content.dataMessage); + return; } - await handleDataMessage(envelope, content.dataMessage); - return; - } - if (content.nullMessage) { - await handleNullMessage(envelope); - return; - } - if (content.callMessage) { - await handleCallMessage(envelope); - return; - } - if (content.receiptMessage) { - await handleReceiptMessage(envelope, content.receiptMessage); - return; - } - if (content.typingMessage) { - if ( - content.typingMessage.groupId && - content.typingMessage.groupId.length === 0 - ) { - content.typingMessage.groupId = null; + if (content.nullMessage) { + await handleNullMessage(envelope); + return; } - await handleTypingMessage(envelope, content.typingMessage); - return; + if (content.callMessage) { + await handleCallMessage(envelope); + return; + } + if (content.receiptMessage) { + await handleReceiptMessage(envelope, content.receiptMessage); + return; + } + if (content.typingMessage) { + if ( + content.typingMessage.groupId && + content.typingMessage.groupId.length === 0 + ) { + content.typingMessage.groupId = null; + } + await handleTypingMessage(envelope, content.typingMessage); + return; + } + } catch (e) { + window.log.warn(e); } - - return; } function onReadReceipt(readAt: any, timestamp: any, reader: any) { diff --git a/ts/session/types/PubKey.ts b/ts/session/types/PubKey.ts index d3fbb7c0c..db333185d 100644 --- a/ts/session/types/PubKey.ts +++ b/ts/session/types/PubKey.ts @@ -1,17 +1,30 @@ export class PubKey { public static readonly PUBKEY_LEN = 66; + private static readonly HEX = '[0-9a-fA-F]'; + // This is a temporary fix to allow groupPubkeys created from mobile to be handled correctly // They have a different regex to match // FIXME move this to a new class which validates group ids and use it in all places where we have group ids (message sending included) - public static readonly MOBILE_GROUP_PUBKEY_LEN = 32; - public static readonly regexForPubkeys = `((05)?[0-9a-fA-F]{${PubKey.PUBKEY_LEN - - 2}})`; + // tslint:disable: member-ordering + public static readonly regexForPubkeys = `((05)?${PubKey.HEX}{64})`; + public static readonly PREFIX_GROUP_TEXTSECURE = '__textsecure_group__!'; - private static readonly regexForMobileGroupID = `__textsecure_group__![0-9a-fA-F]{${PubKey.MOBILE_GROUP_PUBKEY_LEN}}`; // prettier-ignore private static readonly regex: RegExp = new RegExp( - `^${PubKey.regexForPubkeys}|${PubKey.regexForMobileGroupID}$` + `^(${PubKey.PREFIX_GROUP_TEXTSECURE})?(05)?(${PubKey.HEX}{64}|${PubKey.HEX}{32})$` ); + /** + * If you want to update this regex. Be sure that those are matches ; + * __textsecure_group__!05010203040506070809a0b0c0d0e0f0ff010203040506070809a0b0c0d0e0f0ff + * __textsecure_group__!010203040506070809a0b0c0d0e0f0ff010203040506070809a0b0c0d0e0f0ff + * __textsecure_group__!05010203040506070809a0b0c0d0e0f0ff + * __textsecure_group__!010203040506070809a0b0c0d0e0f0ff + * 05010203040506070809a0b0c0d0e0f0ff010203040506070809a0b0c0d0e0f0ff + * 010203040506070809a0b0c0d0e0f0ff010203040506070809a0B0c0d0e0f0FF + * 05010203040506070809a0b0c0d0e0f0ff + * 010203040506070809a0b0c0d0e0f0ff + */ + public readonly key: string; /**