// Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable camelcase */ /* eslint-disable @typescript-eslint/no-explicit-any */ import type { ConversationAttributesType, MessageAttributesType, SenderKeyInfoType, } from '../model-types.d'; import type { StoredJob } from '../jobs/types'; import type { ReactionType } from '../types/Reactions'; import type { ConversationColorType, CustomColorType } from '../types/Colors'; import type { ProcessGroupCallRingRequestResult } from '../types/Calling'; import type { StorageAccessType } from '../types/Storage.d'; import type { AttachmentType } from '../types/Attachment'; import type { BodyRangesType } from '../types/Util'; import type { QualifiedAddressStringType } from '../types/QualifiedAddress'; import type { UUIDStringType } from '../types/UUID'; import type { BadgeType } from '../badges/types'; import type { RemoveAllConfiguration } from '../types/RemoveAllConfiguration'; import type { LoggerType } from '../types/Logging'; export type AttachmentDownloadJobTypeType = | 'long-message' | 'attachment' | 'preview' | 'contact' | 'quote' | 'sticker'; export type AttachmentDownloadJobType = { attachment: AttachmentType; attempts: number; id: string; index: number; messageId: string; pending: number; timestamp: number; type: AttachmentDownloadJobTypeType; }; export type MessageMetricsType = { id: string; // eslint-disable-next-line camelcase received_at: number; // eslint-disable-next-line camelcase sent_at: number; }; export type ConversationMetricsType = { oldest?: MessageMetricsType; newest?: MessageMetricsType; oldestUnread?: MessageMetricsType; totalUnread: number; }; export type ConversationType = ConversationAttributesType; export type EmojiType = { shortName: string; lastUsage: number; }; export type IdentityKeyType = { firstUse: boolean; id: UUIDStringType | `conversation:${string}`; nonblockingApproval: boolean; publicKey: Uint8Array; timestamp: number; verified: number; }; export type IdentityKeyIdType = IdentityKeyType['id']; export type ItemKeyType = keyof StorageAccessType; export type AllItemsType = Partial; export type ItemType = { id: K; value: StorageAccessType[K]; }; export type MessageType = MessageAttributesType; export type MessageTypeUnhydrated = { json: string; }; export type PreKeyType = { id: `${UUIDStringType}:${number}`; keyId: number; ourUuid: UUIDStringType; privateKey: Uint8Array; publicKey: Uint8Array; }; export type PreKeyIdType = PreKeyType['id']; export type ServerSearchResultMessageType = { json: string; snippet: string; }; export type ClientSearchResultMessageType = MessageType & { json: string; bodyRanges: BodyRangesType; snippet: string; }; export type SentProtoType = { contentHint: number; proto: Uint8Array; timestamp: number; }; export type SentProtoWithMessageIdsType = SentProtoType & { messageIds: Array; }; export type SentRecipientsType = Record>; export type SentMessagesType = Array; // These two are for test only export type SentRecipientsDBType = { payloadId: number; recipientUuid: string; deviceId: number; }; export type SentMessageDBType = { payloadId: number; messageId: string; }; export type SenderKeyType = { // Primary key id: `${QualifiedAddressStringType}--${string}`; // These two are combined into one string to give us the final id senderId: string; distributionId: string; // Raw data to serialize/deserialize into signal-client SenderKeyRecord data: Uint8Array; lastUpdatedDate: number; }; export type SenderKeyIdType = SenderKeyType['id']; export type SessionType = { id: QualifiedAddressStringType; ourUuid: UUIDStringType; uuid: UUIDStringType; conversationId: string; deviceId: number; record: string; version?: number; }; export type SessionIdType = SessionType['id']; export type SignedPreKeyType = { confirmed: boolean; // eslint-disable-next-line camelcase created_at: number; ourUuid: UUIDStringType; id: `${UUIDStringType}:${number}`; keyId: number; privateKey: Uint8Array; publicKey: Uint8Array; }; export type SignedPreKeyIdType = SignedPreKeyType['id']; export type StickerType = Readonly<{ id: number; packId: string; emoji?: string; isCoverOnly: boolean; lastUsed?: number; path: string; width: number; height: number; }>; export const StickerPackStatuses = [ 'known', 'ephemeral', 'downloaded', 'installed', 'pending', 'error', ] as const; export type StickerPackStatusType = typeof StickerPackStatuses[number]; export type StickerPackType = Readonly<{ id: string; key: string; attemptedStatus?: 'downloaded' | 'installed' | 'ephemeral'; author: string; coverStickerId: number; createdAt: number; downloadAttempts: number; installedAt?: number; lastUsed?: number; status: StickerPackStatusType; stickerCount: number; stickers: Record; title: string; }>; export type UnprocessedType = { id: string; timestamp: number; version: number; attempts: number; envelope?: string; source?: string; sourceUuid?: string; sourceDevice?: number; destinationUuid?: string; serverGuid?: string; serverTimestamp?: number; decrypted?: string; }; export type UnprocessedUpdateType = { source?: string; sourceUuid?: string; sourceDevice?: number; serverGuid?: string; serverTimestamp?: number; decrypted?: string; }; export type LastConversationMessagesType = { activity?: MessageType; preview?: MessageType; hasUserInitiatedMessages: boolean; }; export type DeleteSentProtoRecipientOptionsType = Readonly<{ timestamp: number; recipientUuid: string; deviceId: number; }>; export type StoryDistributionType = Readonly<{ id: UUIDStringType; name: string; avatarUrlPath: string; avatarKey: Uint8Array; senderKeyInfo: SenderKeyInfoType | undefined; }>; export type StoryDistributionMemberType = Readonly<{ listId: UUIDStringType; uuid: UUIDStringType; }>; export type StoryDistributionWithMembersType = Readonly< { members: Array; } & StoryDistributionType >; export type StoryReadType = Readonly<{ authorId: UUIDStringType; conversationId: UUIDStringType; storyId: UUIDStringType; storyReadDate: number; }>; export type DataInterface = { close: () => Promise; removeDB: () => Promise; removeIndexedDBFiles: () => Promise; createOrUpdateIdentityKey: (data: IdentityKeyType) => Promise; getIdentityKeyById: ( id: IdentityKeyIdType ) => Promise; bulkAddIdentityKeys: (array: Array) => Promise; removeIdentityKeyById: (id: IdentityKeyIdType) => Promise; removeAllIdentityKeys: () => Promise; getAllIdentityKeys: () => Promise>; createOrUpdatePreKey: (data: PreKeyType) => Promise; getPreKeyById: (id: PreKeyIdType) => Promise; bulkAddPreKeys: (array: Array) => Promise; removePreKeyById: (id: PreKeyIdType) => Promise; removeAllPreKeys: () => Promise; getAllPreKeys: () => Promise>; createOrUpdateSignedPreKey: (data: SignedPreKeyType) => Promise; getSignedPreKeyById: ( id: SignedPreKeyIdType ) => Promise; bulkAddSignedPreKeys: (array: Array) => Promise; removeSignedPreKeyById: (id: SignedPreKeyIdType) => Promise; removeAllSignedPreKeys: () => Promise; getAllSignedPreKeys: () => Promise>; createOrUpdateItem(data: ItemType): Promise; getItemById(id: K): Promise | undefined>; removeItemById: (id: ItemKeyType) => Promise; removeAllItems: () => Promise; getAllItems: () => Promise; createOrUpdateSenderKey: (key: SenderKeyType) => Promise; getSenderKeyById: (id: SenderKeyIdType) => Promise; removeAllSenderKeys: () => Promise; getAllSenderKeys: () => Promise>; removeSenderKeyById: (id: SenderKeyIdType) => Promise; insertSentProto: ( proto: SentProtoType, options: { recipients: SentRecipientsType; messageIds: SentMessagesType; } ) => Promise; deleteSentProtosOlderThan: (timestamp: number) => Promise; deleteSentProtoByMessageId: (messageId: string) => Promise; insertProtoRecipients: (options: { id: number; recipientUuid: string; deviceIds: Array; }) => Promise; deleteSentProtoRecipient: ( options: | DeleteSentProtoRecipientOptionsType | ReadonlyArray ) => Promise; getSentProtoByRecipient: (options: { now: number; recipientUuid: string; timestamp: number; }) => Promise; removeAllSentProtos: () => Promise; getAllSentProtos: () => Promise>; // Test-only _getAllSentProtoRecipients: () => Promise>; _getAllSentProtoMessageIds: () => Promise>; createOrUpdateSession: (data: SessionType) => Promise; createOrUpdateSessions: (array: Array) => Promise; commitDecryptResult(options: { senderKeys: Array; sessions: Array; unprocessed: Array; }): Promise; bulkAddSessions: (array: Array) => Promise; removeSessionById: (id: SessionIdType) => Promise; removeSessionsByConversation: (conversationId: string) => Promise; removeAllSessions: () => Promise; getAllSessions: () => Promise>; eraseStorageServiceStateFromConversations: () => Promise; getConversationCount: () => Promise; saveConversation: (data: ConversationType) => Promise; saveConversations: (array: Array) => Promise; getConversationById: (id: string) => Promise; // updateConversation is a normal data method on Server, a sync batch-add on Client updateConversations: (array: Array) => Promise; // removeConversation handles either one id or an array on Server, and one id on Client updateAllConversationColors: ( conversationColor?: ConversationColorType, customColorData?: { id: string; value: CustomColorType; } ) => Promise; getAllConversations: () => Promise>; getAllConversationIds: () => Promise>; getAllGroupsInvolvingUuid: ( id: UUIDStringType ) => Promise>; searchConversations: ( query: string, options?: { limit?: number } ) => Promise>; // searchMessages is JSON on server, full message on Client // searchMessagesInConversation is JSON on server, full message on Client getMessageCount: (conversationId?: string) => Promise; saveMessage: ( data: MessageType, options: { jobToInsert?: StoredJob; forceSave?: boolean; ourUuid: UUIDStringType; } ) => Promise; saveMessages: ( arrayOfMessages: Array, options: { forceSave?: boolean; ourUuid: UUIDStringType } ) => Promise; removeMessage: (id: string) => Promise; removeMessages: (ids: Array) => Promise; getTotalUnreadForConversation: ( conversationId: string, storyId?: UUIDStringType ) => Promise; getUnreadByConversationAndMarkRead: (options: { conversationId: string; newestUnreadAt: number; readAt?: number; storyId?: UUIDStringType; }) => Promise< Array< Pick > >; getUnreadReactionsAndMarkRead: (options: { conversationId: string; newestUnreadAt: number; storyId?: UUIDStringType; }) => Promise< Array< Pick > >; markReactionAsRead: ( targetAuthorUuid: string, targetTimestamp: number ) => Promise; removeReactionFromConversation: (reaction: { emoji: string; fromId: string; targetAuthorUuid: string; targetTimestamp: number; }) => Promise; addReaction: (reactionObj: ReactionType) => Promise; _getAllReactions: () => Promise>; _removeAllReactions: () => Promise; getMessageBySender: (options: { source: string; sourceUuid: string; sourceDevice: number; sent_at: number; }) => Promise; getMessageById: (id: string) => Promise; getMessagesById: (messageIds: Array) => Promise>; _getAllMessages: () => Promise>; _removeAllMessages: () => Promise; getAllMessageIds: () => Promise>; getMessagesBySentAt: (sentAt: number) => Promise>; getExpiredMessages: () => Promise>; getMessagesUnexpectedlyMissingExpirationStartTimestamp: () => Promise< Array >; getSoonestMessageExpiry: () => Promise; getNextTapToViewMessageTimestampToAgeOut: () => Promise; getTapToViewMessagesNeedingErase: () => Promise>; // getOlderMessagesByConversation is JSON on server, full message on Client getOlderStories: (options: { conversationId?: string; limit?: number; receivedAt?: number; sentAt?: number; sourceUuid?: string; }) => Promise>; // getNewerMessagesByConversation is JSON on server, full message on Client getMessageMetricsForConversation: ( conversationId: string, storyId?: UUIDStringType ) => Promise; // getConversationRangeCenteredOnMessage is JSON on server, full message on client getLastConversationMessages: (options: { conversationId: string; ourUuid: UUIDStringType; }) => Promise; hasGroupCallHistoryMessage: ( conversationId: string, eraId: string ) => Promise; migrateConversationMessages: ( obsoleteId: string, currentId: string ) => Promise; getUnprocessedCount: () => Promise; getAllUnprocessed: () => Promise>; updateUnprocessedWithData: ( id: string, data: UnprocessedUpdateType ) => Promise; updateUnprocessedsWithData: ( array: Array<{ id: string; data: UnprocessedUpdateType }> ) => Promise; getUnprocessedById: (id: string) => Promise; removeUnprocessed: (id: string | Array) => Promise; removeAllUnprocessed: () => Promise; getNextAttachmentDownloadJobs: ( limit?: number, options?: { timestamp?: number } ) => Promise>; saveAttachmentDownloadJob: (job: AttachmentDownloadJobType) => Promise; resetAttachmentDownloadPending: () => Promise; setAttachmentDownloadJobPending: ( id: string, pending: boolean ) => Promise; removeAttachmentDownloadJob: (id: string) => Promise; removeAllAttachmentDownloadJobs: () => Promise; createOrUpdateStickerPack: (pack: StickerPackType) => Promise; updateStickerPackStatus: ( id: string, status: StickerPackStatusType, options?: { timestamp: number } ) => Promise; createOrUpdateSticker: (sticker: StickerType) => Promise; updateStickerLastUsed: ( packId: string, stickerId: number, lastUsed: number ) => Promise; addStickerPackReference: (messageId: string, packId: string) => Promise; deleteStickerPackReference: ( messageId: string, packId: string ) => Promise | undefined>; getStickerCount: () => Promise; deleteStickerPack: (packId: string) => Promise>; getAllStickerPacks: () => Promise>; getAllStickers: () => Promise>; getRecentStickers: (options?: { limit?: number; }) => Promise>; clearAllErrorStickerPackAttempts: () => Promise; updateEmojiUsage: (shortName: string, timeUsed?: number) => Promise; getRecentEmojis: (limit?: number) => Promise>; getAllBadges(): Promise>; updateOrCreateBadges(badges: ReadonlyArray): Promise; badgeImageFileDownloaded(url: string, localPath: string): Promise; _getAllStoryDistributions(): Promise>; _getAllStoryDistributionMembers(): Promise< Array >; _deleteAllStoryDistributions(): Promise; createNewStoryDistribution( distribution: StoryDistributionWithMembersType ): Promise; getAllStoryDistributionsWithMembers(): Promise< Array >; modifyStoryDistribution(distribution: StoryDistributionType): Promise; modifyStoryDistributionMembers( id: string, options: { toAdd: Array; toRemove: Array; } ): Promise; deleteStoryDistribution(id: UUIDStringType): Promise; _getAllStoryReads(): Promise>; _deleteAllStoryReads(): Promise; addNewStoryRead(read: StoryReadType): Promise; getLastStoryReadsForAuthor(options: { authorId: UUIDStringType; conversationId?: UUIDStringType; limit?: number; }): Promise>; removeAll: () => Promise; removeAllConfiguration: (type?: RemoveAllConfiguration) => Promise; getMessagesNeedingUpgrade: ( limit: number, options: { maxVersion: number } ) => Promise>; getMessagesWithVisualMediaAttachments: ( conversationId: string, options: { limit: number } ) => Promise>; getMessagesWithFileAttachments: ( conversationId: string, options: { limit: number } ) => Promise>; getMessageServerGuidsForSpam: ( conversationId: string ) => Promise>; getJobsInQueue(queueType: string): Promise>; insertJob(job: Readonly): Promise; deleteJob(id: string): Promise; processGroupCallRingRequest( ringId: bigint ): Promise; processGroupCallRingCancelation(ringId: bigint): Promise; cleanExpiredGroupCallRings(): Promise; getMaxMessageCounter(): Promise; getStatisticsForLogging(): Promise>; }; export type ServerInterface = DataInterface & { // Differing signature on client/server updateConversation: (data: ConversationType) => Promise; removeConversation: (id: Array | string) => Promise; searchMessages: ( query: string, options?: { limit?: number } ) => Promise>; searchMessagesInConversation: ( query: string, conversationId: string, options?: { limit?: number } ) => Promise>; getOlderMessagesByConversation: ( conversationId: string, options?: { limit?: number; messageId?: string; receivedAt?: number; sentAt?: number; storyId?: UUIDStringType; } ) => Promise>; getNewerMessagesByConversation: ( conversationId: string, options?: { limit?: number; receivedAt?: number; sentAt?: number; storyId?: UUIDStringType; } ) => Promise>; getConversationRangeCenteredOnMessage: (options: { conversationId: string; limit?: number; messageId: string; receivedAt: number; sentAt?: number; storyId?: UUIDStringType; }) => Promise<{ older: Array; newer: Array; metrics: ConversationMetricsType; }>; // Server-only getCorruptionLog: () => string; initialize: (options: { configDir: string; key: string; logger: LoggerType; }) => Promise; initializeRenderer: (options: { configDir: string; key: string; }) => Promise; removeKnownAttachments: ( allAttachments: Array ) => Promise>; removeKnownStickers: (allStickers: Array) => Promise>; removeKnownDraftAttachments: ( allStickers: Array ) => Promise>; getAllBadgeImageFileLocalPaths: () => Promise>; }; export type ClientInterface = DataInterface & { // Differing signature on client/server updateConversation: (data: ConversationType) => void; removeConversation: (id: string) => Promise; searchMessages: ( query: string, options?: { limit?: number } ) => Promise>; searchMessagesInConversation: ( query: string, conversationId: string, options?: { limit?: number } ) => Promise>; getOlderMessagesByConversation: ( conversationId: string, options: { limit?: number; messageId?: string; receivedAt?: number; sentAt?: number; storyId?: UUIDStringType; } ) => Promise>; getNewerMessagesByConversation: ( conversationId: string, options: { limit?: number; receivedAt?: number; sentAt?: number; storyId?: UUIDStringType; } ) => Promise>; getConversationRangeCenteredOnMessage: (options: { conversationId: string; limit?: number; messageId: string; receivedAt: number; sentAt?: number; storyId?: UUIDStringType; }) => Promise<{ older: Array; newer: Array; metrics: ConversationMetricsType; }>; // Client-side only shutdown: () => Promise; removeAllMessagesInConversation: ( conversationId: string, options: { logId: string; } ) => Promise; removeOtherData: () => Promise; cleanupOrphanedAttachments: () => Promise; ensureFilePermissions: () => Promise; _jobs: { [id: string]: ClientJobType }; // To decide whether to use IPC to use the database in the main process or // use the db already running in the renderer. goBackToMainProcess: () => Promise; startInRendererProcess: (isTesting?: boolean) => Promise; }; export type ClientJobType = { fnName: string; start: number; resolve?: Function; reject?: Function; // Only in DEBUG mode complete?: boolean; args?: Array; };