From 999e6fc71280378b9e8efbd92c6709e4ce54e78f Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 28 Jan 2021 11:39:07 +1100 Subject: [PATCH] replace GroupUpdateV2 in proto to ClosedGroupControlMessage --- protos/SignalService.proto | 4 ++-- ts/receiver/closedGroupsV2.ts | 20 +++++++++---------- ts/receiver/dataMessage.ts | 11 +++------- ts/session/groupv2/index.ts | 6 +++--- .../ClosedGroupV2EncryptionPairMessage.ts | 10 +++++----- .../data/groupv2/ClosedGroupV2Message.ts | 2 +- .../data/groupv2/ClosedGroupV2NewMessage.ts | 20 +++++++++---------- .../groupv2/ClosedGroupV2UpdateMessage.ts | 10 +++++----- ts/test/session/unit/utils/Messages_test.ts | 8 ++++---- 9 files changed, 43 insertions(+), 48 deletions(-) diff --git a/protos/SignalService.proto b/protos/SignalService.proto index 46c4bdc12..582b5c2aa 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -144,7 +144,7 @@ message DataMessage { optional string profilePicture = 2; } - message ClosedGroupUpdateV2 { + message ClosedGroupControlMessage { enum Type { NEW = 1; // publicKey, name, encryptionKeyPair, members, admins @@ -194,7 +194,7 @@ message DataMessage { repeated Preview preview = 10; optional LokiProfile profile = 101; optional GroupInvitation groupInvitation = 102; - optional ClosedGroupUpdateV2 closedGroupUpdateV2 = 104; + optional ClosedGroupControlMessage closedGroupControlMessage = 104; } diff --git a/ts/receiver/closedGroupsV2.ts b/ts/receiver/closedGroupsV2.ts index 711652945..b048bc0be 100644 --- a/ts/receiver/closedGroupsV2.ts +++ b/ts/receiver/closedGroupsV2.ts @@ -27,7 +27,7 @@ export async function handleClosedGroupV2( groupUpdate: any ) { const { type } = groupUpdate; - const { Type } = SignalService.DataMessage.ClosedGroupUpdateV2; + const { Type } = SignalService.DataMessage.ClosedGroupControlMessage; if (BlockedNumberController.isGroupBlocked(PubKey.cast(envelope.source))) { window.log.warn('Message ignored; destined for blocked group'); @@ -47,7 +47,7 @@ export async function handleClosedGroupV2( } function sanityCheckNewGroupV2( - groupUpdate: SignalService.DataMessage.ClosedGroupUpdateV2 + groupUpdate: SignalService.DataMessage.ClosedGroupControlMessage ): boolean { // for a new group message, we need everything to be set const { name, publicKey, members, admins, encryptionKeyPair } = groupUpdate; @@ -111,12 +111,12 @@ function sanityCheckNewGroupV2( async function handleNewClosedGroupV2( envelope: EnvelopePlus, - groupUpdate: SignalService.DataMessage.ClosedGroupUpdateV2 + groupUpdate: SignalService.DataMessage.ClosedGroupControlMessage ) { const { log } = window; if ( - groupUpdate.type !== SignalService.DataMessage.ClosedGroupUpdateV2.Type.NEW + groupUpdate.type !== SignalService.DataMessage.ClosedGroupControlMessage.Type.NEW ) { return; } @@ -217,11 +217,11 @@ async function handleNewClosedGroupV2( async function handleUpdateClosedGroupV2( envelope: EnvelopePlus, - groupUpdate: SignalService.DataMessage.ClosedGroupUpdateV2 + groupUpdate: SignalService.DataMessage.ClosedGroupControlMessage ) { if ( groupUpdate.type !== - SignalService.DataMessage.ClosedGroupUpdateV2.Type.UPDATE + SignalService.DataMessage.ClosedGroupControlMessage.Type.UPDATE ) { return; } @@ -342,11 +342,11 @@ async function handleUpdateClosedGroupV2( */ async function handleKeyPairClosedGroupV2( envelope: EnvelopePlus, - groupUpdate: SignalService.DataMessage.ClosedGroupUpdateV2 + groupUpdate: SignalService.DataMessage.ClosedGroupControlMessage ) { if ( groupUpdate.type !== - SignalService.DataMessage.ClosedGroupUpdateV2.Type.ENCRYPTION_KEY_PAIR + SignalService.DataMessage.ClosedGroupControlMessage.Type.ENCRYPTION_KEY_PAIR ) { return; } @@ -412,9 +412,9 @@ async function handleKeyPairClosedGroupV2( } // Parse it - let proto: SignalService.DataMessage.ClosedGroupUpdateV2.KeyPair; + let proto: SignalService.DataMessage.ClosedGroupControlMessage.KeyPair; try { - proto = SignalService.DataMessage.ClosedGroupUpdateV2.KeyPair.decode( + proto = SignalService.DataMessage.ClosedGroupControlMessage.KeyPair.decode( plaintext ); if ( diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index d0dac17b5..45dd6e15c 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -241,14 +241,9 @@ export function isMessageEmpty(message: SignalService.DataMessage) { } function isBodyEmpty(body: string) { - return _.isEmpty(body) || isBodyAutoFRContent(body); + return _.isEmpty(body); } -function isBodyAutoFRContent(body: string) { - return ( - body === 'Please accept to enable messages to be synced across devices' - ); -} export async function handleDataMessage( envelope: EnvelopePlus, @@ -256,8 +251,8 @@ export async function handleDataMessage( ): Promise { window.log.info('data message from', getEnvelopeId(envelope)); - if (dataMessage.closedGroupUpdateV2) { - await handleClosedGroupV2(envelope, dataMessage.closedGroupUpdateV2); + if (dataMessage.closedGroupControlMessage) { + await handleClosedGroupV2(envelope, dataMessage.closedGroupControlMessage); return; } diff --git a/ts/session/groupv2/index.ts b/ts/session/groupv2/index.ts index a0e3cc8ab..ce0e98efa 100644 --- a/ts/session/groupv2/index.ts +++ b/ts/session/groupv2/index.ts @@ -478,11 +478,11 @@ export async function generateAndSendNewEncryptionKeyPair( ); return; } - const proto = new SignalService.DataMessage.ClosedGroupUpdateV2.KeyPair({ + const proto = new SignalService.DataMessage.ClosedGroupControlMessage.KeyPair({ privateKey: newKeyPair?.privateKeyData, publicKey: newKeyPair?.publicKeyData, }); - const plaintext = SignalService.DataMessage.ClosedGroupUpdateV2.KeyPair.encode( + const plaintext = SignalService.DataMessage.ClosedGroupControlMessage.KeyPair.encode( proto ).finish(); @@ -493,7 +493,7 @@ export async function generateAndSendNewEncryptionKeyPair( PubKey.cast(pubkey), plaintext ); - return new SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper({ + return new SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper({ encryptedKeyPair: ciphertext, publicKey: fromHexToArray(pubkey), }); diff --git a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2EncryptionPairMessage.ts b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2EncryptionPairMessage.ts index 716be9725..53d4da0eb 100644 --- a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2EncryptionPairMessage.ts +++ b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2EncryptionPairMessage.ts @@ -8,13 +8,13 @@ import { interface ClosedGroupV2EncryptionPairMessageParams extends ClosedGroupV2MessageParams { encryptedKeyPairs: Array< - SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper + SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper >; } export class ClosedGroupV2EncryptionPairMessage extends ClosedGroupV2Message { private readonly encryptedKeyPairs: Array< - SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper + SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper >; constructor(params: ClosedGroupV2EncryptionPairMessageParams) { @@ -34,9 +34,9 @@ export class ClosedGroupV2EncryptionPairMessage extends ClosedGroupV2Message { const dataMessage = super.dataProto(); // tslint:disable: no-non-null-assertion - dataMessage.closedGroupUpdateV2!.type = - SignalService.DataMessage.ClosedGroupUpdateV2.Type.ENCRYPTION_KEY_PAIR; - dataMessage.closedGroupUpdateV2!.wrappers = this.encryptedKeyPairs.map( + dataMessage.closedGroupControlMessage!.type = + SignalService.DataMessage.ClosedGroupControlMessage.Type.ENCRYPTION_KEY_PAIR; + dataMessage.closedGroupControlMessage!.wrappers = this.encryptedKeyPairs.map( w => { const { publicKey, encryptedKeyPair } = w; return { diff --git a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2Message.ts b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2Message.ts index 78cd2250c..d7bd0e941 100644 --- a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2Message.ts +++ b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2Message.ts @@ -35,7 +35,7 @@ export abstract class ClosedGroupV2Message extends DataMessage { public dataProto(): SignalService.DataMessage { const dataMessage = new SignalService.DataMessage(); - dataMessage.closedGroupUpdateV2 = new SignalService.DataMessage.ClosedGroupUpdateV2(); + dataMessage.closedGroupControlMessage = new SignalService.DataMessage.ClosedGroupControlMessage(); dataMessage.expireTimer = this.expireTimer; return dataMessage; diff --git a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2NewMessage.ts b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2NewMessage.ts index 28814c6ac..1d3edfe8c 100644 --- a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2NewMessage.ts +++ b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2NewMessage.ts @@ -58,23 +58,23 @@ export class ClosedGroupV2NewMessage extends ClosedGroupV2Message { dataMessage.expireTimer = this.expireTimer; - dataMessage.closedGroupUpdateV2 = new SignalService.DataMessage.ClosedGroupUpdateV2(); + dataMessage.closedGroupControlMessage = new SignalService.DataMessage.ClosedGroupControlMessage(); - dataMessage.closedGroupUpdateV2.type = - SignalService.DataMessage.ClosedGroupUpdateV2.Type.NEW; - dataMessage.closedGroupUpdateV2.publicKey = fromHexToArray( + dataMessage.closedGroupControlMessage.type = + SignalService.DataMessage.ClosedGroupControlMessage.Type.NEW; + dataMessage.closedGroupControlMessage.publicKey = fromHexToArray( this.groupId.key ); - dataMessage.closedGroupUpdateV2.name = this.name; + dataMessage.closedGroupControlMessage.name = this.name; - dataMessage.closedGroupUpdateV2.admins = this.admins.map(fromHexToArray); - dataMessage.closedGroupUpdateV2.members = this.members.map(fromHexToArray); + dataMessage.closedGroupControlMessage.admins = this.admins.map(fromHexToArray); + dataMessage.closedGroupControlMessage.members = this.members.map(fromHexToArray); try { - dataMessage.closedGroupUpdateV2.encryptionKeyPair = new SignalService.DataMessage.ClosedGroupUpdateV2.KeyPair(); - dataMessage.closedGroupUpdateV2.encryptionKeyPair.privateKey = new Uint8Array( + dataMessage.closedGroupControlMessage.encryptionKeyPair = new SignalService.DataMessage.ClosedGroupControlMessage.KeyPair(); + dataMessage.closedGroupControlMessage.encryptionKeyPair.privateKey = new Uint8Array( this.keypair.privateKeyData ); - dataMessage.closedGroupUpdateV2.encryptionKeyPair.publicKey = new Uint8Array( + dataMessage.closedGroupControlMessage.encryptionKeyPair.publicKey = new Uint8Array( this.keypair.publicKeyData ); } catch (e) { diff --git a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2UpdateMessage.ts b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2UpdateMessage.ts index 0f24bda8d..42910035c 100644 --- a/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2UpdateMessage.ts +++ b/ts/session/messages/outgoing/content/data/groupv2/ClosedGroupV2UpdateMessage.ts @@ -38,11 +38,11 @@ export class ClosedGroupV2UpdateMessage extends ClosedGroupV2Message { public dataProto(): SignalService.DataMessage { const dataMessage = new SignalService.DataMessage(); - dataMessage.closedGroupUpdateV2 = new SignalService.DataMessage.ClosedGroupUpdateV2(); - dataMessage.closedGroupUpdateV2.type = - SignalService.DataMessage.ClosedGroupUpdateV2.Type.UPDATE; - dataMessage.closedGroupUpdateV2.name = this.name; - dataMessage.closedGroupUpdateV2.members = this.members.map(fromHexToArray); + dataMessage.closedGroupControlMessage = new SignalService.DataMessage.ClosedGroupControlMessage(); + dataMessage.closedGroupControlMessage.type = + SignalService.DataMessage.ClosedGroupControlMessage.Type.UPDATE; + dataMessage.closedGroupControlMessage.name = this.name; + dataMessage.closedGroupControlMessage.members = this.members.map(fromHexToArray); return dataMessage; } diff --git a/ts/test/session/unit/utils/Messages_test.ts b/ts/test/session/unit/utils/Messages_test.ts index 5e25bd526..44a88b468 100644 --- a/ts/test/session/unit/utils/Messages_test.ts +++ b/ts/test/session/unit/utils/Messages_test.ts @@ -134,10 +134,10 @@ describe('Message Utils', () => { const device = TestUtils.generateFakePubKey(); const fakeWrappers = new Array< - SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper + SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper >(); fakeWrappers.push( - new SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper({ + new SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper({ publicKey: new Uint8Array(8), encryptedKeyPair: new Uint8Array(8), }) @@ -156,10 +156,10 @@ describe('Message Utils', () => { const device = TestUtils.generateFakePubKey(); const fakeWrappers = new Array< - SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper + SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper >(); fakeWrappers.push( - new SignalService.DataMessage.ClosedGroupUpdateV2.KeyPairWrapper({ + new SignalService.DataMessage.ClosedGroupControlMessage.KeyPairWrapper({ publicKey: new Uint8Array(8), encryptedKeyPair: new Uint8Array(8), })