fix: group control messages issues since strings

SES-2666
pull/3206/head
Audric Ackermann 7 months ago
parent a786c69603
commit b80eb53d31

@ -29,7 +29,7 @@ export function getKickedGroupUpdateStr(kicked: Array<string>, groupName: string
} }
} }
switch (others.length) { switch (othersNames.length) {
case 0: case 0:
throw new Error('kicked without anyone in it.'); throw new Error('kicked without anyone in it.');
case 1: case 1:
@ -46,7 +46,7 @@ export function getKickedGroupUpdateStr(kicked: Array<string>, groupName: string
return { return {
token: 'groupRemovedMultiple', token: 'groupRemovedMultiple',
args: { args: {
name: others[0], name: othersNames[0],
count: othersNames.length - 1, count: othersNames.length - 1,
}, },
}; };
@ -83,7 +83,7 @@ export function getJoinedGroupUpdateChangeStr(
); );
if (us) { if (us) {
switch (others.length) { switch (othersNames.length) {
case 0: case 0:
return { token: 'legacyGroupMemberYouNew' }; return { token: 'legacyGroupMemberYouNew' };
case 1: case 1:
@ -92,7 +92,7 @@ export function getJoinedGroupUpdateChangeStr(
return { token: 'legacyGroupMemberNewYouMultiple', args: { count: othersNames.length } }; return { token: 'legacyGroupMemberNewYouMultiple', args: { count: othersNames.length } };
} }
} }
switch (others.length) { switch (othersNames.length) {
case 0: case 0:
throw new Error('joined without anyone in it.'); throw new Error('joined without anyone in it.');
case 1: case 1:
@ -109,7 +109,7 @@ export function getJoinedGroupUpdateChangeStr(
return { return {
token: 'legacyGroupMemberNewMultiple', token: 'legacyGroupMemberNewMultiple',
args: { args: {
name: others[0], name: othersNames[0],
count: othersNames.length - 1, count: othersNames.length - 1,
}, },
}; };

@ -20,7 +20,7 @@ import { removeMessagePadding } from '../session/crypto/BufferPadding';
import { DisappearingMessages } from '../session/disappearing_messages'; import { DisappearingMessages } from '../session/disappearing_messages';
import { ReadyToDisappearMsgUpdate } from '../session/disappearing_messages/types'; import { ReadyToDisappearMsgUpdate } from '../session/disappearing_messages/types';
import { ProfileManager } from '../session/profile_manager/ProfileManager'; 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 { perfEnd, perfStart } from '../session/utils/Performance';
import { fromHexToArray, toHex } from '../session/utils/String'; import { fromHexToArray, toHex } from '../session/utils/String';
import { isUsFromCache } from '../session/utils/User'; import { isUsFromCache } from '../session/utils/User';
@ -69,10 +69,7 @@ async function decryptForClosedGroup(envelope: EnvelopePlus) {
window?.log?.info('received closed group message'); window?.log?.info('received closed group message');
try { try {
const hexEncodedGroupPublicKey = envelope.source; 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 encryptionKeyPairs = await getAllCachedECKeyPair(hexEncodedGroupPublicKey);
const encryptionKeyPairsCount = encryptionKeyPairs?.length; const encryptionKeyPairsCount = encryptionKeyPairs?.length;

@ -13,16 +13,6 @@ export function getGroupMembers(groupId: PubKey): Array<PubKey> {
return groupMembers.map(PubKey.cast); 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) { export function encodeGroupPubKeyFromHex(hexGroupPublicKey: string | PubKey) {
const pubkey = PubKey.cast(hexGroupPublicKey); const pubkey = PubKey.cast(hexGroupPublicKey);
return fromHexToArray(pubkey.key); return fromHexToArray(pubkey.key);

@ -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 */ /** 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) => { return str.replace(/\{(\w+)\}/g, (match, arg: string) => {
const matchedArg = this.args const matchedArg = this.args
? this.args[arg as keyof StringArgsRecord<Dict[T]>].toString() ? this.args[arg as keyof StringArgsRecord<Dict[T]>]?.toString()
: undefined; : undefined;
return matchedArg ?? LOCALE_DEFAULTS[arg as keyof typeof LOCALE_DEFAULTS] ?? match; return matchedArg ?? LOCALE_DEFAULTS[arg as keyof typeof LOCALE_DEFAULTS] ?? match;

Loading…
Cancel
Save