You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/session/messages/outgoing/visibleMessage/ClosedGroupVisibleMessage.ts

56 lines
1.8 KiB
TypeScript

import { SignalService } from '../../../../protobuf';
import { PubKey } from '../../../types';
import { StringUtils } from '../../../utils';
import { VisibleMessage } from './VisibleMessage';
import {
ClosedGroupMessage,
ClosedGroupMessageParams,
} from '../controlMessage/group/ClosedGroupMessage';
interface ClosedGroupVisibleMessageParams extends ClosedGroupMessageParams {
// TODO Do we need strings?
// groupId: string | PubKey;
chatMessage: VisibleMessage;
}
export class ClosedGroupVisibleMessage extends ClosedGroupMessage {
private readonly chatMessage: VisibleMessage;
constructor(params: ClosedGroupVisibleMessageParams) {
super({
timestamp: params.chatMessage.timestamp,
identifier: params.identifier ?? params.chatMessage.identifier,
groupId: params.groupId,
expirationType: params.expirationType,
expireTimer: params.expireTimer,
});
this.chatMessage = params.chatMessage;
if (!params.groupId) {
throw new Error('ClosedGroupVisibleMessage: groupId must be set');
}
}
public dataProto(): SignalService.DataMessage {
//expireTimer is set in the dataProto in this call directly
const dataProto = this.chatMessage.dataProto();
const groupMessage = new SignalService.GroupContext();
const groupIdWithPrefix = PubKey.addTextSecurePrefixIfNeeded(this.groupId.key);
const encoded = StringUtils.encode(groupIdWithPrefix, 'utf8');
const id = new Uint8Array(encoded);
groupMessage.id = id;
groupMessage.type = SignalService.GroupContext.Type.DELIVER;
dataProto.group = groupMessage;
// TODO legacy messages support will be removed in a future release
if (this.expirationType === 'legacy' && this.expireTimer) {
dataProto.expireTimer = this.expireTimer;
}
return dataProto;
}
}