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/content/data/groupv2/ClosedGroupV2ChatMessage.ts

50 lines
1.5 KiB
TypeScript

import { SignalService } from '../../../../../../protobuf';
import { ChatMessage } from '../ChatMessage';
import { ClosedGroupV2Message } from './ClosedGroupV2Message';
import { PubKey } from '../../../../../types';
import { Constants } from '../../../../..';
import { StringUtils } from '../../../../../utils';
interface ClosedGroupV2ChatMessageParams {
identifier?: string;
groupId: string | PubKey;
chatMessage: ChatMessage;
}
export class ClosedGroupV2ChatMessage extends ClosedGroupV2Message {
private readonly chatMessage: ChatMessage;
constructor(params: ClosedGroupV2ChatMessageParams) {
super({
timestamp: params.chatMessage.timestamp,
5 years ago
identifier: params.identifier ?? params.chatMessage.identifier,
groupId: params.groupId,
expireTimer: params.chatMessage.expireTimer || 0,
});
this.chatMessage = params.chatMessage;
}
public ttl(): number {
return Constants.TTL_DEFAULT.REGULAR_MESSAGE;
}
5 years ago
public dataProto(): SignalService.DataMessage {
const dataProto = this.chatMessage.dataProto();
5 years ago
if (this.groupId) {
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;
}
return dataProto;
5 years ago
}
}