signal-desktop/ts/sql/Interface.ts

1145 lines
34 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2024-07-22 18:16:33 +00:00
import type { Database } from '@signalapp/better-sqlite3';
import type { ReadonlyDeep } from 'type-fest';
2021-07-09 19:36:10 +00:00
import type {
ConversationAttributesType,
MessageAttributesType,
SenderKeyInfoType,
} from '../model-types.d';
2021-07-09 19:36:10 +00:00
import type { StoredJob } from '../jobs/types';
import type { ReactionType, ReactionReadStatus } from '../types/Reactions';
2021-07-09 19:36:10 +00:00
import type { ConversationColorType, CustomColorType } from '../types/Colors';
import type { StorageAccessType } from '../types/Storage.d';
import type { BytesToStrings } from '../types/Util';
import type { QualifiedAddressStringType } from '../types/QualifiedAddress';
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
2023-08-16 20:54:39 +00:00
import type { AciString, PniString, ServiceIdString } from '../types/ServiceId';
2021-11-02 23:01:13 +00:00
import type { BadgeType } from '../badges/types';
import type { ReadStatus } from '../messages/MessageReadStatus';
import type { RawBodyRange } from '../types/BodyRange';
2024-02-08 18:01:30 +00:00
import type {
GetMessagesBetweenOptions,
MaybeStaleCallHistory,
} from './Server';
2023-03-20 22:23:53 +00:00
import type { MessageTimestamps } from '../state/ducks/conversations';
2023-08-09 00:53:06 +00:00
import type {
CallHistoryDetails,
CallHistoryFilter,
CallHistoryGroup,
CallHistoryPagination,
2024-06-26 00:58:38 +00:00
CallLogEventTarget,
2023-08-09 00:53:06 +00:00
} from '../types/CallDisposition';
2024-04-25 17:09:05 +00:00
import type { CallLinkStateType, CallLinkType } from '../types/CallLink';
import type { AttachmentDownloadJobType } from '../types/AttachmentDownload';
2024-05-20 18:15:39 +00:00
import type { GroupSendEndorsementsData } from '../types/GroupSendEndorsements';
import type { SyncTaskType } from '../util/syncTasks';
2024-05-29 23:46:43 +00:00
import type { AttachmentBackupJobType } from '../types/AttachmentBackup';
import type { SingleProtoJobQueue } from '../jobs/singleProtoJobQueue';
2024-07-22 18:16:33 +00:00
export type ReadableDB = Database & { __readable_db: never };
export type WritableDB = ReadableDB & { __writable_db: never };
2023-03-04 03:03:15 +00:00
export type AdjacentMessagesByConversationOptionsType = Readonly<{
conversationId: string;
messageId?: string;
includeStoryReplies: boolean;
limit?: number;
receivedAt?: number;
sentAt?: number;
storyId: string | undefined;
requireVisualMediaAttachments?: boolean;
}>;
2023-03-20 22:23:53 +00:00
export type GetNearbyMessageFromDeletedSetOptionsType = Readonly<{
conversationId: string;
lastSelectedMessage: MessageTimestamps;
deletedMessageIds: ReadonlyArray<string>;
storyId: string | undefined;
includeStoryReplies: boolean;
}>;
export type MessageMetricsType = {
id: string;
received_at: number;
sent_at: number;
};
export type ConversationMetricsType = {
oldest?: MessageMetricsType;
newest?: MessageMetricsType;
oldestUnseen?: MessageMetricsType;
totalUnseen: number;
};
export type ConversationType = ConversationAttributesType;
export type EmojiType = {
shortName: string;
lastUsage: number;
};
export type IdentityKeyType = {
firstUse: boolean;
id: ServiceIdString | `conversation:${string}`;
nonblockingApproval: boolean;
2021-09-24 00:49:05 +00:00
publicKey: Uint8Array;
timestamp: number;
verified: number;
};
2022-07-28 16:35:29 +00:00
export type StoredIdentityKeyType = {
firstUse: boolean;
id: ServiceIdString | `conversation:${string}`;
2022-07-28 16:35:29 +00:00
nonblockingApproval: boolean;
publicKey: string;
timestamp: number;
verified: number;
};
export type IdentityKeyIdType = IdentityKeyType['id'];
export type ItemKeyType = keyof StorageAccessType;
export type AllItemsType = Partial<StorageAccessType>;
2022-07-28 16:35:29 +00:00
export type StoredAllItemsType = Partial<BytesToStrings<StorageAccessType>>;
export type ItemType<K extends ItemKeyType> = {
id: K;
value: StorageAccessType[K];
};
2022-07-28 16:35:29 +00:00
export type StoredItemType<K extends ItemKeyType> = {
id: K;
value: BytesToStrings<StorageAccessType[K]>;
};
export type MessageType = MessageAttributesType;
export type MessageTypeUnhydrated = {
json: string;
};
export type PreKeyIdType = `${ServiceIdString}:${number}`;
export type KyberPreKeyType = {
id: PreKeyIdType;
createdAt: number;
data: Uint8Array;
isConfirmed: boolean;
isLastResort: boolean;
keyId: number;
2023-08-16 20:54:39 +00:00
ourServiceId: ServiceIdString;
};
export type StoredKyberPreKeyType = KyberPreKeyType & {
data: string;
};
export type PreKeyType = {
id: PreKeyIdType;
createdAt: number;
keyId: number;
2023-08-16 20:54:39 +00:00
ourServiceId: ServiceIdString;
2021-09-24 00:49:05 +00:00
privateKey: Uint8Array;
publicKey: Uint8Array;
};
export type StoredPreKeyType = PreKeyType & {
2022-07-28 16:35:29 +00:00
privateKey: string;
publicKey: string;
};
export type ServerSearchResultMessageType = {
json: string;
// If the FTS matches text in message.body, snippet will be populated
ftsSnippet: string | null;
// Otherwise, a matching mention will be returned
2023-08-16 20:54:39 +00:00
mentionAci: string | null;
mentionStart: number | null;
mentionLength: number | null;
};
export type ClientSearchResultMessageType = MessageType & {
json: string;
bodyRanges: ReadonlyArray<RawBodyRange>;
snippet: string;
};
export type SentProtoType = {
contentHint: number;
2021-09-24 00:49:05 +00:00
proto: Uint8Array;
timestamp: number;
urgent: boolean;
2022-08-15 21:53:33 +00:00
hasPniSignatureMessage: boolean;
};
export type SentProtoWithMessageIdsType = SentProtoType & {
messageIds: Array<string>;
};
export type SentRecipientsType = Record<ServiceIdString, Array<number>>;
export type SentMessagesType = Array<string>;
// These two are for test only
export type SentRecipientsDBType = {
payloadId: number;
2023-08-16 20:54:39 +00:00
recipientServiceId: ServiceIdString;
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
2021-09-24 00:49:05 +00:00
data: Uint8Array;
lastUpdatedDate: number;
};
export type SenderKeyIdType = SenderKeyType['id'];
export type SessionType = {
id: QualifiedAddressStringType;
2023-08-16 20:54:39 +00:00
ourServiceId: ServiceIdString;
serviceId: ServiceIdString;
conversationId: string;
deviceId: number;
record: string;
version?: number;
};
export type SessionIdType = SessionType['id'];
export type SignedPreKeyType = {
confirmed: boolean;
created_at: number;
2023-08-16 20:54:39 +00:00
ourServiceId: ServiceIdString;
id: `${ServiceIdString}:${number}`;
keyId: number;
2021-09-24 00:49:05 +00:00
privateKey: Uint8Array;
publicKey: Uint8Array;
};
2022-07-28 16:35:29 +00:00
export type StoredSignedPreKeyType = {
confirmed: boolean;
created_at: number;
2023-08-16 20:54:39 +00:00
ourServiceId: ServiceIdString;
id: `${ServiceIdString}:${number}`;
2022-07-28 16:35:29 +00:00
keyId: number;
privateKey: string;
publicKey: string;
};
export type SignedPreKeyIdType = SignedPreKeyType['id'];
2021-07-09 19:36:10 +00:00
export type StickerType = Readonly<{
id: number;
packId: string;
2021-07-09 19:36:10 +00:00
emoji?: string;
isCoverOnly: boolean;
lastUsed?: number;
path: string;
2021-07-09 19:36:10 +00:00
width: number;
height: number;
2024-07-11 19:44:09 +00:00
version: 1 | 2;
localKey?: string;
size?: number;
2021-07-09 19:36:10 +00:00
}>;
export const StickerPackStatuses = [
'known',
'ephemeral',
'downloaded',
'installed',
'pending',
'error',
] as const;
2024-07-24 00:31:40 +00:00
export type StickerPackStatusType = (typeof StickerPackStatuses)[number];
2021-07-09 19:36:10 +00:00
2022-08-03 17:10:49 +00:00
export type StorageServiceFieldsType = Readonly<{
storageID?: string;
storageVersion?: number;
storageUnknownFields?: Uint8Array | null;
storageNeedsSync: boolean;
}>;
export type InstalledStickerPackType = Readonly<{
id: string;
key: string;
2022-08-03 17:10:49 +00:00
uninstalledAt?: undefined;
position?: number | null;
}> &
StorageServiceFieldsType;
export type UninstalledStickerPackType = Readonly<{
id: string;
key?: undefined;
uninstalledAt: number;
position?: undefined;
}> &
StorageServiceFieldsType;
export type StickerPackInfoType =
| InstalledStickerPackType
| UninstalledStickerPackType;
export type StickerPackType = InstalledStickerPackType &
Readonly<{
attemptedStatus?: 'downloaded' | 'installed' | 'ephemeral';
author: string;
coverStickerId: number;
createdAt: number;
downloadAttempts: number;
installedAt?: number;
lastUsed?: number;
status: StickerPackStatusType;
stickerCount: number;
stickers: Record<string, StickerType>;
title: string;
}>;
2021-07-09 19:36:10 +00:00
export type UnprocessedType = {
id: string;
timestamp: number;
receivedAtCounter: number | null;
version: number;
attempts: number;
envelope?: string;
messageAgeSec?: number;
source?: string;
2023-08-16 20:54:39 +00:00
sourceServiceId?: ServiceIdString;
sourceDevice?: number;
2023-08-16 20:54:39 +00:00
destinationServiceId?: ServiceIdString;
updatedPni?: PniString;
serverGuid?: string;
serverTimestamp?: number;
decrypted?: string;
urgent?: boolean;
story?: boolean;
2023-02-08 00:55:12 +00:00
reportingToken?: string;
};
export type UnprocessedUpdateType = {
source?: string;
2023-08-16 20:54:39 +00:00
sourceServiceId?: ServiceIdString;
sourceDevice?: number;
serverGuid?: string;
serverTimestamp?: number;
decrypted?: string;
};
export type ConversationMessageStatsType = {
activity?: MessageType;
preview?: MessageType;
hasUserInitiatedMessages: boolean;
};
2021-08-31 21:35:01 +00:00
export type DeleteSentProtoRecipientOptionsType = Readonly<{
timestamp: number;
recipientServiceId: ServiceIdString;
2021-08-31 21:35:01 +00:00
deviceId: number;
}>;
2022-08-15 21:53:33 +00:00
export type DeleteSentProtoRecipientResultType = Readonly<{
2023-08-16 20:54:39 +00:00
successfulPhoneNumberShares: ReadonlyArray<ServiceIdString>;
2022-08-15 21:53:33 +00:00
}>;
export type StoryDistributionType = Readonly<{
id: StoryDistributionIdString;
name: string;
2022-07-01 00:52:03 +00:00
deletedAtTimestamp?: number;
allowsReplies: boolean;
isBlockList: boolean;
senderKeyInfo: SenderKeyInfoType | undefined;
2022-08-03 17:10:49 +00:00
}> &
StorageServiceFieldsType;
export type StoryDistributionMemberType = Readonly<{
listId: StoryDistributionIdString;
2023-08-16 20:54:39 +00:00
serviceId: ServiceIdString;
}>;
export type StoryDistributionWithMembersType = Readonly<
{
members: Array<ServiceIdString>;
} & StoryDistributionType
>;
export type StoryReadType = Readonly<{
authorId: ServiceIdString;
2022-07-08 20:46:25 +00:00
conversationId: string;
storyId: string;
storyReadDate: number;
}>;
2022-07-28 16:35:29 +00:00
export type ReactionResultType = Pick<
ReactionType,
2023-08-16 20:54:39 +00:00
'targetAuthorAci' | 'targetTimestamp' | 'messageId'
2022-07-28 16:35:29 +00:00
> & { rowid: number };
export type GetUnreadByConversationAndMarkReadResultType = Array<
{ originalReadStatus: ReadStatus | undefined } & Pick<
MessageType,
| 'id'
| 'source'
2023-08-16 20:54:39 +00:00
| 'sourceServiceId'
2022-07-28 16:35:29 +00:00
| 'sent_at'
| 'type'
| 'readStatus'
| 'seenStatus'
| 'expirationStartTimestamp'
2022-07-28 16:35:29 +00:00
>
>;
export type GetConversationRangeCenteredOnMessageResultType<Message> =
Readonly<{
older: Array<Message>;
newer: Array<Message>;
metrics: ConversationMetricsType;
}>;
2024-03-15 14:20:33 +00:00
export type MessageCursorType = Readonly<{
done: boolean;
runId: string;
count: number;
}>;
2024-03-15 14:20:33 +00:00
export type MessageAttachmentsCursorType = MessageCursorType &
Readonly<{
__message_attachments_cursor: never;
}>;
export type GetKnownMessageAttachmentsResultType = Readonly<{
cursor: MessageAttachmentsCursorType;
attachments: ReadonlyArray<string>;
2024-08-19 20:05:35 +00:00
downloads: ReadonlyArray<string>;
}>;
2024-03-15 14:20:33 +00:00
export type PageMessagesCursorType = MessageCursorType &
Readonly<{
__page_messages_cursor: never;
}>;
export type PageMessagesResultType = Readonly<{
cursor: PageMessagesCursorType;
messages: ReadonlyArray<MessageAttributesType>;
}>;
2022-11-28 17:19:48 +00:00
export type GetAllStoriesResultType = ReadonlyArray<
MessageType & {
hasReplies: boolean;
hasRepliesFromSelf: boolean;
}
>;
2023-03-27 23:48:57 +00:00
export type EditedMessageType = Readonly<{
conversationId: string;
2023-03-27 23:48:57 +00:00
messageId: string;
sentAt: number;
readStatus: MessageType['readStatus'];
}>;
2024-05-29 23:46:43 +00:00
export type BackupCdnMediaObjectType = {
mediaId: string;
cdnNumber: number;
sizeOnBackupCdn: number;
};
2024-07-22 18:16:33 +00:00
export type GetRecentStoryRepliesOptionsType = {
limit?: number;
messageId?: string;
receivedAt?: number;
sentAt?: number;
};
type ReadableInterface = {
close: () => void;
getSenderKeyById: (id: SenderKeyIdType) => SenderKeyType | undefined;
getAllSenderKeys: () => Array<SenderKeyType>;
getAllSentProtos: () => Array<SentProtoType>;
// Test-only
_getAllSentProtoRecipients: () => Array<SentRecipientsDBType>;
_getAllSentProtoMessageIds: () => Array<SentMessageDBType>;
getAllSessions: () => Array<SessionType>;
getConversationCount: () => number;
getConversationById: (id: string) => ConversationType | undefined;
getAllConversations: () => Array<ConversationType>;
getAllConversationIds: () => Array<string>;
getAllGroupsInvolvingServiceId: (
serviceId: ServiceIdString
) => Array<ConversationType>;
getGroupSendCombinedEndorsementExpiration: (groupId: string) => number | null;
getMessageCount: (conversationId?: string) => number;
getStoryCount: (conversationId: string) => number;
pageMessages: (cursor?: PageMessagesCursorType) => PageMessagesResultType;
finishPageMessages: (cursor: PageMessagesCursorType) => void;
getTotalUnreadForConversation: (
conversationId: string,
options: {
storyId: string | undefined;
includeStoryReplies: boolean;
}
) => number;
getTotalUnreadMentionsOfMeForConversation: (
conversationId: string,
options: {
storyId?: string;
includeStoryReplies: boolean;
}
) => number;
getOldestUnreadMentionOfMeForConversation(
conversationId: string,
options: {
storyId?: string;
includeStoryReplies: boolean;
}
): MessageMetricsType | undefined;
getReactionByTimestamp: (
fromId: string,
timestamp: number
) => ReactionType | undefined;
_getAllReactions: () => Array<ReactionType>;
getMessageBySender: (options: {
source?: string;
sourceServiceId?: ServiceIdString;
sourceDevice?: number;
sent_at: number;
}) => MessageType | undefined;
getMessageById: (id: string) => MessageType | undefined;
getMessagesById: (messageIds: ReadonlyArray<string>) => Array<MessageType>;
_getAllMessages: () => Array<MessageType>;
_getAllEditedMessages: () => Array<{ messageId: string; sentAt: number }>;
getAllMessageIds: () => Array<string>;
getMessagesBySentAt: (sentAt: number) => Array<MessageType>;
getExpiredMessages: () => Array<MessageType>;
getMessagesUnexpectedlyMissingExpirationStartTimestamp: () => Array<MessageType>;
getSoonestMessageExpiry: () => undefined | number;
getNextTapToViewMessageTimestampToAgeOut: () => undefined | number;
getTapToViewMessagesNeedingErase: () => Array<MessageType>;
// getOlderMessagesByConversation is JSON on server, full message on Client
getAllStories: (options: {
conversationId?: string;
sourceServiceId?: ServiceIdString;
}) => GetAllStoriesResultType;
// getNewerMessagesByConversation is JSON on server, full message on Client
getMessageMetricsForConversation: (options: {
conversationId: string;
storyId?: string;
includeStoryReplies: boolean;
}) => ConversationMetricsType;
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
getConversationMessageStats: (options: {
conversationId: string;
includeStoryReplies: boolean;
}) => ConversationMessageStatsType;
getLastConversationMessage(options: {
conversationId: string;
}): MessageType | undefined;
getAllCallHistory: () => ReadonlyArray<CallHistoryDetails>;
getCallHistoryUnreadCount(): number;
getCallHistoryMessageByCallId(options: {
conversationId: string;
callId: string;
}): MessageType | undefined;
getCallHistory(
callId: string,
peerId: ServiceIdString | string
): CallHistoryDetails | undefined;
getCallHistoryGroupsCount(filter: CallHistoryFilter): number;
getCallHistoryGroups(
filter: CallHistoryFilter,
pagination: CallHistoryPagination
): Array<CallHistoryGroup>;
hasGroupCallHistoryMessage: (
conversationId: string,
eraId: string
) => boolean;
callLinkExists(roomId: string): boolean;
getAllCallLinks: () => ReadonlyArray<CallLinkType>;
getCallLinkByRoomId: (roomId: string) => CallLinkType | undefined;
getAllMarkedDeletedCallLinks(): ReadonlyArray<CallLinkType>;
2024-07-22 18:16:33 +00:00
getMessagesBetween: (
conversationId: string,
options: GetMessagesBetweenOptions
) => Array<string>;
getNearbyMessageFromDeletedSet: (
options: GetNearbyMessageFromDeletedSetOptionsType
) => string | null;
getMostRecentAddressableMessages: (
conversationId: string,
limit?: number
) => Array<MessageType>;
getMostRecentAddressableNondisappearingMessages: (
conversationId: string,
limit?: number
) => Array<MessageType>;
getUnprocessedCount: () => number;
getUnprocessedById: (id: string) => UnprocessedType | undefined;
getAttachmentDownloadJob(
job: Pick<
AttachmentDownloadJobType,
'messageId' | 'attachmentType' | 'digest'
>
): AttachmentDownloadJobType;
getBackupCdnObjectMetadata: (
mediaId: string
) => BackupCdnMediaObjectType | undefined;
getStickerCount: () => number;
getAllStickerPacks: () => Array<StickerPackType>;
getInstalledStickerPacks: () => Array<StickerPackType>;
getUninstalledStickerPacks: () => Array<UninstalledStickerPackType>;
getStickerPackInfo: (packId: string) => StickerPackInfoType | undefined;
getAllStickers: () => Array<StickerType>;
getRecentStickers: (options?: { limit?: number }) => Array<StickerType>;
getRecentEmojis: (limit?: number) => Array<EmojiType>;
getAllBadges(): Array<BadgeType>;
_getAllStoryDistributions(): Array<StoryDistributionType>;
_getAllStoryDistributionMembers(): Array<StoryDistributionMemberType>;
getAllStoryDistributionsWithMembers(): Array<StoryDistributionWithMembersType>;
getStoryDistributionWithMembers(
id: string
): StoryDistributionWithMembersType | undefined;
_getAllStoryReads(): Array<StoryReadType>;
getLastStoryReadsForAuthor(options: {
authorId: ServiceIdString;
conversationId?: string;
limit?: number;
}): Array<StoryReadType>;
countStoryReadsByConversation(conversationId: string): number;
getMessagesNeedingUpgrade: (
limit: number,
options: { maxVersion: number }
) => Array<MessageType>;
getMessagesWithVisualMediaAttachments: (
conversationId: string,
options: { limit: number }
) => Array<MessageType>;
getMessagesWithFileAttachments: (
conversationId: string,
options: { limit: number }
) => Array<MessageType>;
getMessageServerGuidsForSpam: (conversationId: string) => Array<string>;
getJobsInQueue(queueType: string): Array<StoredJob>;
wasGroupCallRingPreviouslyCanceled(ringId: bigint): boolean;
getMaxMessageCounter(): number | undefined;
getStatisticsForLogging(): Record<string, string>;
};
type WritableInterface = {
close: () => void;
2024-03-15 14:20:33 +00:00
2024-07-22 18:16:33 +00:00
removeIndexedDBFiles: () => void;
2024-07-22 18:16:33 +00:00
removeIdentityKeyById: (id: IdentityKeyIdType) => number;
removeAllIdentityKeys: () => number;
2024-07-22 18:16:33 +00:00
removeKyberPreKeyById: (id: PreKeyIdType | Array<PreKeyIdType>) => number;
removeKyberPreKeysByServiceId: (serviceId: ServiceIdString) => void;
removeAllKyberPreKeys: () => number;
removePreKeyById: (id: PreKeyIdType | Array<PreKeyIdType>) => number;
removePreKeysByServiceId: (serviceId: ServiceIdString) => void;
removeAllPreKeys: () => number;
removeSignedPreKeyById: (
id: SignedPreKeyIdType | Array<SignedPreKeyIdType>
2024-07-22 18:16:33 +00:00
) => number;
removeSignedPreKeysByServiceId: (serviceId: ServiceIdString) => void;
removeAllSignedPreKeys: () => number;
2024-07-22 18:16:33 +00:00
removeAllItems: () => number;
removeItemById: (id: ItemKeyType | Array<ItemKeyType>) => number;
2024-07-22 18:16:33 +00:00
createOrUpdateSenderKey: (key: SenderKeyType) => void;
removeAllSenderKeys: () => void;
removeSenderKeyById: (id: SenderKeyIdType) => void;
2024-07-22 18:16:33 +00:00
getSentProtoByRecipient: (options: {
now: number;
recipientServiceId: ServiceIdString;
timestamp: number;
}) => SentProtoWithMessageIdsType | undefined;
insertSentProto: (
proto: SentProtoType,
options: {
recipients: SentRecipientsType;
messageIds: SentMessagesType;
}
2024-07-22 18:16:33 +00:00
) => number;
deleteSentProtosOlderThan: (timestamp: number) => void;
deleteSentProtoByMessageId: (messageId: string) => void;
insertProtoRecipients: (options: {
id: number;
recipientServiceId: ServiceIdString;
deviceIds: Array<number>;
2024-07-22 18:16:33 +00:00
}) => void;
2021-08-31 21:35:01 +00:00
deleteSentProtoRecipient: (
options:
| DeleteSentProtoRecipientOptionsType
| ReadonlyArray<DeleteSentProtoRecipientOptionsType>
2024-07-22 18:16:33 +00:00
) => DeleteSentProtoRecipientResultType;
removeAllSentProtos: () => void;
2024-07-22 18:16:33 +00:00
createOrUpdateSession: (data: SessionType) => void;
createOrUpdateSessions: (array: Array<SessionType>) => void;
commitDecryptResult(options: {
senderKeys: Array<SenderKeyType>;
sessions: Array<SessionType>;
unprocessed: Array<UnprocessedType>;
2024-07-22 18:16:33 +00:00
}): void;
bulkAddSessions: (array: Array<SessionType>) => void;
removeSessionById: (id: SessionIdType) => number;
removeSessionsByConversation: (conversationId: string) => void;
removeSessionsByServiceId: (serviceId: ServiceIdString) => void;
removeAllSessions: () => number;
saveConversation: (data: ConversationType) => void;
saveConversations: (array: Array<ConversationType>) => void;
// updateConversation is a normal data method on Server, a sync batch-add on Client
2024-07-22 18:16:33 +00:00
updateConversations: (array: Array<ConversationType>) => void;
// removeConversation handles either one id or an array on Server, and one id on Client
2024-07-22 18:16:33 +00:00
_removeAllConversations: () => void;
updateAllConversationColors: (
conversationColor?: ConversationColorType,
customColorData?: {
id: string;
value: CustomColorType;
}
2024-07-22 18:16:33 +00:00
) => void;
removeAllProfileKeyCredentials: () => void;
replaceAllEndorsementsForGroup: (data: GroupSendEndorsementsData) => void;
deleteAllEndorsementsForGroup: (groupId: string) => void;
saveMessage: (
data: ReadonlyDeep<MessageType>,
2021-12-20 21:04:02 +00:00
options: {
jobToInsert?: StoredJob;
forceSave?: boolean;
ourAci: AciString;
}
2024-07-22 18:16:33 +00:00
) => string;
saveMessages: (
arrayOfMessages: ReadonlyArray<ReadonlyDeep<MessageType>>,
options: { forceSave?: boolean; ourAci: AciString }
2024-07-22 18:16:33 +00:00
) => Array<string>;
getUnreadByConversationAndMarkRead: (options: {
conversationId: string;
includeStoryReplies: boolean;
newestUnreadAt: number;
now?: number;
readAt?: number;
2023-03-04 03:03:15 +00:00
storyId?: string;
2024-07-22 18:16:33 +00:00
}) => GetUnreadByConversationAndMarkReadResultType;
2023-03-27 23:48:57 +00:00
getUnreadEditedMessagesAndMarkRead: (options: {
conversationId: string;
2023-03-27 23:48:57 +00:00
newestUnreadAt: number;
2024-07-22 18:16:33 +00:00
}) => GetUnreadByConversationAndMarkReadResultType;
getUnreadReactionsAndMarkRead: (options: {
conversationId: string;
newestUnreadAt: number;
2023-03-04 03:03:15 +00:00
storyId?: string;
2024-07-22 18:16:33 +00:00
}) => Array<ReactionResultType>;
markReactionAsRead: (
targetAuthorServiceId: ServiceIdString,
targetTimestamp: number
2024-07-22 18:16:33 +00:00
) => ReactionType | undefined;
removeReactionFromConversation: (reaction: {
emoji: string;
fromId: string;
targetAuthorServiceId: ServiceIdString;
targetTimestamp: number;
2024-07-22 18:16:33 +00:00
}) => void;
addReaction: (
reactionObj: ReactionType,
options: {
readStatus: ReactionReadStatus;
}
2024-07-22 18:16:33 +00:00
) => void;
_removeAllReactions: () => void;
_removeAllMessages: () => void;
incrementMessagesMigrationAttempts: (
messageIds: ReadonlyArray<string>
) => void;
2024-07-22 18:16:33 +00:00
clearCallHistory: (target: CallLogEventTarget) => ReadonlyArray<string>;
2024-08-13 18:39:04 +00:00
_removeAllCallHistory: () => void;
2024-07-22 18:16:33 +00:00
markCallHistoryDeleted: (callId: string) => void;
cleanupCallHistoryMessages: () => void;
markCallHistoryRead(callId: string): void;
2024-08-27 13:20:23 +00:00
markAllCallHistoryRead(target: CallLogEventTarget): number;
markAllCallHistoryReadInConversation(target: CallLogEventTarget): number;
2024-07-22 18:16:33 +00:00
saveCallHistory(callHistory: CallHistoryDetails): void;
markCallHistoryMissed(callIds: ReadonlyArray<string>): void;
getRecentStaleRingsAndMarkOlderMissed(): ReadonlyArray<MaybeStaleCallHistory>;
insertCallLink(callLink: CallLinkType): void;
updateCallLinkAdminKeyByRoomId(roomId: string, adminKey: string): void;
2024-04-01 19:19:35 +00:00
updateCallLinkState(
roomId: string,
2024-04-25 17:09:05 +00:00
callLinkState: CallLinkStateType
2024-07-22 18:16:33 +00:00
): CallLinkType;
beginDeleteAllCallLinks(): void;
beginDeleteCallLink(roomId: string): void;
finalizeDeleteCallLink(roomId: string): void;
2024-08-13 18:39:04 +00:00
_removeAllCallLinks(): void;
deleteCallLinkFromSync(roomId: string): void;
2024-07-22 18:16:33 +00:00
migrateConversationMessages: (obsoleteId: string, currentId: string) => void;
2023-03-27 23:48:57 +00:00
saveEditedMessage: (
mainMessage: ReadonlyDeep<MessageType>,
ourAci: AciString,
opts: ReadonlyDeep<EditedMessageType>
2024-07-22 18:16:33 +00:00
) => void;
2024-06-03 17:02:25 +00:00
saveEditedMessages: (
mainMessage: ReadonlyDeep<MessageType>,
2024-06-03 17:02:25 +00:00
ourAci: AciString,
history: ReadonlyArray<ReadonlyDeep<EditedMessageType>>
2024-07-22 18:16:33 +00:00
) => void;
2024-07-22 18:16:33 +00:00
removeSyncTaskById: (id: string) => void;
saveSyncTasks: (tasks: Array<SyncTaskType>) => void;
getAllSyncTasks: () => Array<SyncTaskType>;
2024-07-22 18:16:33 +00:00
getAllUnprocessedIds: () => Array<string>;
getUnprocessedByIdsAndIncrementAttempts: (
ids: ReadonlyArray<string>
2024-07-22 18:16:33 +00:00
) => Array<UnprocessedType>;
updateUnprocessedWithData: (id: string, data: UnprocessedUpdateType) => void;
updateUnprocessedsWithData: (
array: Array<{ id: string; data: UnprocessedUpdateType }>
2024-07-22 18:16:33 +00:00
) => void;
removeUnprocessed: (id: string | Array<string>) => void;
/** only for testing */
2024-07-22 18:16:33 +00:00
removeAllUnprocessed: () => void;
getNextAttachmentDownloadJobs: (options: {
limit: number;
prioritizeMessageIds?: Array<string>;
timestamp?: number;
2024-07-22 18:16:33 +00:00
}) => Array<AttachmentDownloadJobType>;
saveAttachmentDownloadJob: (job: AttachmentDownloadJobType) => void;
resetAttachmentDownloadActive: () => void;
removeAttachmentDownloadJob: (job: AttachmentDownloadJobType) => void;
2024-05-29 23:46:43 +00:00
getNextAttachmentBackupJobs: (options: {
limit: number;
timestamp?: number;
2024-07-22 18:16:33 +00:00
}) => Array<AttachmentBackupJobType>;
saveAttachmentBackupJob: (job: AttachmentBackupJobType) => void;
markAllAttachmentBackupJobsInactive: () => void;
removeAttachmentBackupJob: (job: AttachmentBackupJobType) => void;
clearAllAttachmentBackupJobs: () => void;
2024-05-29 23:46:43 +00:00
2024-07-22 18:16:33 +00:00
clearAllBackupCdnObjectMetadata: () => void;
2024-05-29 23:46:43 +00:00
saveBackupCdnObjectMetadata: (
mediaObjects: Array<BackupCdnMediaObjectType>
2024-07-22 18:16:33 +00:00
) => void;
2024-05-29 23:46:43 +00:00
2024-07-22 18:16:33 +00:00
createOrUpdateStickerPack: (pack: StickerPackType) => void;
updateStickerPackStatus: (
id: string,
status: StickerPackStatusType,
options?: { timestamp: number }
2024-07-22 18:16:33 +00:00
) => void;
updateStickerPackInfo: (info: StickerPackInfoType) => void;
createOrUpdateSticker: (sticker: StickerType) => void;
createOrUpdateStickers: (sticker: ReadonlyArray<StickerType>) => void;
updateStickerLastUsed: (
packId: string,
stickerId: number,
lastUsed: number
2024-07-22 18:16:33 +00:00
) => void;
addStickerPackReference: (messageId: string, packId: string) => void;
deleteStickerPackReference: (
messageId: string,
packId: string
2024-07-22 18:16:33 +00:00
) => ReadonlyArray<string> | undefined;
deleteStickerPack: (packId: string) => Array<string>;
addUninstalledStickerPack: (pack: UninstalledStickerPackType) => void;
removeUninstalledStickerPack: (packId: string) => void;
installStickerPack: (packId: string, timestamp: number) => void;
uninstallStickerPack: (packId: string, timestamp: number) => void;
clearAllErrorStickerPackAttempts: () => void;
2024-07-22 18:16:33 +00:00
updateEmojiUsage: (shortName: string, timeUsed?: number) => void;
2024-07-22 18:16:33 +00:00
updateOrCreateBadges(badges: ReadonlyArray<BadgeType>): void;
badgeImageFileDownloaded(url: string, localPath: string): void;
2021-11-02 23:01:13 +00:00
2024-07-22 18:16:33 +00:00
_deleteAllStoryDistributions(): void;
createNewStoryDistribution(
distribution: StoryDistributionWithMembersType
2024-07-22 18:16:33 +00:00
): void;
modifyStoryDistribution(distribution: StoryDistributionType): void;
modifyStoryDistributionMembers(
2022-07-01 00:52:03 +00:00
listId: string,
options: {
toAdd: Array<ServiceIdString>;
toRemove: Array<ServiceIdString>;
2022-07-01 00:52:03 +00:00
}
2024-07-22 18:16:33 +00:00
): void;
2022-07-01 00:52:03 +00:00
modifyStoryDistributionWithMembers(
distribution: StoryDistributionType,
options: {
toAdd: Array<ServiceIdString>;
toRemove: Array<ServiceIdString>;
}
2024-07-22 18:16:33 +00:00
): void;
deleteStoryDistribution(id: StoryDistributionIdString): void;
2021-04-29 23:02:27 +00:00
2024-07-22 18:16:33 +00:00
_deleteAllStoryReads(): void;
addNewStoryRead(read: StoryReadType): void;
2021-05-28 16:15:17 +00:00
2024-07-22 18:16:33 +00:00
removeAll: () => void;
removeAllConfiguration: () => void;
eraseStorageServiceState: () => void;
2021-08-20 16:06:15 +00:00
2024-07-22 18:16:33 +00:00
insertJob(job: Readonly<StoredJob>): void;
deleteJob(id: string): void;
2024-07-22 18:16:33 +00:00
processGroupCallRingCancellation(ringId: bigint): void;
cleanExpiredGroupCallRingCancellations(): void;
};
2023-10-10 23:55:32 +00:00
2024-07-22 18:16:33 +00:00
// Adds a database argument
type AddReadonlyDB<I> = {
[Key in keyof I]: I[Key] extends (...args: infer Args) => infer R
? (db: ReadableDB, ...args: Args) => R
: never;
};
2024-07-22 18:16:33 +00:00
export type ServerReadableDirectInterface = ReadableInterface & {
// Differing signature on client/server
searchMessages: ({
query,
conversationId,
options,
2023-08-16 20:54:39 +00:00
contactServiceIdsMatchingQuery,
}: {
query: string;
conversationId?: string;
options?: { limit?: number };
2023-08-16 20:54:39 +00:00
contactServiceIdsMatchingQuery?: Array<ServiceIdString>;
2024-07-22 18:16:33 +00:00
}) => Array<ServerSearchResultMessageType>;
getRecentStoryReplies(
storyId: string,
options?: GetRecentStoryRepliesOptionsType
2024-07-22 18:16:33 +00:00
): Array<MessageTypeUnhydrated>;
getOlderMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
2024-07-22 18:16:33 +00:00
) => Array<MessageTypeUnhydrated>;
getNewerMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
2024-07-22 18:16:33 +00:00
) => Array<MessageTypeUnhydrated>;
2023-03-04 03:03:15 +00:00
getConversationRangeCenteredOnMessage: (
options: AdjacentMessagesByConversationOptionsType
2024-07-22 18:16:33 +00:00
) => GetConversationRangeCenteredOnMessageResultType<MessageTypeUnhydrated>;
2022-07-28 16:35:29 +00:00
getIdentityKeyById: (
id: IdentityKeyIdType
2024-07-22 18:16:33 +00:00
) => StoredIdentityKeyType | undefined;
getAllIdentityKeys: () => Array<StoredIdentityKeyType>;
getKyberPreKeyById: (id: PreKeyIdType) => StoredKyberPreKeyType | undefined;
getAllKyberPreKeys: () => Array<StoredKyberPreKeyType>;
getPreKeyById: (id: PreKeyIdType) => StoredPreKeyType | undefined;
getAllPreKeys: () => Array<StoredPreKeyType>;
2022-07-28 16:35:29 +00:00
getSignedPreKeyById: (
id: SignedPreKeyIdType
2024-07-22 18:16:33 +00:00
) => StoredSignedPreKeyType | undefined;
getAllSignedPreKeys: () => Array<StoredSignedPreKeyType>;
2024-07-22 18:16:33 +00:00
getItemById<K extends ItemKeyType>(id: K): StoredItemType<K> | undefined;
getAllItems: () => StoredAllItemsType;
2024-07-22 18:16:33 +00:00
// Server-only
getKnownMessageAttachments: (
cursor?: MessageAttachmentsCursorType
2024-07-22 18:16:33 +00:00
) => GetKnownMessageAttachmentsResultType;
finishGetKnownMessageAttachments: (
cursor: MessageAttachmentsCursorType
2024-07-22 18:16:33 +00:00
) => void;
2024-08-27 21:00:41 +00:00
getKnownDownloads: () => Array<string>;
2024-07-22 18:16:33 +00:00
getKnownConversationAttachments: () => Array<string>;
getAllBadgeImageFileLocalPaths: () => Set<string>;
};
export type ServerReadableInterface =
AddReadonlyDB<ServerReadableDirectInterface>;
// Adds a database argument
type AddWritableDB<I> = {
[Key in keyof I]: I[Key] extends (...args: infer Args) => infer R
? (db: WritableDB, ...args: Args) => R
: never;
};
export type ServerWritableDirectInterface = WritableInterface & {
// Differing signature on client/server
updateConversation: (data: ConversationType) => void;
removeConversation: (id: Array<string> | string) => void;
removeMessage: (id: string) => void;
removeMessages: (ids: ReadonlyArray<string>) => void;
createOrUpdateIdentityKey: (data: StoredIdentityKeyType) => void;
bulkAddIdentityKeys: (array: Array<StoredIdentityKeyType>) => void;
createOrUpdateKyberPreKey: (data: StoredKyberPreKeyType) => void;
bulkAddKyberPreKeys: (array: Array<StoredKyberPreKeyType>) => void;
createOrUpdatePreKey: (data: StoredPreKeyType) => void;
bulkAddPreKeys: (array: Array<StoredPreKeyType>) => void;
createOrUpdateSignedPreKey: (data: StoredSignedPreKeyType) => void;
bulkAddSignedPreKeys: (array: Array<StoredSignedPreKeyType>) => void;
createOrUpdateItem<K extends ItemKeyType>(data: StoredItemType<K>): void;
// Server-only
removeKnownStickers: (allStickers: ReadonlyArray<string>) => Array<string>;
removeKnownDraftAttachments: (
allStickers: ReadonlyArray<string>
2024-07-22 18:16:33 +00:00
) => Array<string>;
runCorruptionChecks: () => void;
};
2024-07-22 18:16:33 +00:00
export type ServerWritableInterface =
AddWritableDB<ServerWritableDirectInterface>;
// Makes sync calls - async
export type ClientInterfaceWrap<I> = {
[Key in keyof I]: I[Key] extends (...args: infer Args) => infer R
? (...args: Args) => Promise<R>
: never;
};
2024-07-22 18:16:33 +00:00
export type ClientOnlyReadableInterface = ClientInterfaceWrap<{
// Differing signature on client/server
searchMessages: ({
query,
conversationId,
options,
2023-08-16 20:54:39 +00:00
contactServiceIdsMatchingQuery,
}: {
query: string;
conversationId?: string;
options?: { limit?: number };
2023-08-16 20:54:39 +00:00
contactServiceIdsMatchingQuery?: Array<ServiceIdString>;
2024-07-22 18:16:33 +00:00
}) => Array<ClientSearchResultMessageType>;
getRecentStoryReplies(
storyId: string,
options?: GetRecentStoryRepliesOptionsType
): Array<MessageType>;
getOlderMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
) => Array<MessageType>;
getNewerMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
) => Array<MessageType>;
2023-03-04 03:03:15 +00:00
getConversationRangeCenteredOnMessage: (
options: AdjacentMessagesByConversationOptionsType
2024-07-22 18:16:33 +00:00
) => GetConversationRangeCenteredOnMessageResultType<MessageType>;
2022-07-28 16:35:29 +00:00
2024-07-22 18:16:33 +00:00
getIdentityKeyById: (id: IdentityKeyIdType) => IdentityKeyType | undefined;
getAllIdentityKeys: () => Array<IdentityKeyType>;
getKyberPreKeyById: (id: PreKeyIdType) => KyberPreKeyType | undefined;
getAllKyberPreKeys: () => Array<KyberPreKeyType>;
getPreKeyById: (id: PreKeyIdType) => PreKeyType | undefined;
getAllPreKeys: () => Array<PreKeyType>;
getSignedPreKeyById: (id: SignedPreKeyIdType) => SignedPreKeyType | undefined;
getAllSignedPreKeys: () => Array<SignedPreKeyType>;
2022-07-28 16:35:29 +00:00
2024-07-22 18:16:33 +00:00
getItemById<K extends ItemKeyType>(id: K): ItemType<K> | undefined;
getAllItems: () => AllItemsType;
}>;
export type ClientOnlyWritableInterface = ClientInterfaceWrap<{
// Differing signature on client/server
updateConversation: (data: ConversationType) => void;
removeConversation: (id: string) => void;
flushUpdateConversationBatcher: () => void;
removeMessage: (
id: string,
options: {
fromSync?: boolean;
singleProtoJobQueue: SingleProtoJobQueue;
}
) => void;
removeMessages: (
ids: ReadonlyArray<string>,
options: {
fromSync?: boolean;
singleProtoJobQueue: SingleProtoJobQueue;
}
) => void;
createOrUpdateIdentityKey: (data: IdentityKeyType) => void;
bulkAddIdentityKeys: (array: Array<IdentityKeyType>) => void;
createOrUpdateKyberPreKey: (data: KyberPreKeyType) => void;
bulkAddKyberPreKeys: (array: Array<KyberPreKeyType>) => void;
createOrUpdatePreKey: (data: PreKeyType) => void;
bulkAddPreKeys: (array: Array<PreKeyType>) => void;
createOrUpdateSignedPreKey: (data: SignedPreKeyType) => void;
bulkAddSignedPreKeys: (array: Array<SignedPreKeyType>) => void;
createOrUpdateItem<K extends ItemKeyType>(data: ItemType<K>): void;
// Client-side only
2024-07-22 18:16:33 +00:00
shutdown: () => void;
2024-08-12 19:54:24 +00:00
removeDB: () => void;
removeMessagesInConversation: (
conversationId: string,
2021-01-13 00:42:15 +00:00
options: {
fromSync?: boolean;
2021-01-13 00:42:15 +00:00
logId: string;
receivedAt?: number;
singleProtoJobQueue: SingleProtoJobQueue;
2021-01-13 00:42:15 +00:00
}
2024-07-22 18:16:33 +00:00
) => void;
removeOtherData: () => void;
cleanupOrphanedAttachments: () => void;
ensureFilePermissions: () => void;
}>;
2024-07-22 18:16:33 +00:00
export type ClientReadableInterface = ClientInterfaceWrap<ReadableInterface> &
ClientOnlyReadableInterface;
export type ClientWritableInterface = ClientInterfaceWrap<WritableInterface> &
ClientOnlyWritableInterface;