add GroupInvitationMessage and tests

pull/1151/head
Audric Ackermann 5 years ago
parent 56d744fda9
commit 9ea95e59fa
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1,13 +1,39 @@
import { DataMessage } from './DataMessage';
import { SignalService } from '../../../../../protobuf';
interface GroupInvitationMessageParams {
timestamp: number;
identifier: string;
serverAddress: string;
channelId: number;
serverName: string;
}
export class GroupInvitationMessage extends DataMessage {
private readonly serverAddress: string;
private readonly channelId: number;
private readonly serverName: string;
constructor(params: GroupInvitationMessageParams) {
super({ timestamp: params.timestamp, identifier: params.identifier });
this.serverAddress = params.serverAddress;
this.channelId = params.channelId;
this.serverName = params.serverName;
}
public ttl(): number {
return this.getDefaultTTL();
}
protected dataProto(): SignalService.DataMessage {
throw new Error('Not implemented');
const groupInvitation = new SignalService.DataMessage.GroupInvitation({
serverAddress: this.serverAddress,
channelId: this.channelId,
serverName: this.serverName,
});
return new SignalService.DataMessage({
groupInvitation,
});
}
}

@ -3,6 +3,7 @@ import { SignalService } from '../../../../../protobuf';
// this message type is probably to sub divise again.
// should handle quote, body, attachmentsPointer, ... @see DataMessage in compiled.d.ts
// Also, find a better name
export abstract class RegularMessage extends DataMessage {
public ttl(): number {
return this.getDefaultTTL();

@ -42,5 +42,5 @@ export {
ClosedGroupMessage,
DeviceUnlinkMessage,
GroupInvitationMessage,
RegularMessage
RegularMessage,
};

@ -1,7 +1,7 @@
import { expect } from 'chai';
import { beforeEach} from 'mocha';
import { DeviceLinkGrantMessage, DeviceLinkRequestMessage, ContentMessage } from '../../../session/messages/outgoing';
import { DeviceLinkGrantMessage, DeviceLinkRequestMessage } from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
import { LokiProfile } from '../../../types/Message';

@ -0,0 +1,37 @@
import { expect } from 'chai';
import { beforeEach} from 'mocha';
import { GroupInvitationMessage } from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
describe('GroupInvitationMessage', () => {
let message: GroupInvitationMessage;
const timestamp = Date.now();
const identifier = '123456';
const serverAddress = 'http://localhost';
const channelId = 1;
const serverName = 'test';
beforeEach(() => {
message = new GroupInvitationMessage({
timestamp,
identifier,
serverAddress,
channelId,
serverName,
});
});
it('dataMessage.groupInvitation has serverAddress, channelId, and serverName set', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
expect(decoded.dataMessage.groupInvitation).to.have.property('serverAddress', serverAddress);
expect(decoded.dataMessage.groupInvitation).to.have.property('channelId', channelId);
expect(decoded.dataMessage.groupInvitation).to.have.property('serverName', serverName);
});
it('ttl of 1 day', () => {
expect(message.ttl()).to.equal(24 * 60 * 60 * 1000);
});
});
Loading…
Cancel
Save