2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2021-07-09 19:36:10 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
/* eslint-disable max-classes-per-file */
|
|
|
|
|
2022-03-24 21:47:21 +00:00
|
|
|
import type { PublicKey } from '@signalapp/libsignal-client';
|
2024-05-28 15:56:00 +00:00
|
|
|
import { z } from 'zod';
|
2021-07-23 17:44:21 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { SignalService as Proto } from '../protobuf';
|
2024-06-17 19:24:39 +00:00
|
|
|
import {
|
|
|
|
type ServiceIdString,
|
|
|
|
type AciString,
|
|
|
|
isPniString,
|
|
|
|
} from '../types/ServiceId';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-08-05 23:34:49 +00:00
|
|
|
ProcessedEnvelope,
|
|
|
|
ProcessedDataMessage,
|
|
|
|
ProcessedSent,
|
|
|
|
} from './Types.d';
|
2023-10-30 16:24:28 +00:00
|
|
|
import type { ContactDetailsWithAvatar } from './ContactsParser';
|
2024-06-26 00:58:38 +00:00
|
|
|
import type {
|
|
|
|
CallEventDetails,
|
|
|
|
CallLogEventDetails,
|
|
|
|
} from '../types/CallDisposition';
|
2024-04-25 17:09:05 +00:00
|
|
|
import type { CallLinkUpdateSyncType } from '../types/CallLink';
|
2024-05-28 15:56:00 +00:00
|
|
|
import { isAciString } from '../util/isAciString';
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
export class EmptyEvent extends Event {
|
|
|
|
constructor() {
|
|
|
|
super('empty');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ProgressEvent extends Event {
|
|
|
|
public readonly count: number;
|
|
|
|
|
|
|
|
constructor({ count }: { count: number }) {
|
|
|
|
super('progress');
|
|
|
|
|
|
|
|
this.count = count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type TypingEventData = Readonly<{
|
|
|
|
typingMessage: Proto.ITypingMessage;
|
|
|
|
timestamp: number;
|
|
|
|
started: boolean;
|
|
|
|
stopped: boolean;
|
|
|
|
groupId?: string;
|
|
|
|
groupV2Id?: string;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export type TypingEventConfig = {
|
|
|
|
sender?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
senderAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
senderDevice: number;
|
|
|
|
typing: TypingEventData;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class TypingEvent extends Event {
|
|
|
|
public readonly sender?: string;
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
public readonly senderAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
public readonly senderDevice: number;
|
|
|
|
|
|
|
|
public readonly typing: TypingEventData;
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
constructor({ sender, senderAci, senderDevice, typing }: TypingEventConfig) {
|
2021-07-09 19:36:10 +00:00
|
|
|
super('typing');
|
|
|
|
|
|
|
|
this.sender = sender;
|
2023-08-10 16:43:33 +00:00
|
|
|
this.senderAci = senderAci;
|
2021-07-09 19:36:10 +00:00
|
|
|
this.senderDevice = senderDevice;
|
|
|
|
this.typing = typing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ErrorEvent extends Event {
|
|
|
|
constructor(public readonly error: Error) {
|
|
|
|
super('error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 05:04:42 +00:00
|
|
|
export class ContactSyncEvent extends Event {
|
2022-06-20 22:43:16 +00:00
|
|
|
constructor(
|
2023-10-30 16:24:28 +00:00
|
|
|
public readonly contacts: ReadonlyArray<ContactDetailsWithAvatar>,
|
2022-08-26 22:26:38 +00:00
|
|
|
public readonly complete: boolean,
|
2022-09-13 00:52:55 +00:00
|
|
|
public readonly receivedAtCounter: number,
|
|
|
|
public readonly sentAt: number
|
2022-06-20 22:43:16 +00:00
|
|
|
) {
|
2021-07-09 19:36:10 +00:00
|
|
|
super('contactSync');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 23:16:17 +00:00
|
|
|
// Emitted right before we do full decrypt on a message, but after Sealed Sender unseal
|
|
|
|
export class EnvelopeUnsealedEvent extends Event {
|
2021-08-05 23:34:49 +00:00
|
|
|
constructor(public readonly envelope: ProcessedEnvelope) {
|
2023-07-05 23:16:17 +00:00
|
|
|
super('envelopeUnsealed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class EnvelopeQueuedEvent extends Event {
|
|
|
|
constructor(public readonly envelope: ProcessedEnvelope) {
|
|
|
|
super('envelopeQueued');
|
2021-08-05 23:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
//
|
|
|
|
// Confirmable events below
|
|
|
|
//
|
|
|
|
|
|
|
|
export type ConfirmCallback = () => void;
|
|
|
|
|
|
|
|
export class ConfirmableEvent extends Event {
|
|
|
|
constructor(type: string, public readonly confirm: ConfirmCallback) {
|
|
|
|
super(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type DeliveryEventData = Readonly<{
|
|
|
|
timestamp: number;
|
|
|
|
source?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
sourceServiceId?: ServiceIdString;
|
2021-07-09 19:36:10 +00:00
|
|
|
sourceDevice?: number;
|
2022-08-15 21:53:33 +00:00
|
|
|
wasSentEncrypted: boolean;
|
2021-07-09 19:36:10 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export class DeliveryEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
2024-06-17 19:24:39 +00:00
|
|
|
public readonly deliveryReceipts: ReadonlyArray<DeliveryEventData>,
|
|
|
|
public readonly envelopeId: string,
|
|
|
|
public readonly envelopeTimestamp: number,
|
2021-07-09 19:36:10 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('delivery', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 21:50:00 +00:00
|
|
|
export type DecryptionErrorEventData = Readonly<{
|
|
|
|
cipherTextBytes?: Uint8Array;
|
|
|
|
cipherTextType?: number;
|
|
|
|
contentHint?: number;
|
|
|
|
groupId?: string;
|
|
|
|
receivedAtCounter: number;
|
|
|
|
receivedAtDate: number;
|
|
|
|
senderDevice: number;
|
2023-08-10 16:43:33 +00:00
|
|
|
senderAci: AciString;
|
2021-10-20 21:50:00 +00:00
|
|
|
timestamp: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class DecryptionErrorEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly decryptionError: DecryptionErrorEventData,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('decryption-error', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-03 20:53:28 +00:00
|
|
|
export type InvalidPlaintextEventData = Readonly<{
|
|
|
|
senderDevice: number;
|
2023-08-10 16:43:33 +00:00
|
|
|
senderAci: AciString;
|
2023-05-03 20:53:28 +00:00
|
|
|
timestamp: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class InvalidPlaintextEvent extends Event {
|
|
|
|
constructor(public readonly data: InvalidPlaintextEventData) {
|
|
|
|
super('invalid-plaintext');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 21:50:00 +00:00
|
|
|
export type RetryRequestEventData = Readonly<{
|
|
|
|
groupId?: string;
|
|
|
|
ratchetKey?: PublicKey;
|
2023-08-10 16:43:33 +00:00
|
|
|
requesterAci: AciString;
|
2021-10-20 21:50:00 +00:00
|
|
|
requesterDevice: number;
|
|
|
|
senderDevice: number;
|
|
|
|
sentAt: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class RetryRequestEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly retryRequest: RetryRequestEventData,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('retry-request', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
export type SentEventData = Readonly<{
|
2023-08-07 16:36:37 +00:00
|
|
|
envelopeId: string;
|
2021-07-09 19:36:10 +00:00
|
|
|
destination?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
destinationServiceId?: ServiceIdString;
|
2021-07-09 19:36:10 +00:00
|
|
|
timestamp?: number;
|
|
|
|
serverTimestamp?: number;
|
2022-11-23 20:52:36 +00:00
|
|
|
device: number | undefined;
|
2021-07-09 19:36:10 +00:00
|
|
|
unidentifiedStatus: ProcessedSent['unidentifiedStatus'];
|
|
|
|
message: ProcessedDataMessage;
|
|
|
|
isRecipientUpdate: boolean;
|
|
|
|
receivedAtCounter: number;
|
|
|
|
receivedAtDate: number;
|
|
|
|
expirationStartTimestamp?: number;
|
2023-08-10 16:43:33 +00:00
|
|
|
storyDistributionListId?: StoryDistributionIdString;
|
2021-07-09 19:36:10 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export class SentEvent extends ConfirmableEvent {
|
|
|
|
constructor(public readonly data: SentEventData, confirm: ConfirmCallback) {
|
|
|
|
super('sent', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ProfileKeyUpdateData = Readonly<{
|
|
|
|
source?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
sourceAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
profileKey: string;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class ProfileKeyUpdateEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly data: ProfileKeyUpdateData,
|
2024-06-10 20:21:44 +00:00
|
|
|
public readonly reason: string,
|
2021-07-09 19:36:10 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('profileKeyUpdate', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type MessageEventData = Readonly<{
|
2023-08-07 16:36:37 +00:00
|
|
|
envelopeId: string;
|
2021-07-09 19:36:10 +00:00
|
|
|
source?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
sourceAci: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
sourceDevice?: number;
|
2023-08-10 16:43:33 +00:00
|
|
|
destinationServiceId: ServiceIdString;
|
2021-07-09 19:36:10 +00:00
|
|
|
timestamp: number;
|
|
|
|
serverGuid?: string;
|
|
|
|
serverTimestamp?: number;
|
|
|
|
unidentifiedDeliveryReceived: boolean;
|
|
|
|
message: ProcessedDataMessage;
|
|
|
|
receivedAtCounter: number;
|
|
|
|
receivedAtDate: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class MessageEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly data: MessageEventData,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('message', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 15:42:25 +00:00
|
|
|
export type ReadOrViewEventData = Readonly<{
|
2021-07-09 19:36:10 +00:00
|
|
|
timestamp: number;
|
|
|
|
source?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
sourceServiceId?: ServiceIdString;
|
2021-07-15 23:48:09 +00:00
|
|
|
sourceDevice?: number;
|
2022-08-15 21:53:33 +00:00
|
|
|
wasSentEncrypted: true;
|
2021-07-09 19:36:10 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export class ReadEvent extends ConfirmableEvent {
|
2021-07-27 15:42:25 +00:00
|
|
|
constructor(
|
2024-06-17 19:24:39 +00:00
|
|
|
public readonly receipts: ReadonlyArray<ReadOrViewEventData>,
|
|
|
|
public readonly envelopeId: string,
|
|
|
|
public readonly envelopeTimestamp: number,
|
2021-07-27 15:42:25 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
2021-07-09 19:36:10 +00:00
|
|
|
super('read', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 15:42:25 +00:00
|
|
|
export class ViewEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
2024-06-17 19:24:39 +00:00
|
|
|
public readonly receipts: ReadonlyArray<ReadOrViewEventData>,
|
|
|
|
public readonly envelopeId: string,
|
|
|
|
public readonly envelopeTimestamp: number,
|
2021-07-27 15:42:25 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('view', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
export class ConfigurationEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly configuration: Proto.SyncMessage.IConfiguration,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('configuration', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 17:07:53 +00:00
|
|
|
export type ViewOnceOpenSyncOptions = {
|
2021-07-09 19:36:10 +00:00
|
|
|
source?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
sourceAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
timestamp?: number;
|
|
|
|
};
|
|
|
|
|
2021-07-22 17:07:53 +00:00
|
|
|
export class ViewOnceOpenSyncEvent extends ConfirmableEvent {
|
2021-07-09 19:36:10 +00:00
|
|
|
public readonly source?: string;
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
public readonly sourceAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
public readonly timestamp?: number;
|
|
|
|
|
|
|
|
constructor(
|
2023-08-10 16:43:33 +00:00
|
|
|
{ source, sourceAci, timestamp }: ViewOnceOpenSyncOptions,
|
2021-07-09 19:36:10 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
2021-07-22 17:07:53 +00:00
|
|
|
super('viewOnceOpenSync', confirm);
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
this.source = source;
|
2023-08-10 16:43:33 +00:00
|
|
|
this.sourceAci = sourceAci;
|
2021-07-09 19:36:10 +00:00
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type MessageRequestResponseOptions = {
|
2023-08-21 20:08:27 +00:00
|
|
|
envelopeId: string;
|
2021-07-09 19:36:10 +00:00
|
|
|
threadE164?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
threadAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
messageRequestResponseType: Proto.SyncMessage.IMessageRequestResponse['type'];
|
|
|
|
groupId?: string;
|
|
|
|
groupV2Id?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class MessageRequestResponseEvent extends ConfirmableEvent {
|
|
|
|
public readonly threadE164?: string;
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
public readonly threadAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
public readonly messageRequestResponseType?: MessageRequestResponseOptions['messageRequestResponseType'];
|
|
|
|
|
|
|
|
public readonly groupId?: string;
|
|
|
|
|
|
|
|
public readonly groupV2Id?: string;
|
|
|
|
|
2023-08-21 20:08:27 +00:00
|
|
|
public readonly envelopeId?: string;
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
constructor(
|
|
|
|
{
|
2023-08-21 20:08:27 +00:00
|
|
|
envelopeId,
|
2021-07-09 19:36:10 +00:00
|
|
|
threadE164,
|
2023-08-10 16:43:33 +00:00
|
|
|
threadAci,
|
2021-07-09 19:36:10 +00:00
|
|
|
messageRequestResponseType,
|
|
|
|
groupId,
|
|
|
|
groupV2Id,
|
|
|
|
}: MessageRequestResponseOptions,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('messageRequestResponse', confirm);
|
|
|
|
|
2023-08-21 20:08:27 +00:00
|
|
|
this.envelopeId = envelopeId;
|
2021-07-09 19:36:10 +00:00
|
|
|
this.threadE164 = threadE164;
|
2023-08-10 16:43:33 +00:00
|
|
|
this.threadAci = threadAci;
|
2021-07-09 19:36:10 +00:00
|
|
|
this.messageRequestResponseType = messageRequestResponseType;
|
|
|
|
this.groupId = groupId;
|
|
|
|
this.groupV2Id = groupV2Id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class FetchLatestEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly eventType: Proto.SyncMessage.IFetchLatest['type'],
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('fetchLatest', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-12 19:42:24 +00:00
|
|
|
export type KeysEventData = Readonly<{
|
|
|
|
storageServiceKey: Uint8Array | undefined;
|
|
|
|
masterKey: Uint8Array | undefined;
|
|
|
|
}>;
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
export class KeysEvent extends ConfirmableEvent {
|
2023-10-12 19:42:24 +00:00
|
|
|
public readonly storageServiceKey: Uint8Array | undefined;
|
|
|
|
public readonly masterKey: Uint8Array | undefined;
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
constructor(
|
2023-10-12 19:42:24 +00:00
|
|
|
{ storageServiceKey, masterKey }: KeysEventData,
|
2021-07-09 19:36:10 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('keys', confirm);
|
2023-10-12 19:42:24 +00:00
|
|
|
|
|
|
|
this.storageServiceKey = storageServiceKey;
|
|
|
|
this.masterKey = masterKey;
|
2021-07-09 19:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type StickerPackEventData = Readonly<{
|
|
|
|
id?: string;
|
|
|
|
key?: string;
|
|
|
|
isInstall: boolean;
|
|
|
|
isRemove: boolean;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class StickerPackEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly stickerPacks: ReadonlyArray<StickerPackEventData>,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('sticker-pack', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ReadSyncEventData = Readonly<{
|
2023-08-21 20:08:27 +00:00
|
|
|
envelopeId: string;
|
2021-07-09 19:36:10 +00:00
|
|
|
timestamp?: number;
|
|
|
|
envelopeTimestamp: number;
|
|
|
|
sender?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
senderAci?: AciString;
|
2021-07-09 19:36:10 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export class ReadSyncEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
2024-06-17 19:24:39 +00:00
|
|
|
public readonly reads: ReadonlyArray<ReadSyncEventData>,
|
|
|
|
public readonly envelopeId: string,
|
|
|
|
public readonly envelopeTimestamp: number,
|
2021-07-09 19:36:10 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('readSync', confirm);
|
|
|
|
}
|
|
|
|
}
|
2021-08-12 18:15:55 +00:00
|
|
|
|
|
|
|
export type ViewSyncEventData = Readonly<{
|
|
|
|
timestamp?: number;
|
|
|
|
senderE164?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
senderAci?: AciString;
|
2021-08-12 18:15:55 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export class ViewSyncEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
2024-06-17 19:24:39 +00:00
|
|
|
public readonly views: ReadonlyArray<ViewSyncEventData>,
|
|
|
|
public readonly envelopeId: string,
|
|
|
|
public readonly envelopeTimestamp: number,
|
2021-08-12 18:15:55 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('viewSync', confirm);
|
|
|
|
}
|
|
|
|
}
|
2022-07-13 23:09:18 +00:00
|
|
|
|
2023-01-10 00:52:01 +00:00
|
|
|
export type CallEventSyncEventData = Readonly<{
|
2023-08-09 00:53:06 +00:00
|
|
|
callEventDetails: CallEventDetails;
|
2023-01-10 00:52:01 +00:00
|
|
|
receivedAtCounter: number;
|
2024-05-28 05:13:09 +00:00
|
|
|
receivedAtMS: number;
|
2023-01-10 00:52:01 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export class CallEventSyncEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly callEvent: CallEventSyncEventData,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('callEventSync', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 17:09:05 +00:00
|
|
|
export type CallLinkUpdateSyncEventData = Readonly<{
|
|
|
|
type: CallLinkUpdateSyncType;
|
|
|
|
rootKey: Uint8Array | undefined;
|
|
|
|
adminKey: Uint8Array | undefined;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class CallLinkUpdateSyncEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly callLinkUpdate: CallLinkUpdateSyncEventData,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('callLinkUpdateSync', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-28 15:56:00 +00:00
|
|
|
const messageToDeleteSchema = z.union([
|
|
|
|
z.object({
|
|
|
|
type: z.literal('aci').readonly(),
|
|
|
|
authorAci: z.string().refine(isAciString),
|
|
|
|
sentAt: z.number(),
|
|
|
|
}),
|
|
|
|
z.object({
|
|
|
|
type: z.literal('e164').readonly(),
|
|
|
|
authorE164: z.string(),
|
|
|
|
sentAt: z.number(),
|
|
|
|
}),
|
2024-06-17 19:24:39 +00:00
|
|
|
z.object({
|
|
|
|
type: z.literal('pni').readonly(),
|
|
|
|
authorPni: z.string().refine(isPniString),
|
|
|
|
sentAt: z.number(),
|
|
|
|
}),
|
2024-05-28 15:56:00 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
export type MessageToDelete = z.infer<typeof messageToDeleteSchema>;
|
|
|
|
|
|
|
|
const conversationToDeleteSchema = z.union([
|
|
|
|
z.object({
|
|
|
|
type: z.literal('aci').readonly(),
|
|
|
|
aci: z.string().refine(isAciString),
|
|
|
|
}),
|
|
|
|
z.object({
|
|
|
|
type: z.literal('e164').readonly(),
|
|
|
|
e164: z.string(),
|
|
|
|
}),
|
2024-06-17 19:24:39 +00:00
|
|
|
z.object({
|
|
|
|
type: z.literal('group').readonly(),
|
|
|
|
groupId: z.string(),
|
|
|
|
}),
|
|
|
|
z.object({
|
|
|
|
type: z.literal('pni').readonly(),
|
|
|
|
pni: z.string().refine(isPniString),
|
|
|
|
}),
|
2024-05-28 15:56:00 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
export type ConversationToDelete = z.infer<typeof conversationToDeleteSchema>;
|
|
|
|
|
|
|
|
export const deleteMessageSchema = z.object({
|
|
|
|
type: z.literal('delete-message').readonly(),
|
|
|
|
conversation: conversationToDeleteSchema,
|
|
|
|
message: messageToDeleteSchema,
|
|
|
|
timestamp: z.number(),
|
|
|
|
});
|
|
|
|
export type DeleteMessageSyncTarget = z.infer<typeof deleteMessageSchema>;
|
|
|
|
export const deleteConversationSchema = z.object({
|
|
|
|
type: z.literal('delete-conversation').readonly(),
|
|
|
|
conversation: conversationToDeleteSchema,
|
|
|
|
mostRecentMessages: z.array(messageToDeleteSchema),
|
2024-06-24 17:49:36 +00:00
|
|
|
mostRecentNonExpiringMessages: z.array(messageToDeleteSchema).optional(),
|
2024-05-28 15:56:00 +00:00
|
|
|
isFullDelete: z.boolean(),
|
|
|
|
timestamp: z.number(),
|
|
|
|
});
|
|
|
|
export const deleteLocalConversationSchema = z.object({
|
|
|
|
type: z.literal('delete-local-conversation').readonly(),
|
|
|
|
conversation: conversationToDeleteSchema,
|
|
|
|
timestamp: z.number(),
|
|
|
|
});
|
2024-06-21 22:35:18 +00:00
|
|
|
export const deleteAttachmentSchema = z.object({
|
|
|
|
type: z.literal('delete-single-attachment').readonly(),
|
|
|
|
conversation: conversationToDeleteSchema,
|
|
|
|
message: messageToDeleteSchema,
|
|
|
|
clientUuid: z.string().optional(),
|
|
|
|
fallbackDigest: z.string().optional(),
|
|
|
|
fallbackPlaintextHash: z.string().optional(),
|
|
|
|
timestamp: z.number(),
|
|
|
|
});
|
2024-05-28 15:56:00 +00:00
|
|
|
export const deleteForMeSyncTargetSchema = z.union([
|
|
|
|
deleteMessageSchema,
|
|
|
|
deleteConversationSchema,
|
|
|
|
deleteLocalConversationSchema,
|
2024-06-21 22:35:18 +00:00
|
|
|
deleteAttachmentSchema,
|
2024-05-28 15:56:00 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
export type DeleteForMeSyncTarget = z.infer<typeof deleteForMeSyncTargetSchema>;
|
|
|
|
|
|
|
|
export type DeleteForMeSyncEventData = ReadonlyArray<DeleteForMeSyncTarget>;
|
|
|
|
|
|
|
|
export class DeleteForMeSyncEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly deleteForMeSync: DeleteForMeSyncEventData,
|
|
|
|
public readonly timestamp: number,
|
|
|
|
public readonly envelopeId: string,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('deleteForMeSync', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
export type CallLogEventSyncEventData = Readonly<{
|
2024-06-26 00:58:38 +00:00
|
|
|
callLogEventDetails: CallLogEventDetails;
|
2023-08-09 00:53:06 +00:00
|
|
|
receivedAtCounter: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class CallLogEventSyncEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
2024-06-26 00:58:38 +00:00
|
|
|
public readonly data: CallLogEventSyncEventData,
|
2023-08-09 00:53:06 +00:00
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('callLogEventSync', confirm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 23:09:18 +00:00
|
|
|
export type StoryRecipientUpdateData = Readonly<{
|
2023-08-10 16:43:33 +00:00
|
|
|
destinationServiceId: ServiceIdString;
|
2022-07-13 23:09:18 +00:00
|
|
|
storyMessageRecipients: Array<Proto.SyncMessage.Sent.IStoryMessageRecipient>;
|
|
|
|
timestamp: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export class StoryRecipientUpdateEvent extends ConfirmableEvent {
|
|
|
|
constructor(
|
|
|
|
public readonly data: StoryRecipientUpdateData,
|
|
|
|
confirm: ConfirmCallback
|
|
|
|
) {
|
|
|
|
super('storyRecipientUpdate', confirm);
|
|
|
|
}
|
|
|
|
}
|