// 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 { LocaleMessagesType } from '../types/I18N'; import { ConversationModelCollectionType, MessageModelCollectionType, } from '../model-types.d'; import { MessageModel } from '../models/messages'; import { ConversationModel } from '../models/conversations'; export type AttachmentDownloadJobType = any; export type ConverationMetricsType = any; export type ConversationType = any; export type EmojiType = any; export type IdentityKeyType = any; export type ItemType = any; export type MessageType = any; export type MessageTypeUnhydrated = any; export type PreKeyType = any; export type SearchResultMessageType = any; export type SessionType = any; export type SignedPreKeyType = any; export type StickerPackStatusType = string; export type StickerPackType = any; export type StickerType = any; export type UnprocessedType = any; export type DataInterface = { close: () => Promise; removeDB: () => Promise; removeIndexedDBFiles: () => Promise; createOrUpdateIdentityKey: (data: IdentityKeyType) => Promise; getIdentityKeyById: (id: string) => Promise; bulkAddIdentityKeys: (array: Array) => Promise; removeIdentityKeyById: (id: string) => Promise; removeAllIdentityKeys: () => Promise; getAllIdentityKeys: () => Promise>; createOrUpdatePreKey: (data: PreKeyType) => Promise; getPreKeyById: (id: number) => Promise; bulkAddPreKeys: (array: Array) => Promise; removePreKeyById: (id: number) => Promise; removeAllPreKeys: () => Promise; getAllPreKeys: () => Promise>; createOrUpdateSignedPreKey: (data: SignedPreKeyType) => Promise; getSignedPreKeyById: (id: number) => Promise; bulkAddSignedPreKeys: (array: Array) => Promise; removeSignedPreKeyById: (id: number) => Promise; removeAllSignedPreKeys: () => Promise; getAllSignedPreKeys: () => Promise>; createOrUpdateItem: (data: ItemType) => Promise; getItemById: (id: string) => Promise; bulkAddItems: (array: Array) => Promise; removeItemById: (id: string) => Promise; removeAllItems: () => Promise; getAllItems: () => Promise>; createOrUpdateSession: (data: SessionType) => Promise; createOrUpdateSessions: (array: Array) => Promise; getSessionById: (id: string) => Promise; getSessionsById: (conversationId: string) => Promise>; bulkAddSessions: (array: Array) => Promise; removeSessionById: (id: string) => Promise; removeSessionsByConversation: (conversationId: string) => Promise; removeAllSessions: () => Promise; getAllSessions: () => Promise>; eraseStorageServiceStateFromConversations: () => Promise; getConversationCount: () => Promise; saveConversation: (data: ConversationType) => Promise; saveConversations: (array: Array) => Promise; updateConversations: (array: Array) => Promise; getAllConversationIds: () => Promise>; searchConversations: ( query: string, options?: { limit?: number } ) => Promise>; searchMessages: ( query: string, options?: { limit?: number } ) => Promise>; searchMessagesInConversation: ( query: string, conversationId: string, options?: { limit?: number } ) => Promise>; getMessageCount: (conversationId?: string) => Promise; saveMessages: ( arrayOfMessages: Array, options: { forceSave?: boolean } ) => Promise; getAllMessageIds: () => Promise>; getMessageMetricsForConversation: ( conversationId: string ) => Promise; hasGroupCallHistoryMessage: ( conversationId: string, eraId: string ) => Promise; migrateConversationMessages: ( obsoleteId: string, currentId: string ) => Promise; getUnprocessedCount: () => Promise; getAllUnprocessed: () => Promise>; saveUnprocessed: ( data: UnprocessedType, options?: { forceSave?: boolean } ) => Promise; updateUnprocessedAttempts: (id: string, attempts: number) => Promise; updateUnprocessedWithData: ( id: string, data: UnprocessedType ) => Promise; updateUnprocessedsWithData: (array: Array) => Promise; getUnprocessedById: (id: string) => Promise; saveUnprocesseds: ( arrayOfUnprocessed: Array, options?: { forceSave?: boolean } ) => Promise; removeUnprocessed: (id: string) => Promise; removeAllUnprocessed: () => Promise; getNextAttachmentDownloadJobs: ( limit?: number, options?: { timestamp?: number } ) => Promise>; saveAttachmentDownloadJob: (job: AttachmentDownloadJobType) => Promise; setAttachmentDownloadJobPending: ( id: string, pending: boolean ) => Promise; resetAttachmentDownloadPending: () => 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>; 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>; removeAll: () => Promise; removeAllConfiguration: () => Promise; getMessagesNeedingUpgrade: ( limit: number, options: { maxVersion: number } ) => Promise>; getMessagesWithVisualMediaAttachments: ( conversationId: string, options: { limit: number } ) => Promise>; getMessagesWithFileAttachments: ( conversationId: string, options: { limit: number } ) => Promise>; }; // The reason for client/server divergence is the need to inject Backbone models and // collections into data calls so those are the objects returned. This was necessary in // July 2018 when creating the Data API as a drop-in replacement for previous database // requests via ORM. // Note: It is extremely important that items are duplicated between these two. Client.js // loops over all of its local functions to generate the server-side IPC-based API. export type ServerInterface = DataInterface & { getAllConversations: () => Promise>; getAllGroupsInvolvingId: (id: string) => Promise>; getAllPrivateConversations: () => Promise>; getConversationById: (id: string) => Promise; getExpiredMessages: () => Promise>; getMessageById: (id: string) => Promise; getMessageBySender: (options: { source: string; sourceUuid: string; sourceDevice: string; sent_at: number; }) => Promise>; getMessagesBySentAt: (sentAt: number) => Promise>; getOlderMessagesByConversation: ( conversationId: string, options?: { limit?: number; receivedAt?: number; sentAt?: number; messageId?: string; } ) => Promise>; getNewerMessagesByConversation: ( conversationId: string, options?: { limit?: number; receivedAt?: number; sentAt?: number } ) => Promise>; getLastConversationActivity: (options: { conversationId: string; ourConversationId: string; }) => Promise; getLastConversationPreview: (options: { conversationId: string; ourConversationId: string; }) => Promise; getNextExpiringMessage: () => Promise; getNextTapToViewMessageToAgeOut: () => Promise; getOutgoingWithoutExpiresAt: () => Promise>; getTapToViewMessagesNeedingErase: () => Promise>; getUnreadByConversation: ( conversationId: string ) => Promise>; removeConversation: (id: Array | string) => Promise; removeMessage: (id: string) => Promise; removeMessages: (ids: Array) => Promise; saveMessage: ( data: MessageType, options: { forceSave?: boolean } ) => Promise; updateConversation: (data: ConversationType) => Promise; // For testing only _getAllMessages: () => Promise>; // Server-only initialize: (options: { configDir: string; key: string; messages: LocaleMessagesType; }) => Promise; removeKnownAttachments: ( allAttachments: Array ) => Promise>; removeKnownStickers: (allStickers: Array) => Promise>; removeKnownDraftAttachments: ( allStickers: Array ) => Promise>; }; export type ClientInterface = DataInterface & { getAllConversations: (options: { ConversationCollection: typeof ConversationModelCollectionType; }) => Promise; getAllGroupsInvolvingId: ( id: string, options: { ConversationCollection: typeof ConversationModelCollectionType; } ) => Promise; getAllPrivateConversations: (options: { ConversationCollection: typeof ConversationModelCollectionType; }) => Promise; getConversationById: ( id: string, options: { Conversation: typeof ConversationModel } ) => Promise; getExpiredMessages: (options: { MessageCollection: typeof MessageModelCollectionType; }) => Promise; getMessageById: ( id: string, options: { Message: typeof MessageModel } ) => Promise; getMessageBySender: ( data: { source: string; sourceUuid: string; sourceDevice: string; sent_at: number; }, options: { Message: typeof MessageModel } ) => Promise; getMessagesBySentAt: ( sentAt: number, options: { MessageCollection: typeof MessageModelCollectionType } ) => Promise; getOlderMessagesByConversation: ( conversationId: string, options: { limit?: number; messageId?: string; receivedAt?: number; sentAt?: number; MessageCollection: typeof MessageModelCollectionType; } ) => Promise; getNewerMessagesByConversation: ( conversationId: string, options: { limit?: number; receivedAt?: number; sentAt?: number; MessageCollection: typeof MessageModelCollectionType; } ) => Promise; getLastConversationActivity: (options: { conversationId: string; ourConversationId: string; Message: typeof MessageModel; }) => Promise; getLastConversationPreview: (options: { conversationId: string; ourConversationId: string; Message: typeof MessageModel; }) => Promise; getNextExpiringMessage: (options: { Message: typeof MessageModel; }) => Promise; getNextTapToViewMessageToAgeOut: (options: { Message: typeof MessageModel; }) => Promise; getOutgoingWithoutExpiresAt: (options: { MessageCollection: typeof MessageModelCollectionType; }) => Promise; getTapToViewMessagesNeedingErase: (options: { MessageCollection: typeof MessageModelCollectionType; }) => Promise; getUnreadByConversation: ( conversationId: string, options: { MessageCollection: typeof MessageModelCollectionType } ) => Promise; removeConversation: ( id: string, options: { Conversation: typeof ConversationModel } ) => Promise; removeMessage: ( id: string, options: { Message: typeof MessageModel } ) => Promise; removeMessages: ( ids: Array, options: { Message: typeof MessageModel } ) => Promise; saveMessage: ( data: MessageType, options: { forceSave?: boolean; Message: typeof MessageModel } ) => Promise; updateConversation: (data: ConversationType, extra?: unknown) => void; // Test-only _getAllMessages: (options: { MessageCollection: typeof MessageModelCollectionType; }) => Promise; // Client-side only shutdown: () => Promise; removeAllMessagesInConversation: ( conversationId: string, options: { logId: string; MessageCollection: typeof MessageModelCollectionType; } ) => Promise; removeOtherData: () => Promise; cleanupOrphanedAttachments: () => Promise; ensureFilePermissions: () => Promise; // Client-side only, and test-only _removeConversations: (ids: Array) => Promise; _cleanData: (data: any, path?: string) => any; _jobs: { [id: string]: ClientJobType }; }; export type ClientJobType = { fnName: string; start: number; resolve?: Function; reject?: Function; // Only in DEBUG mode complete?: boolean; args?: Array; };