signal-desktop/ts/sql/Interface.ts

1053 lines
33 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
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';
2021-07-09 19:36:10 +00:00
import type { AttachmentType } from '../types/Attachment';
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 { LoggerType } from '../types/Logging';
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,
} from '../types/CallDisposition';
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 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;
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;
2021-07-09 19:36:10 +00:00
}>;
export const StickerPackStatuses = [
'known',
'ephemeral',
'downloaded',
'installed',
'pending',
'error',
] as const;
export type StickerPackStatusType = typeof StickerPackStatuses[number];
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'
>
>;
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-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-10-10 23:55:32 +00:00
export type FTSOptimizationStateType = Readonly<{
steps: number;
done?: 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'];
}>;
export type DataInterface = {
close: () => Promise<void>;
2024-03-15 14:20:33 +00:00
pauseWriteAccess(): Promise<void>;
resumeWriteAccess(): Promise<void>;
removeDB: () => Promise<void>;
removeIndexedDBFiles: () => Promise<void>;
removeIdentityKeyById: (id: IdentityKeyIdType) => Promise<number>;
removeAllIdentityKeys: () => Promise<number>;
removeKyberPreKeyById: (
id: PreKeyIdType | Array<PreKeyIdType>
) => Promise<number>;
removeKyberPreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllKyberPreKeys: () => Promise<number>;
removePreKeyById: (id: PreKeyIdType | Array<PreKeyIdType>) => Promise<number>;
removePreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllPreKeys: () => Promise<number>;
removeSignedPreKeyById: (
id: SignedPreKeyIdType | Array<SignedPreKeyIdType>
) => Promise<number>;
removeSignedPreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllSignedPreKeys: () => Promise<number>;
removeAllItems: () => Promise<number>;
removeItemById: (id: ItemKeyType | Array<ItemKeyType>) => Promise<number>;
createOrUpdateSenderKey: (key: SenderKeyType) => Promise<void>;
getSenderKeyById: (id: SenderKeyIdType) => Promise<SenderKeyType | undefined>;
removeAllSenderKeys: () => Promise<void>;
getAllSenderKeys: () => Promise<Array<SenderKeyType>>;
removeSenderKeyById: (id: SenderKeyIdType) => Promise<void>;
insertSentProto: (
proto: SentProtoType,
options: {
recipients: SentRecipientsType;
messageIds: SentMessagesType;
}
) => Promise<number>;
deleteSentProtosOlderThan: (timestamp: number) => Promise<void>;
deleteSentProtoByMessageId: (messageId: string) => Promise<void>;
insertProtoRecipients: (options: {
id: number;
recipientServiceId: ServiceIdString;
deviceIds: Array<number>;
}) => Promise<void>;
2021-08-31 21:35:01 +00:00
deleteSentProtoRecipient: (
options:
| DeleteSentProtoRecipientOptionsType
| ReadonlyArray<DeleteSentProtoRecipientOptionsType>
2022-08-15 21:53:33 +00:00
) => Promise<DeleteSentProtoRecipientResultType>;
getSentProtoByRecipient: (options: {
now: number;
recipientServiceId: ServiceIdString;
timestamp: number;
}) => Promise<SentProtoWithMessageIdsType | undefined>;
removeAllSentProtos: () => Promise<void>;
getAllSentProtos: () => Promise<Array<SentProtoType>>;
// Test-only
_getAllSentProtoRecipients: () => Promise<Array<SentRecipientsDBType>>;
_getAllSentProtoMessageIds: () => Promise<Array<SentMessageDBType>>;
createOrUpdateSession: (data: SessionType) => Promise<void>;
createOrUpdateSessions: (array: Array<SessionType>) => Promise<void>;
commitDecryptResult(options: {
senderKeys: Array<SenderKeyType>;
sessions: Array<SessionType>;
unprocessed: Array<UnprocessedType>;
}): Promise<void>;
bulkAddSessions: (array: Array<SessionType>) => Promise<void>;
removeSessionById: (id: SessionIdType) => Promise<number>;
removeSessionsByConversation: (conversationId: string) => Promise<void>;
removeSessionsByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllSessions: () => Promise<number>;
getAllSessions: () => Promise<Array<SessionType>>;
getConversationCount: () => Promise<number>;
saveConversation: (data: ConversationType) => Promise<void>;
saveConversations: (array: Array<ConversationType>) => Promise<void>;
getConversationById: (id: string) => Promise<ConversationType | undefined>;
// updateConversation is a normal data method on Server, a sync batch-add on Client
updateConversations: (array: Array<ConversationType>) => Promise<void>;
// removeConversation handles either one id or an array on Server, and one id on Client
_removeAllConversations: () => Promise<void>;
updateAllConversationColors: (
conversationColor?: ConversationColorType,
customColorData?: {
id: string;
value: CustomColorType;
}
) => Promise<void>;
2022-07-08 20:46:25 +00:00
removeAllProfileKeyCredentials: () => Promise<void>;
getAllConversations: () => Promise<Array<ConversationType>>;
getAllConversationIds: () => Promise<Array<string>>;
getAllGroupsInvolvingServiceId: (
serviceId: ServiceIdString
) => Promise<Array<ConversationType>>;
getMessageCount: (conversationId?: string) => Promise<number>;
2022-03-29 01:10:08 +00:00
getStoryCount: (conversationId: string) => Promise<number>;
saveMessage: (
data: MessageType,
2021-12-20 21:04:02 +00:00
options: {
jobToInsert?: StoredJob;
forceSave?: boolean;
ourAci: AciString;
}
) => Promise<string>;
saveMessages: (
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourAci: AciString }
) => Promise<void>;
removeMessage: (id: string) => Promise<void>;
removeMessages: (ids: ReadonlyArray<string>) => Promise<void>;
2024-03-15 14:20:33 +00:00
pageMessages: (
cursor?: PageMessagesCursorType
) => Promise<PageMessagesResultType>;
finishPageMessages: (cursor: PageMessagesCursorType) => Promise<void>;
getTotalUnreadForConversation: (
conversationId: string,
options: {
2023-03-04 03:03:15 +00:00
storyId: string | undefined;
includeStoryReplies: boolean;
}
) => Promise<number>;
getTotalUnreadMentionsOfMeForConversation: (
conversationId: string,
options: {
storyId?: string;
includeStoryReplies: boolean;
}
) => Promise<number>;
getOldestUnreadMentionOfMeForConversation(
conversationId: string,
options: {
storyId?: string;
includeStoryReplies: boolean;
}
): Promise<MessageMetricsType | undefined>;
getUnreadByConversationAndMarkRead: (options: {
conversationId: string;
includeStoryReplies: boolean;
newestUnreadAt: number;
now?: number;
readAt?: number;
2023-03-04 03:03:15 +00:00
storyId?: string;
2022-07-28 16:35:29 +00:00
}) => Promise<GetUnreadByConversationAndMarkReadResultType>;
2023-03-27 23:48:57 +00:00
getUnreadEditedMessagesAndMarkRead: (options: {
conversationId: string;
2023-03-27 23:48:57 +00:00
newestUnreadAt: number;
}) => Promise<GetUnreadByConversationAndMarkReadResultType>;
getUnreadReactionsAndMarkRead: (options: {
conversationId: string;
newestUnreadAt: number;
2023-03-04 03:03:15 +00:00
storyId?: string;
2022-07-28 16:35:29 +00:00
}) => Promise<Array<ReactionResultType>>;
markReactionAsRead: (
targetAuthorServiceId: ServiceIdString,
targetTimestamp: number
) => Promise<ReactionType | undefined>;
removeReactionFromConversation: (reaction: {
emoji: string;
fromId: string;
targetAuthorServiceId: ServiceIdString;
targetTimestamp: number;
}) => Promise<void>;
getReactionByTimestamp: (
fromId: string,
timestamp: number
) => Promise<ReactionType | undefined>;
addReaction: (
reactionObj: ReactionType,
options: {
readStatus: ReactionReadStatus;
}
) => Promise<void>;
_getAllReactions: () => Promise<Array<ReactionType>>;
_removeAllReactions: () => Promise<void>;
getMessageBySender: (options: {
source?: string;
2023-08-16 20:54:39 +00:00
sourceServiceId?: ServiceIdString;
sourceDevice?: number;
sent_at: number;
}) => Promise<MessageType | undefined>;
getMessageById: (id: string) => Promise<MessageType | undefined>;
2023-03-20 22:23:53 +00:00
getMessagesById: (
messageIds: ReadonlyArray<string>
) => Promise<Array<MessageType>>;
_getAllMessages: () => Promise<Array<MessageType>>;
2023-03-27 23:48:57 +00:00
_getAllEditedMessages: () => Promise<
Array<{ messageId: string; sentAt: number }>
>;
_removeAllMessages: () => Promise<void>;
getAllMessageIds: () => Promise<Array<string>>;
getMessagesBySentAt: (sentAt: number) => Promise<Array<MessageType>>;
getExpiredMessages: () => Promise<Array<MessageType>>;
getMessagesUnexpectedlyMissingExpirationStartTimestamp: () => Promise<
Array<MessageType>
>;
getSoonestMessageExpiry: () => Promise<undefined | number>;
getNextTapToViewMessageTimestampToAgeOut: () => Promise<undefined | number>;
getTapToViewMessagesNeedingErase: () => Promise<Array<MessageType>>;
// getOlderMessagesByConversation is JSON on server, full message on Client
getAllStories: (options: {
conversationId?: string;
2023-08-16 20:54:39 +00:00
sourceServiceId?: ServiceIdString;
2022-11-28 17:19:48 +00:00
}) => Promise<GetAllStoriesResultType>;
// getNewerMessagesByConversation is JSON on server, full message on Client
2023-03-04 03:03:15 +00:00
getMessageMetricsForConversation: (options: {
conversationId: string;
storyId?: string;
includeStoryReplies: boolean;
}) => Promise<ConversationMetricsType>;
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
getConversationMessageStats: (options: {
conversationId: string;
includeStoryReplies: boolean;
}) => Promise<ConversationMessageStatsType>;
getLastConversationMessage(options: {
conversationId: string;
}): Promise<MessageType | undefined>;
2023-08-09 00:53:06 +00:00
getAllCallHistory: () => Promise<ReadonlyArray<CallHistoryDetails>>;
clearCallHistory: (beforeTimestamp: number) => Promise<Array<string>>;
cleanupCallHistoryMessages: () => Promise<void>;
getCallHistoryUnreadCount(): Promise<number>;
markCallHistoryRead(callId: string): Promise<void>;
markAllCallHistoryRead(
beforeTimestamp: number
): Promise<ReadonlyArray<string>>;
2023-08-09 00:53:06 +00:00
getCallHistoryMessageByCallId(options: {
conversationId: string;
callId: string;
}): Promise<MessageType | undefined>;
getCallHistory(
callId: string,
peerId: ServiceIdString | string
2023-08-09 00:53:06 +00:00
): Promise<CallHistoryDetails | undefined>;
getCallHistoryGroupsCount(filter: CallHistoryFilter): Promise<number>;
getCallHistoryGroups(
filter: CallHistoryFilter,
pagination: CallHistoryPagination
): Promise<Array<CallHistoryGroup>>;
saveCallHistory(callHistory: CallHistoryDetails): Promise<void>;
hasGroupCallHistoryMessage: (
conversationId: string,
eraId: string
) => Promise<boolean>;
2024-02-08 18:01:30 +00:00
markCallHistoryMissed(callIds: ReadonlyArray<string>): Promise<void>;
getRecentStaleRingsAndMarkOlderMissed(): Promise<
ReadonlyArray<MaybeStaleCallHistory>
>;
migrateConversationMessages: (
obsoleteId: string,
currentId: string
) => Promise<void>;
2023-03-20 22:23:53 +00:00
getMessagesBetween: (
conversationId: string,
options: GetMessagesBetweenOptions
) => Promise<Array<string>>;
getNearbyMessageFromDeletedSet: (
options: GetNearbyMessageFromDeletedSetOptionsType
) => Promise<string | null>;
2023-03-27 23:48:57 +00:00
saveEditedMessage: (
mainMessage: MessageType,
ourAci: AciString,
2023-03-27 23:48:57 +00:00
opts: EditedMessageType
) => Promise<void>;
getUnprocessedCount: () => Promise<number>;
getUnprocessedByIdsAndIncrementAttempts: (
ids: ReadonlyArray<string>
) => Promise<Array<UnprocessedType>>;
getAllUnprocessedIds: () => Promise<Array<string>>;
updateUnprocessedWithData: (
id: string,
data: UnprocessedUpdateType
) => Promise<void>;
updateUnprocessedsWithData: (
array: Array<{ id: string; data: UnprocessedUpdateType }>
) => Promise<void>;
getUnprocessedById: (id: string) => Promise<UnprocessedType | undefined>;
2021-02-26 23:42:45 +00:00
removeUnprocessed: (id: string | Array<string>) => Promise<void>;
/** only for testing */
removeAllUnprocessed: () => Promise<void>;
getAttachmentDownloadJobById: (
id: string
) => Promise<AttachmentDownloadJobType | undefined>;
getNextAttachmentDownloadJobs: (
limit?: number,
options?: { timestamp?: number }
) => Promise<Array<AttachmentDownloadJobType>>;
saveAttachmentDownloadJob: (job: AttachmentDownloadJobType) => Promise<void>;
resetAttachmentDownloadPending: () => Promise<void>;
setAttachmentDownloadJobPending: (
id: string,
pending: boolean
) => Promise<void>;
removeAttachmentDownloadJob: (id: string) => Promise<number>;
removeAllAttachmentDownloadJobs: () => Promise<number>;
createOrUpdateStickerPack: (pack: StickerPackType) => Promise<void>;
updateStickerPackStatus: (
id: string,
status: StickerPackStatusType,
options?: { timestamp: number }
) => Promise<void>;
2022-08-03 17:10:49 +00:00
updateStickerPackInfo: (info: StickerPackInfoType) => Promise<void>;
createOrUpdateSticker: (sticker: StickerType) => Promise<void>;
updateStickerLastUsed: (
packId: string,
stickerId: number,
lastUsed: number
) => Promise<void>;
addStickerPackReference: (messageId: string, packId: string) => Promise<void>;
deleteStickerPackReference: (
messageId: string,
packId: string
) => Promise<ReadonlyArray<string> | undefined>;
getStickerCount: () => Promise<number>;
deleteStickerPack: (packId: string) => Promise<Array<string>>;
getAllStickerPacks: () => Promise<Array<StickerPackType>>;
2022-08-03 17:10:49 +00:00
addUninstalledStickerPack: (
pack: UninstalledStickerPackType
) => Promise<void>;
removeUninstalledStickerPack: (packId: string) => Promise<void>;
getInstalledStickerPacks: () => Promise<Array<StickerPackType>>;
getUninstalledStickerPacks: () => Promise<Array<UninstalledStickerPackType>>;
installStickerPack: (packId: string, timestamp: number) => Promise<void>;
uninstallStickerPack: (packId: string, timestamp: number) => Promise<void>;
getStickerPackInfo: (
packId: string
) => Promise<StickerPackInfoType | undefined>;
getAllStickers: () => Promise<Array<StickerType>>;
getRecentStickers: (options?: {
limit?: number;
}) => Promise<Array<StickerType>>;
2021-01-27 22:39:45 +00:00
clearAllErrorStickerPackAttempts: () => Promise<void>;
updateEmojiUsage: (shortName: string, timeUsed?: number) => Promise<void>;
getRecentEmojis: (limit?: number) => Promise<Array<EmojiType>>;
2021-11-02 23:01:13 +00:00
getAllBadges(): Promise<Array<BadgeType>>;
updateOrCreateBadges(badges: ReadonlyArray<BadgeType>): Promise<void>;
badgeImageFileDownloaded(url: string, localPath: string): Promise<void>;
_getAllStoryDistributions(): Promise<Array<StoryDistributionType>>;
_getAllStoryDistributionMembers(): Promise<
Array<StoryDistributionMemberType>
>;
_deleteAllStoryDistributions(): Promise<void>;
createNewStoryDistribution(
distribution: StoryDistributionWithMembersType
): Promise<void>;
getAllStoryDistributionsWithMembers(): Promise<
Array<StoryDistributionWithMembersType>
>;
2022-03-04 21:14:52 +00:00
getStoryDistributionWithMembers(
id: string
): Promise<StoryDistributionWithMembersType | undefined>;
modifyStoryDistribution(distribution: StoryDistributionType): Promise<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
}
): Promise<void>;
modifyStoryDistributionWithMembers(
distribution: StoryDistributionType,
options: {
toAdd: Array<ServiceIdString>;
toRemove: Array<ServiceIdString>;
}
): Promise<void>;
deleteStoryDistribution(id: StoryDistributionIdString): Promise<void>;
_getAllStoryReads(): Promise<Array<StoryReadType>>;
_deleteAllStoryReads(): Promise<void>;
addNewStoryRead(read: StoryReadType): Promise<void>;
getLastStoryReadsForAuthor(options: {
authorId: ServiceIdString;
conversationId?: string;
limit?: number;
}): Promise<Array<StoryReadType>>;
2022-03-29 01:10:08 +00:00
countStoryReadsByConversation(conversationId: string): Promise<number>;
removeAll: () => Promise<void>;
removeAllConfiguration: () => Promise<void>;
eraseStorageServiceState: () => Promise<void>;
getMessagesNeedingUpgrade: (
limit: number,
options: { maxVersion: number }
) => Promise<Array<MessageType>>;
getMessagesWithVisualMediaAttachments: (
conversationId: string,
options: { limit: number }
) => Promise<Array<MessageType>>;
getMessagesWithFileAttachments: (
conversationId: string,
options: { limit: number }
) => Promise<Array<MessageType>>;
getMessageServerGuidsForSpam: (
conversationId: string
) => Promise<Array<string>>;
2021-04-29 23:02:27 +00:00
getJobsInQueue(queueType: string): Promise<Array<StoredJob>>;
insertJob(job: Readonly<StoredJob>): Promise<void>;
deleteJob(id: string): Promise<void>;
2021-05-28 16:15:17 +00:00
wasGroupCallRingPreviouslyCanceled(ringId: bigint): Promise<boolean>;
processGroupCallRingCancellation(ringId: bigint): Promise<void>;
cleanExpiredGroupCallRingCancellations(): Promise<void>;
2021-08-20 16:06:15 +00:00
2021-09-15 18:45:22 +00:00
getMaxMessageCounter(): Promise<number | undefined>;
getStatisticsForLogging(): Promise<Record<string, string>>;
2023-10-10 23:55:32 +00:00
optimizeFTS: (
state?: FTSOptimizationStateType
) => Promise<FTSOptimizationStateType | undefined>;
};
export type ServerInterface = DataInterface & {
// Differing signature on client/server
updateConversation: (data: ConversationType) => Promise<void>;
removeConversation: (id: Array<string> | string) => Promise<void>;
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>;
}) => Promise<Array<ServerSearchResultMessageType>>;
getRecentStoryReplies(
storyId: string,
options?: GetRecentStoryRepliesOptionsType
): Promise<Array<MessageTypeUnhydrated>>;
getOlderMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
) => Promise<Array<MessageTypeUnhydrated>>;
getNewerMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
) => Promise<Array<MessageTypeUnhydrated>>;
2023-03-04 03:03:15 +00:00
getConversationRangeCenteredOnMessage: (
options: AdjacentMessagesByConversationOptionsType
) => Promise<
2022-07-28 16:35:29 +00:00
GetConversationRangeCenteredOnMessageResultType<MessageTypeUnhydrated>
>;
createOrUpdateIdentityKey: (data: StoredIdentityKeyType) => Promise<void>;
getIdentityKeyById: (
id: IdentityKeyIdType
) => Promise<StoredIdentityKeyType | undefined>;
bulkAddIdentityKeys: (array: Array<StoredIdentityKeyType>) => Promise<void>;
getAllIdentityKeys: () => Promise<Array<StoredIdentityKeyType>>;
createOrUpdateKyberPreKey: (data: StoredKyberPreKeyType) => Promise<void>;
getKyberPreKeyById: (
id: PreKeyIdType
) => Promise<StoredKyberPreKeyType | undefined>;
bulkAddKyberPreKeys: (array: Array<StoredKyberPreKeyType>) => Promise<void>;
getAllKyberPreKeys: () => Promise<Array<StoredKyberPreKeyType>>;
2022-07-28 16:35:29 +00:00
createOrUpdatePreKey: (data: StoredPreKeyType) => Promise<void>;
getPreKeyById: (id: PreKeyIdType) => Promise<StoredPreKeyType | undefined>;
bulkAddPreKeys: (array: Array<StoredPreKeyType>) => Promise<void>;
getAllPreKeys: () => Promise<Array<StoredPreKeyType>>;
createOrUpdateSignedPreKey: (data: StoredSignedPreKeyType) => Promise<void>;
getSignedPreKeyById: (
id: SignedPreKeyIdType
) => Promise<StoredSignedPreKeyType | undefined>;
bulkAddSignedPreKeys: (array: Array<StoredSignedPreKeyType>) => Promise<void>;
getAllSignedPreKeys: () => Promise<Array<StoredSignedPreKeyType>>;
createOrUpdateItem<K extends ItemKeyType>(
data: StoredItemType<K>
): Promise<void>;
getItemById<K extends ItemKeyType>(
id: K
): Promise<StoredItemType<K> | undefined>;
getAllItems: () => Promise<StoredAllItemsType>;
// Server-only
initialize: (options: {
2023-10-10 23:55:32 +00:00
appVersion: string;
configDir: string;
key: string;
logger: LoggerType;
}) => Promise<void>;
getKnownMessageAttachments: (
cursor?: MessageAttachmentsCursorType
) => Promise<GetKnownMessageAttachmentsResultType>;
finishGetKnownMessageAttachments: (
cursor: MessageAttachmentsCursorType
) => Promise<void>;
getKnownConversationAttachments: () => Promise<Array<string>>;
removeKnownStickers: (
allStickers: ReadonlyArray<string>
) => Promise<Array<string>>;
removeKnownDraftAttachments: (
allStickers: ReadonlyArray<string>
) => Promise<Array<string>>;
2021-11-02 23:01:13 +00:00
getAllBadgeImageFileLocalPaths: () => Promise<Set<string>>;
runCorruptionChecks: () => void;
};
export type GetRecentStoryRepliesOptionsType = {
limit?: number;
messageId?: string;
receivedAt?: number;
sentAt?: number;
};
// Differing signature on client/server
export type ClientExclusiveInterface = {
// Differing signature on client/server
updateConversation: (data: ConversationType) => void;
removeConversation: (id: string) => Promise<void>;
flushUpdateConversationBatcher: () => Promise<void>;
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>;
}) => Promise<Array<ClientSearchResultMessageType>>;
getRecentStoryReplies(
storyId: string,
options?: GetRecentStoryRepliesOptionsType
): Promise<Array<MessageAttributesType>>;
getOlderMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
) => Promise<Array<MessageAttributesType>>;
getNewerMessagesByConversation: (
2023-03-04 03:03:15 +00:00
options: AdjacentMessagesByConversationOptionsType
) => Promise<Array<MessageAttributesType>>;
2023-03-04 03:03:15 +00:00
getConversationRangeCenteredOnMessage: (
options: AdjacentMessagesByConversationOptionsType
) => Promise<GetConversationRangeCenteredOnMessageResultType<MessageType>>;
2022-07-28 16:35:29 +00:00
createOrUpdateIdentityKey: (data: IdentityKeyType) => Promise<void>;
getIdentityKeyById: (
id: IdentityKeyIdType
) => Promise<IdentityKeyType | undefined>;
bulkAddIdentityKeys: (array: Array<IdentityKeyType>) => Promise<void>;
getAllIdentityKeys: () => Promise<Array<IdentityKeyType>>;
createOrUpdateKyberPreKey: (data: KyberPreKeyType) => Promise<void>;
getKyberPreKeyById: (
id: PreKeyIdType
) => Promise<KyberPreKeyType | undefined>;
bulkAddKyberPreKeys: (array: Array<KyberPreKeyType>) => Promise<void>;
getAllKyberPreKeys: () => Promise<Array<KyberPreKeyType>>;
2022-07-28 16:35:29 +00:00
createOrUpdatePreKey: (data: PreKeyType) => Promise<void>;
getPreKeyById: (id: PreKeyIdType) => Promise<PreKeyType | undefined>;
bulkAddPreKeys: (array: Array<PreKeyType>) => Promise<void>;
getAllPreKeys: () => Promise<Array<PreKeyType>>;
createOrUpdateSignedPreKey: (data: SignedPreKeyType) => Promise<void>;
getSignedPreKeyById: (
id: SignedPreKeyIdType
) => Promise<SignedPreKeyType | undefined>;
bulkAddSignedPreKeys: (array: Array<SignedPreKeyType>) => Promise<void>;
getAllSignedPreKeys: () => Promise<Array<SignedPreKeyType>>;
createOrUpdateItem<K extends ItemKeyType>(data: ItemType<K>): Promise<void>;
getItemById<K extends ItemKeyType>(id: K): Promise<ItemType<K> | undefined>;
getAllItems: () => Promise<AllItemsType>;
// Client-side only
shutdown: () => Promise<void>;
removeAllMessagesInConversation: (
conversationId: string,
2021-01-13 00:42:15 +00:00
options: {
logId: string;
}
) => Promise<void>;
removeOtherData: () => Promise<void>;
cleanupOrphanedAttachments: () => Promise<void>;
ensureFilePermissions: () => Promise<void>;
};
export type ClientInterface = DataInterface & ClientExclusiveInterface;