From 68608754772d1dad25efe2fe03ea9967e44e913e Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 26 May 2020 15:13:20 +1000 Subject: [PATCH] remove setIdentifier and make identifier optional in constructor --- ts/session/messages/outgoing/Message.ts | 13 +++++-------- ts/session/messages/outgoing/OpenGroupMessage.ts | 3 ++- .../messages/outgoing/content/ContentMessage.ts | 4 ---- .../outgoing/content/SessionResetMessage.ts | 2 +- .../messages/outgoing/content/TypingMessage.ts | 2 +- .../outgoing/content/data/GroupInvitationMessage.ts | 2 +- .../outgoing/content/link/DeviceLinkGrantMessage.ts | 1 + .../content/link/DeviceLinkRequestMessage.ts | 2 +- .../outgoing/content/receipt/ReceiptMessage.ts | 4 ++-- 9 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ts/session/messages/outgoing/Message.ts b/ts/session/messages/outgoing/Message.ts index 37ad4ff4d..b432cac94 100644 --- a/ts/session/messages/outgoing/Message.ts +++ b/ts/session/messages/outgoing/Message.ts @@ -2,22 +2,19 @@ import { v4 as uuid } from 'uuid'; export interface MessageParams { timestamp: number; + identifier?: string; } export abstract class Message { public readonly timestamp: number; - public identifier: string; + public readonly identifier: string; - constructor({ timestamp }: MessageParams) { + constructor({ timestamp, identifier }: MessageParams) { this.timestamp = timestamp; - this.identifier = uuid(); - } - - public setIdentifier(identifier: string) { - if (identifier.length === 0) { + if (identifier && identifier.length === 0) { throw new Error('Cannot set empty identifier'); } - this.identifier = identifier; + this.identifier = identifier || uuid(); } } diff --git a/ts/session/messages/outgoing/OpenGroupMessage.ts b/ts/session/messages/outgoing/OpenGroupMessage.ts index 65cec168c..e7680bbe2 100644 --- a/ts/session/messages/outgoing/OpenGroupMessage.ts +++ b/ts/session/messages/outgoing/OpenGroupMessage.ts @@ -21,8 +21,9 @@ export class OpenGroupMessage extends Message { attachments, body, quote, + identifier, } : OpenGroupMessageParams) { - super({ timestamp }); + super({ timestamp, identifier }); this.server = server; this.body = body; this.attachments = attachments; diff --git a/ts/session/messages/outgoing/content/ContentMessage.ts b/ts/session/messages/outgoing/content/ContentMessage.ts index 5cfd8ca01..57b9f9f5d 100644 --- a/ts/session/messages/outgoing/content/ContentMessage.ts +++ b/ts/session/messages/outgoing/content/ContentMessage.ts @@ -3,10 +3,6 @@ import { SignalService } from '../../../../protobuf'; export abstract class ContentMessage extends Message { - constructor({ timestamp }: { timestamp: number }) { - super({timestamp}); - } - public plainTextBuffer(): Uint8Array { return SignalService.Content.encode(this.contentProto()).finish(); } diff --git a/ts/session/messages/outgoing/content/SessionResetMessage.ts b/ts/session/messages/outgoing/content/SessionResetMessage.ts index 5a18e4ead..b7d21221f 100644 --- a/ts/session/messages/outgoing/content/SessionResetMessage.ts +++ b/ts/session/messages/outgoing/content/SessionResetMessage.ts @@ -22,7 +22,7 @@ export class SessionResetMessage extends ContentMessage { private readonly preKeyBundle: PreKeyBundleType; constructor(params: SessionResetParams) { - super({ timestamp: params.timestamp }); + super({ timestamp: params.timestamp, identifier: params.identifier }); this.preKeyBundle = params.preKeyBundle; } diff --git a/ts/session/messages/outgoing/content/TypingMessage.ts b/ts/session/messages/outgoing/content/TypingMessage.ts index a8ee75031..c9da65401 100644 --- a/ts/session/messages/outgoing/content/TypingMessage.ts +++ b/ts/session/messages/outgoing/content/TypingMessage.ts @@ -15,7 +15,7 @@ export class TypingMessage extends ContentMessage { private readonly groupId?: string; constructor(params: TypingMessageParams) { - super({timestamp: params.timestamp}); + super({timestamp: params.timestamp, identifier: params.identifier}); this.isTyping = params.isTyping; this.typingTimestamp = params.typingTimestamp; this.groupId = params.groupId; diff --git a/ts/session/messages/outgoing/content/data/GroupInvitationMessage.ts b/ts/session/messages/outgoing/content/data/GroupInvitationMessage.ts index 20534e857..69c019230 100644 --- a/ts/session/messages/outgoing/content/data/GroupInvitationMessage.ts +++ b/ts/session/messages/outgoing/content/data/GroupInvitationMessage.ts @@ -14,7 +14,7 @@ export class GroupInvitationMessage extends DataMessage { private readonly serverName: string; constructor(params: GroupInvitationMessageParams) { - super({ timestamp: params.timestamp }); + super({ timestamp: params.timestamp, identifier: params.identifier }); this.serverAddress = params.serverAddress; this.channelId = params.channelId; this.serverName = params.serverName; diff --git a/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts b/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts index afcefa976..78a936e59 100644 --- a/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts +++ b/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts @@ -17,6 +17,7 @@ export class DeviceLinkGrantMessage extends DeviceLinkRequestMessage { ) { super({ timestamp: params.timestamp, + identifier: params.identifier, primaryDevicePubKey: params.primaryDevicePubKey, secondaryDevicePubKey: params.secondaryDevicePubKey, requestSignature: params.requestSignature, diff --git a/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts b/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts index d77b7628d..3c9c43d5d 100644 --- a/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts +++ b/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts @@ -14,7 +14,7 @@ export class DeviceLinkRequestMessage extends ContentMessage { protected readonly requestSignature: Uint8Array; constructor(params: DeviceLinkMessageParams) { - super({ timestamp: params.timestamp }); + super({ timestamp: params.timestamp, identifier: params.identifier }); this.primaryDevicePubKey = params.primaryDevicePubKey; this.secondaryDevicePubKey = params.secondaryDevicePubKey; this.requestSignature = params.requestSignature; diff --git a/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts b/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts index e65c52cc2..9e00042e9 100644 --- a/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts +++ b/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts @@ -8,9 +8,9 @@ interface ReceiptMessageParams extends MessageParams { export abstract class ReceiptMessage extends ContentMessage { private readonly timestamps: Array; - constructor({ timestamp, timestamps }: + constructor({ timestamp, identifier, timestamps }: ReceiptMessageParams) { - super({timestamp}); + super({timestamp, identifier}); this.timestamps = timestamps; }