From b80eb53d31c16059c476abfe0b2e303d61cb7344 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 2 Sep 2024 12:15:17 +1000 Subject: [PATCH] fix: group control messages issues since strings SES-2666 --- ts/models/groupUpdate.ts | 10 +++++----- ts/receiver/contentMessage.ts | 7 ++----- ts/session/utils/Groups.ts | 10 ---------- ts/util/i18n/localizedString.ts | 2 +- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/ts/models/groupUpdate.ts b/ts/models/groupUpdate.ts index 145983672..ecea125a9 100644 --- a/ts/models/groupUpdate.ts +++ b/ts/models/groupUpdate.ts @@ -29,7 +29,7 @@ export function getKickedGroupUpdateStr(kicked: Array, groupName: string } } - switch (others.length) { + switch (othersNames.length) { case 0: throw new Error('kicked without anyone in it.'); case 1: @@ -46,7 +46,7 @@ export function getKickedGroupUpdateStr(kicked: Array, groupName: string return { token: 'groupRemovedMultiple', args: { - name: others[0], + name: othersNames[0], count: othersNames.length - 1, }, }; @@ -83,7 +83,7 @@ export function getJoinedGroupUpdateChangeStr( ); if (us) { - switch (others.length) { + switch (othersNames.length) { case 0: return { token: 'legacyGroupMemberYouNew' }; case 1: @@ -92,7 +92,7 @@ export function getJoinedGroupUpdateChangeStr( return { token: 'legacyGroupMemberNewYouMultiple', args: { count: othersNames.length } }; } } - switch (others.length) { + switch (othersNames.length) { case 0: throw new Error('joined without anyone in it.'); case 1: @@ -109,7 +109,7 @@ export function getJoinedGroupUpdateChangeStr( return { token: 'legacyGroupMemberNewMultiple', args: { - name: others[0], + name: othersNames[0], count: othersNames.length - 1, }, }; diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index a413a1cb0..022dee13a 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -20,7 +20,7 @@ import { removeMessagePadding } from '../session/crypto/BufferPadding'; import { DisappearingMessages } from '../session/disappearing_messages'; import { ReadyToDisappearMsgUpdate } from '../session/disappearing_messages/types'; import { ProfileManager } from '../session/profile_manager/ProfileManager'; -import { GroupUtils, UserUtils } from '../session/utils'; +import { UserUtils } from '../session/utils'; import { perfEnd, perfStart } from '../session/utils/Performance'; import { fromHexToArray, toHex } from '../session/utils/String'; import { isUsFromCache } from '../session/utils/User'; @@ -69,10 +69,7 @@ async function decryptForClosedGroup(envelope: EnvelopePlus) { window?.log?.info('received closed group message'); try { const hexEncodedGroupPublicKey = envelope.source; - if (!GroupUtils.isClosedGroup(PubKey.cast(hexEncodedGroupPublicKey))) { - window?.log?.warn('received medium group message but not for an existing medium group'); - throw new Error('Invalid group public key'); // invalidGroupPublicKey - } + const encryptionKeyPairs = await getAllCachedECKeyPair(hexEncodedGroupPublicKey); const encryptionKeyPairsCount = encryptionKeyPairs?.length; diff --git a/ts/session/utils/Groups.ts b/ts/session/utils/Groups.ts index 8b22c350c..bea3ce9cf 100644 --- a/ts/session/utils/Groups.ts +++ b/ts/session/utils/Groups.ts @@ -13,16 +13,6 @@ export function getGroupMembers(groupId: PubKey): Array { return groupMembers.map(PubKey.cast); } -export function isClosedGroup(groupId: PubKey): boolean { - const conversation = getConversationController().get(groupId.key); - - if (!conversation) { - return false; - } - - return Boolean(conversation.isClosedGroup()); -} - export function encodeGroupPubKeyFromHex(hexGroupPublicKey: string | PubKey) { const pubkey = PubKey.cast(hexGroupPublicKey); return fromHexToArray(pubkey.key); diff --git a/ts/util/i18n/localizedString.ts b/ts/util/i18n/localizedString.ts index ee5abfcca..f02766894 100644 --- a/ts/util/i18n/localizedString.ts +++ b/ts/util/i18n/localizedString.ts @@ -277,7 +277,7 @@ export class LocalizedStringBuilder< /** Find and replace the dynamic variables in a localized string and substitute the variables with the provided values */ return str.replace(/\{(\w+)\}/g, (match, arg: string) => { const matchedArg = this.args - ? this.args[arg as keyof StringArgsRecord].toString() + ? this.args[arg as keyof StringArgsRecord]?.toString() : undefined; return matchedArg ?? LOCALE_DEFAULTS[arg as keyof typeof LOCALE_DEFAULTS] ?? match;