add ttl as abstract method so each message can define its own

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

1
ts/global.d.ts vendored

@ -52,6 +52,7 @@ interface Window {
toggleSpellCheck: any;
toggleLinkPreview: any;
toggleMediaPermissions: any;
getMessageTTL: () => number;
getSettingValue: any;
setSettingValue: any;

@ -4,11 +4,10 @@ import { SignalService } from '../../../../protobuf';
export abstract class ContentMessage implements Message {
public readonly timestamp: number;
public readonly identifier: string;
public readonly ttl: number;
constructor(timestamp: number, identifier: string, ttl: number) {
constructor(timestamp: number, identifier: string) {
this.timestamp = timestamp;
this.identifier = identifier;
this.ttl = ttl;
}
public plainTextBuffer(): Uint8Array {
@ -17,8 +16,19 @@ export abstract class ContentMessage implements Message {
return this.processPlainTextBuffer(encoded);
}
public abstract ttl(): number;
protected abstract contentProto(): SignalService.Content;
/**
* If the message is not a message with a specific TTL,
* this value can be used in all child classes
*/
protected getDefaultTTL(): number {
// 1 day default for any other message
return (window.getMessageTTL() || 24) * 60 * 60 * 1000;
}
private processPlainTextBuffer(buffer: Uint8Array): Uint8Array {
const paddedMessageLength = this.getPaddedMessageLength(
buffer.byteLength + 1

@ -3,6 +3,10 @@ import { SignalService } from '../../../../protobuf';
export class DeviceLinkMessage extends ContentMessage {
public ttl(): number {
return 2 * 60 * 1000; // 2 minutes for linking requests
}
protected contentProto(): SignalService.Content {
throw new Error('Not implemented');
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../protobuf';
export class EndSessionMessage extends SessionResetMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected contentProto(): SignalService.Content {
throw new Error('Not implemented');
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../protobuf';
export class ReceiptMessage extends ContentMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected contentProto(): SignalService.Content {
return new SignalService.Content({
receiptMessage: this.receiptProto(),

@ -3,6 +3,10 @@ import { SignalService } from '../../../../protobuf';
export class SessionEstablishedMessage extends ContentMessage {
public ttl(): number {
return 60 * 1000;
}
protected contentProto(): SignalService.Content {
throw new Error('Not implemented');
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../protobuf';
export class SessionResetMessage extends ContentMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected contentProto(): SignalService.Content {
throw new Error('Not implemented');
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../protobuf';
export abstract class TypingMessage extends ContentMessage {
public ttl(): number {
return 60 * 1000; // 1 minute for typing indicators
}
protected contentProto(): SignalService.Content {
return new SignalService.Content({
typingMessage: this.typingProto(),
@ -10,4 +14,5 @@ export abstract class TypingMessage extends ContentMessage {
}
protected abstract typingProto(): SignalService.TypingMessage;
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../../protobuf';
export class ClosedGroupMessage extends DataMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected dataProto(): SignalService.DataMessage {
throw new Error('Not implemented');
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../../protobuf';
export class DeviceUnlinkMessage extends DataMessage {
public ttl(): number {
return 4 * 24 * 60 * 60 * 1000; // 4 days for device unlinking
}
protected dataProto(): SignalService.DataMessage {
throw new Error('Not implemented');
}

@ -3,6 +3,10 @@ import { SignalService } from '../../../../../protobuf';
export class GroupInvitationMessage extends DataMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected dataProto(): SignalService.DataMessage {
throw new Error('Not implemented');
}

@ -4,6 +4,9 @@ import { SignalService } from '../../../../../protobuf';
// this message type is probably to sub divise again.
// should handle quote, body, attachmentsPointer, ... @see DataMessage in compiled.d.ts
export abstract class RegularMessage extends DataMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected dataProto(): SignalService.DataMessage {
throw new Error('Not implemented');

@ -2,6 +2,9 @@ import { ContentMessage } from '../ContentMessage';
import { SignalService } from '../../../../../protobuf';
export abstract class SyncMessage extends ContentMessage {
public ttl(): number {
return this.getDefaultTTL();
}
protected contentProto(): SignalService.Content {
return new SignalService.Content({
@ -10,4 +13,5 @@ export abstract class SyncMessage extends ContentMessage {
}
protected abstract syncProto(): SignalService.SyncMessage;
}

Loading…
Cancel
Save