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.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { SignalService } from '../../../../protobuf';
|
|
import { PubKey } from '../../../types';
|
|
import { StringUtils } from '../../../utils';
|
|
import { VisibleMessage } from './VisibleMessage';
|
|
import { ClosedGroupMessage } from '../controlMessage/group/ClosedGroupMessage';
|
|
import { DisappearingMessageType } from '../../../../util/expiringMessages';
|
|
|
|
interface ClosedGroupVisibleMessageParams {
|
|
identifier?: string;
|
|
groupId: string | PubKey;
|
|
expirationType?: DisappearingMessageType;
|
|
expireTimer?: number;
|
|
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;
|
|
|
|
return dataProto;
|
|
}
|
|
}
|