signal-desktop/ts/textsecure/messageReceiverEvents.ts

471 lines
11 KiB
TypeScript
Raw Normal View History

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 */
import type { PublicKey } from '@signalapp/libsignal-client';
import type { SignalService as Proto } from '../protobuf';
import type { ServiceIdString, AciString } from '../types/ServiceId';
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
import type {
2021-08-05 23:34:49 +00:00
ProcessedEnvelope,
ProcessedDataMessage,
ProcessedSent,
} from './Types.d';
2023-07-26 17:49:27 +00:00
import type { ModifiedContactDetails } from './ContactsParser';
2023-08-09 00:53:06 +00:00
import type { CallEventDetails, CallLogEvent } from '../types/CallDisposition';
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;
senderAci?: AciString;
2021-07-09 19:36:10 +00:00
senderDevice: number;
typing: TypingEventData;
};
export class TypingEvent extends Event {
public readonly sender?: string;
public readonly senderAci?: AciString;
2021-07-09 19:36:10 +00:00
public readonly senderDevice: number;
public readonly typing: TypingEventData;
constructor({ sender, senderAci, senderDevice, typing }: TypingEventConfig) {
2021-07-09 19:36:10 +00:00
super('typing');
this.sender = sender;
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 {
constructor(
2022-08-25 05:04:42 +00:00
public readonly contacts: ReadonlyArray<ModifiedContactDetails>,
public readonly complete: boolean,
public readonly receivedAtCounter: number,
public readonly sentAt: number
) {
2021-07-09 19:36:10 +00:00
super('contactSync');
}
}
// 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) {
super('envelopeUnsealed');
}
}
// Emitted when we queue previously-decrypted events from the cache
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<{
envelopeId: string;
2021-07-09 19:36:10 +00:00
timestamp: number;
envelopeTimestamp: number;
2021-07-09 19:36:10 +00:00
source?: string;
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(
public readonly deliveryReceipt: DeliveryEventData,
confirm: ConfirmCallback
) {
super('delivery', confirm);
}
}
export type DecryptionErrorEventData = Readonly<{
cipherTextBytes?: Uint8Array;
cipherTextType?: number;
contentHint?: number;
groupId?: string;
receivedAtCounter: number;
receivedAtDate: number;
senderDevice: number;
senderAci: AciString;
timestamp: number;
}>;
export class DecryptionErrorEvent extends ConfirmableEvent {
constructor(
public readonly decryptionError: DecryptionErrorEventData,
confirm: ConfirmCallback
) {
super('decryption-error', confirm);
}
}
export type InvalidPlaintextEventData = Readonly<{
senderDevice: number;
senderAci: AciString;
timestamp: number;
}>;
export class InvalidPlaintextEvent extends Event {
constructor(public readonly data: InvalidPlaintextEventData) {
super('invalid-plaintext');
}
}
export type RetryRequestEventData = Readonly<{
groupId?: string;
ratchetKey?: PublicKey;
requesterAci: AciString;
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<{
envelopeId: string;
2021-07-09 19:36:10 +00:00
destination?: string;
destinationServiceId?: ServiceIdString;
2021-07-09 19:36:10 +00:00
timestamp?: number;
serverTimestamp?: number;
device: number | undefined;
2021-07-09 19:36:10 +00:00
unidentifiedStatus: ProcessedSent['unidentifiedStatus'];
message: ProcessedDataMessage;
isRecipientUpdate: boolean;
receivedAtCounter: number;
receivedAtDate: number;
expirationStartTimestamp?: number;
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;
sourceAci?: AciString;
2021-07-09 19:36:10 +00:00
profileKey: string;
}>;
export class ProfileKeyUpdateEvent extends ConfirmableEvent {
constructor(
public readonly data: ProfileKeyUpdateData,
confirm: ConfirmCallback
) {
super('profileKeyUpdate', confirm);
}
}
export type MessageEventData = Readonly<{
envelopeId: string;
2021-07-09 19:36:10 +00:00
source?: string;
sourceAci: AciString;
2021-07-09 19:36:10 +00:00
sourceDevice?: number;
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);
}
}
export type ReadOrViewEventData = Readonly<{
envelopeId: string;
2021-07-09 19:36:10 +00:00
timestamp: number;
envelopeTimestamp: number;
source?: string;
sourceServiceId?: ServiceIdString;
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 {
constructor(
public readonly receipt: ReadOrViewEventData,
confirm: ConfirmCallback
) {
2021-07-09 19:36:10 +00:00
super('read', confirm);
}
}
export class ViewEvent extends ConfirmableEvent {
constructor(
public readonly receipt: ReadOrViewEventData,
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);
}
}
export type ViewOnceOpenSyncOptions = {
2021-07-09 19:36:10 +00:00
source?: string;
sourceAci?: AciString;
2021-07-09 19:36:10 +00:00
timestamp?: number;
};
export class ViewOnceOpenSyncEvent extends ConfirmableEvent {
2021-07-09 19:36:10 +00:00
public readonly source?: string;
public readonly sourceAci?: AciString;
2021-07-09 19:36:10 +00:00
public readonly timestamp?: number;
constructor(
{ source, sourceAci, timestamp }: ViewOnceOpenSyncOptions,
2021-07-09 19:36:10 +00:00
confirm: ConfirmCallback
) {
super('viewOnceOpenSync', confirm);
2021-07-09 19:36:10 +00:00
this.source = source;
this.sourceAci = sourceAci;
2021-07-09 19:36:10 +00:00
this.timestamp = timestamp;
}
}
export type MessageRequestResponseOptions = {
envelopeId: string;
2021-07-09 19:36:10 +00:00
threadE164?: string;
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;
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;
public readonly envelopeId?: string;
2021-07-09 19:36:10 +00:00
constructor(
{
envelopeId,
2021-07-09 19:36:10 +00:00
threadE164,
threadAci,
2021-07-09 19:36:10 +00:00
messageRequestResponseType,
groupId,
groupV2Id,
}: MessageRequestResponseOptions,
confirm: ConfirmCallback
) {
super('messageRequestResponse', confirm);
this.envelopeId = envelopeId;
2021-07-09 19:36:10 +00:00
this.threadE164 = threadE164;
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);
}
}
export type KeysEventData = Readonly<{
storageServiceKey: Uint8Array | undefined;
masterKey: Uint8Array | undefined;
}>;
2021-07-09 19:36:10 +00:00
export class KeysEvent extends ConfirmableEvent {
public readonly storageServiceKey: Uint8Array | undefined;
public readonly masterKey: Uint8Array | undefined;
2021-07-09 19:36:10 +00:00
constructor(
{ storageServiceKey, masterKey }: KeysEventData,
2021-07-09 19:36:10 +00:00
confirm: ConfirmCallback
) {
super('keys', confirm);
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<{
envelopeId: string;
2021-07-09 19:36:10 +00:00
timestamp?: number;
envelopeTimestamp: number;
sender?: string;
senderAci?: AciString;
2021-07-09 19:36:10 +00:00
}>;
export class ReadSyncEvent extends ConfirmableEvent {
constructor(
public readonly read: ReadSyncEventData,
confirm: ConfirmCallback
) {
super('readSync', confirm);
}
}
export type ViewSyncEventData = Readonly<{
envelopeId: string;
timestamp?: number;
envelopeTimestamp: number;
senderE164?: string;
senderAci?: AciString;
}>;
export class ViewSyncEvent extends ConfirmableEvent {
constructor(
public readonly view: ViewSyncEventData,
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;
}>;
export class CallEventSyncEvent extends ConfirmableEvent {
constructor(
public readonly callEvent: CallEventSyncEventData,
confirm: ConfirmCallback
) {
super('callEventSync', confirm);
}
}
2023-08-09 00:53:06 +00:00
export type CallLogEventSyncEventData = Readonly<{
event: CallLogEvent;
timestamp: number;
receivedAtCounter: number;
}>;
export class CallLogEventSyncEvent extends ConfirmableEvent {
constructor(
public readonly callLogEvent: CallLogEventSyncEventData,
confirm: ConfirmCallback
) {
super('callLogEventSync', confirm);
}
}
2022-07-13 23:09:18 +00:00
export type StoryRecipientUpdateData = Readonly<{
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);
}
}