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/controlMessage/ExpirationTimerUpdateMessag...

76 lines
2.8 KiB
TypeScript

import { SignalService } from '../../../../protobuf';
import { DisappearingMessageType } from '../../../../util/expiringMessages';
import { PubKey } from '../../../types';
import { StringUtils } from '../../../utils';
import { MessageParams } from '../Message';
import { VisibleMessage } from '../visibleMessage/VisibleMessage';
interface ExpirationTimerUpdateMessageParams extends MessageParams {
groupId?: string | PubKey;
syncTarget?: string | PubKey;
expirationType: DisappearingMessageType | null;
expireTimer: number | null;
lastDisappearingMessageChangeTimestamp: number | null;
}
// Note the old disappearing messages used a data message for the expiration time.
// The new ones use properties on the Content Message
// We will remove support for the old one 2 weeks after the release
export class ExpirationTimerUpdateMessage extends VisibleMessage {
public readonly groupId?: PubKey;
public readonly lastDisappearingMessageChangeTimestamp: number | null;
constructor(params: ExpirationTimerUpdateMessageParams) {
super({
timestamp: params.timestamp,
identifier: params.identifier,
expirationType: params.expirationType,
expireTimer: params.expireTimer || undefined,
syncTarget: params.syncTarget ? PubKey.cast(params.syncTarget).key : undefined,
});
this.lastDisappearingMessageChangeTimestamp = params.lastDisappearingMessageChangeTimestamp;
const { groupId } = params;
this.groupId = groupId ? PubKey.cast(groupId) : undefined;
}
public contentProto(): SignalService.Content {
return new SignalService.Content({
dataMessage: this.dataProto(),
expirationType:
this.expirationType === 'deleteAfterSend'
? SignalService.Content.ExpirationType.DELETE_AFTER_SEND
: SignalService.Content.ExpirationType.DELETE_AFTER_READ,
expirationTimer: this.expireTimer,
lastDisappearingMessageChangeTimestamp: this.lastDisappearingMessageChangeTimestamp,
});
}
5 years ago
public dataProto(): SignalService.DataMessage {
const data = super.dataProto();
5 years ago
data.flags = SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE;
// FIXME we shouldn't need this once android recieving refactor is done.
// the envelope stores the groupId for a closed group already.
if (this.groupId) {
5 years ago
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;
5 years ago
data.group = groupMessage;
}
5 years ago
// TODO remove 2 weeks after the release
if (this.expireTimer) {
data.expireTimer = this.expireTimer;
}
return data;
}
}