remove setIdentifier and make identifier optional in constructor

pull/1151/head
Audric Ackermann 5 years ago
parent da8999263b
commit 6860875477
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -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();
}
}

@ -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;

@ -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();
}

@ -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;
}

@ -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;

@ -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;

@ -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,

@ -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;

@ -8,9 +8,9 @@ interface ReceiptMessageParams extends MessageParams {
export abstract class ReceiptMessage extends ContentMessage {
private readonly timestamps: Array<number>;
constructor({ timestamp, timestamps }:
constructor({ timestamp, identifier, timestamps }:
ReceiptMessageParams) {
super({timestamp});
super({timestamp, identifier});
this.timestamps = timestamps;
}

Loading…
Cancel
Save