add device unlink and receiptMessage class and tests
parent
81cb1122f8
commit
f1244f3031
@ -1,19 +0,0 @@
|
||||
import { ContentMessage } from './ContentMessage';
|
||||
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(),
|
||||
});
|
||||
}
|
||||
|
||||
protected receiptProto(): SignalService.ReceiptMessage {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { SignalService } from '../../../../../protobuf';
|
||||
import { ReceiptMessage } from './ReceiptMessage';
|
||||
|
||||
export class DeliveryReceiptMessage extends ReceiptMessage {
|
||||
public getReceiptType(): SignalService.ReceiptMessage.Type {
|
||||
return SignalService.ReceiptMessage.Type.DELIVERY;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import { SignalService } from '../../../../../protobuf';
|
||||
import { ReceiptMessage } from './ReceiptMessage';
|
||||
|
||||
export class ReadReceiptMessage extends ReceiptMessage {
|
||||
|
||||
public getReceiptType(): SignalService.ReceiptMessage.Type {
|
||||
return SignalService.ReceiptMessage.Type.READ;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
import { ContentMessage } from '../ContentMessage';
|
||||
import { SignalService } from '../../../../../protobuf';
|
||||
|
||||
export abstract class ReceiptMessage extends ContentMessage {
|
||||
private readonly timestamps: Array<number>;
|
||||
|
||||
constructor(timestamp: number, identifier: string, timestamps: Array<number>) {
|
||||
super(timestamp, identifier);
|
||||
this.timestamps = timestamps;
|
||||
}
|
||||
|
||||
public ttl(): number {
|
||||
return this.getDefaultTTL();
|
||||
}
|
||||
|
||||
public abstract getReceiptType(): SignalService.ReceiptMessage.Type;
|
||||
|
||||
protected contentProto(): SignalService.Content {
|
||||
return new SignalService.Content({
|
||||
receiptMessage: this.receiptProto(),
|
||||
});
|
||||
}
|
||||
|
||||
protected receiptProto(): SignalService.ReceiptMessage {
|
||||
return new SignalService.ReceiptMessage({
|
||||
type: this.getReceiptType(),
|
||||
timestamp: this.timestamps,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
import { expect } from 'chai';
|
||||
import { beforeEach} from 'mocha';
|
||||
|
||||
import { DeliveryReceiptMessage, ReadReceiptMessage } from '../../../session/messages/outgoing';
|
||||
import { SignalService } from '../../../protobuf';
|
||||
|
||||
describe('ReceiptMessage', () => {
|
||||
let readMessage: ReadReceiptMessage;
|
||||
let deliveryMessage: ReadReceiptMessage;
|
||||
let timestamps: Array<number>;
|
||||
|
||||
beforeEach(() => {
|
||||
timestamps = [987654321, 123456789];
|
||||
readMessage = new ReadReceiptMessage(Date.now(), '123456', timestamps);
|
||||
deliveryMessage = new DeliveryReceiptMessage(Date.now(), '123456', timestamps);
|
||||
});
|
||||
|
||||
it('content of a read receipt is correct', () => {
|
||||
const plainText = readMessage.plainTextBuffer();
|
||||
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
|
||||
|
||||
expect(decoded.receiptMessage).to.have.property('type', 1);
|
||||
expect(decoded.receiptMessage.timestamp).to.have.lengthOf(2);
|
||||
expect(decoded.receiptMessage.timestamp[0]).to.have.property('low', timestamps[0]);
|
||||
expect(decoded.receiptMessage.timestamp[1]).to.have.property('low', timestamps[1]);
|
||||
});
|
||||
|
||||
it('content of a delivery receipt is correct', () => {
|
||||
const plainText = deliveryMessage.plainTextBuffer();
|
||||
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
|
||||
|
||||
expect(decoded.receiptMessage).to.have.property('type', 0);
|
||||
expect(decoded.receiptMessage.timestamp).to.have.lengthOf(2);
|
||||
expect(decoded.receiptMessage.timestamp[0]).to.have.property('low', timestamps[0]);
|
||||
expect(decoded.receiptMessage.timestamp[1]).to.have.property('low', timestamps[1]);
|
||||
});
|
||||
|
||||
it('ttl of 1 day', () => {
|
||||
expect(readMessage.ttl()).to.equal(24 * 60 * 60 * 1000);
|
||||
expect(deliveryMessage.ttl()).to.equal(24 * 60 * 60 * 1000);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue