diff --git a/ts/session/messages/outgoing/Message.ts b/ts/session/messages/outgoing/Message.ts index 2e23284c8..1fdd1f12a 100644 --- a/ts/session/messages/outgoing/Message.ts +++ b/ts/session/messages/outgoing/Message.ts @@ -1,3 +1,20 @@ -export interface Message { - timestamp: number; +export abstract class Message { + public readonly timestamp: number; + public identifier: string; + + + constructor({ timestamp, identifier }: { timestamp: number; identifier: string }) { + if (identifier.length === 0) { + throw new Error('Cannot set empty identifier'); + } + this.timestamp = timestamp; + this.identifier = identifier; + } + + public setIdentifier(identifier: string) { + if (identifier.length === 0) { + throw new Error('Cannot set empty identifier'); + } + this.identifier = identifier; + } } diff --git a/ts/session/messages/outgoing/OpenGroupMessage.ts b/ts/session/messages/outgoing/OpenGroupMessage.ts index 65c23c6ba..34914d95b 100644 --- a/ts/session/messages/outgoing/OpenGroupMessage.ts +++ b/ts/session/messages/outgoing/OpenGroupMessage.ts @@ -2,21 +2,30 @@ import { Message } from './Message'; import { AttachmentType } from '../../../types/Attachment'; import { QuotedAttachmentType } from '../../../components/conversation/Quote'; -export class OpenGroupMessage implements Message { - public readonly timestamp: number; +interface OpenGroupMessageParams { + timestamp: number; + identifier: string; + server: string; + attachments: [AttachmentType]; + body?: string; + quote?: QuotedAttachmentType; +} + +export class OpenGroupMessage extends Message { public readonly server: string; public readonly body?: string; public readonly attachments: [AttachmentType]; // TODO: Not sure if we should only use a subset of this type public readonly quote?: QuotedAttachmentType; - constructor( - timestamp: number, - server: string, - attachments: [AttachmentType], - body?: string, - quote?: QuotedAttachmentType - ) { - this.timestamp = timestamp; + constructor({ + identifier, + timestamp, + server, + attachments, + body, + quote, + } : OpenGroupMessageParams) { + 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 ba82bfa40..8bb517075 100644 --- a/ts/session/messages/outgoing/content/ContentMessage.ts +++ b/ts/session/messages/outgoing/content/ContentMessage.ts @@ -1,13 +1,10 @@ import { Message } from '../Message'; import { SignalService } from '../../../../protobuf'; -export abstract class ContentMessage implements Message { - public readonly timestamp: number; - public readonly identifier: string; +export abstract class ContentMessage extends Message { constructor({ timestamp, identifier }: { timestamp: number; identifier: string }) { - this.timestamp = timestamp; - this.identifier = identifier; + super({timestamp, identifier}); } public plainTextBuffer(): Uint8Array {