make OutgoingMessage interface an abstract class and add setIdentifier

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

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

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

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

Loading…
Cancel
Save