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 { export abstract class Message {
timestamp: number; 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 { AttachmentType } from '../../../types/Attachment';
import { QuotedAttachmentType } from '../../../components/conversation/Quote'; import { QuotedAttachmentType } from '../../../components/conversation/Quote';
export class OpenGroupMessage implements Message { interface OpenGroupMessageParams {
public readonly timestamp: number; timestamp: number;
identifier: string;
server: string;
attachments: [AttachmentType];
body?: string;
quote?: QuotedAttachmentType;
}
export class OpenGroupMessage extends Message {
public readonly server: string; public readonly server: string;
public readonly body?: string; public readonly body?: string;
public readonly attachments: [AttachmentType]; // TODO: Not sure if we should only use a subset of this type public readonly attachments: [AttachmentType]; // TODO: Not sure if we should only use a subset of this type
public readonly quote?: QuotedAttachmentType; public readonly quote?: QuotedAttachmentType;
constructor( constructor({
timestamp: number, identifier,
server: string, timestamp,
attachments: [AttachmentType], server,
body?: string, attachments,
quote?: QuotedAttachmentType body,
) { quote,
this.timestamp = timestamp; } : OpenGroupMessageParams) {
super({ timestamp, identifier });
this.server = server; this.server = server;
this.body = body; this.body = body;
this.attachments = attachments; this.attachments = attachments;

@ -1,13 +1,10 @@
import { Message } from '../Message'; import { Message } from '../Message';
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
export abstract class ContentMessage implements Message { export abstract class ContentMessage extends Message {
public readonly timestamp: number;
public readonly identifier: string;
constructor({ timestamp, identifier }: { timestamp: number; identifier: string }) { constructor({ timestamp, identifier }: { timestamp: number; identifier: string }) {
this.timestamp = timestamp; super({timestamp, identifier});
this.identifier = identifier;
} }
public plainTextBuffer(): Uint8Array { public plainTextBuffer(): Uint8Array {

Loading…
Cancel
Save