Handle PniChangeNumber
This commit is contained in:
parent
412f07d2a2
commit
79b48115e6
32 changed files with 1086 additions and 485 deletions
449
ts/sql/Client.ts
449
ts/sql/Client.ts
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,7 @@
|
|||
// Copyright 2020-2022 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,
|
||||
|
@ -15,7 +13,7 @@ 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 { BodyRangesType, BytesToStrings } from '../types/Util';
|
||||
import type { QualifiedAddressStringType } from '../types/QualifiedAddress';
|
||||
import type { UUIDStringType } from '../types/UUID';
|
||||
import type { BadgeType } from '../badges/types';
|
||||
|
@ -66,14 +64,27 @@ export type IdentityKeyType = {
|
|||
timestamp: number;
|
||||
verified: number;
|
||||
};
|
||||
export type StoredIdentityKeyType = {
|
||||
firstUse: boolean;
|
||||
id: UUIDStringType | `conversation:${string}`;
|
||||
nonblockingApproval: boolean;
|
||||
publicKey: string;
|
||||
timestamp: number;
|
||||
verified: number;
|
||||
};
|
||||
export type IdentityKeyIdType = IdentityKeyType['id'];
|
||||
|
||||
export type ItemKeyType = keyof StorageAccessType;
|
||||
export type AllItemsType = Partial<StorageAccessType>;
|
||||
export type StoredAllItemsType = Partial<BytesToStrings<StorageAccessType>>;
|
||||
export type ItemType<K extends ItemKeyType> = {
|
||||
id: K;
|
||||
value: StorageAccessType[K];
|
||||
};
|
||||
export type StoredItemType<K extends ItemKeyType> = {
|
||||
id: K;
|
||||
value: BytesToStrings<StorageAccessType[K]>;
|
||||
};
|
||||
export type MessageType = MessageAttributesType;
|
||||
export type MessageTypeUnhydrated = {
|
||||
json: string;
|
||||
|
@ -85,6 +96,13 @@ export type PreKeyType = {
|
|||
privateKey: Uint8Array;
|
||||
publicKey: Uint8Array;
|
||||
};
|
||||
export type StoredPreKeyType = {
|
||||
id: `${UUIDStringType}:${number}`;
|
||||
keyId: number;
|
||||
ourUuid: UUIDStringType;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
};
|
||||
export type PreKeyIdType = PreKeyType['id'];
|
||||
export type ServerSearchResultMessageType = {
|
||||
json: string;
|
||||
|
@ -149,6 +167,15 @@ export type SignedPreKeyType = {
|
|||
privateKey: Uint8Array;
|
||||
publicKey: Uint8Array;
|
||||
};
|
||||
export type StoredSignedPreKeyType = {
|
||||
confirmed: boolean;
|
||||
created_at: number;
|
||||
ourUuid: UUIDStringType;
|
||||
id: `${UUIDStringType}:${number}`;
|
||||
keyId: number;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
};
|
||||
export type SignedPreKeyIdType = SignedPreKeyType['id'];
|
||||
|
||||
export type StickerType = Readonly<{
|
||||
|
@ -205,6 +232,7 @@ export type UnprocessedType = {
|
|||
sourceUuid?: UUIDStringType;
|
||||
sourceDevice?: number;
|
||||
destinationUuid?: string;
|
||||
updatedPni?: string;
|
||||
serverGuid?: string;
|
||||
serverTimestamp?: number;
|
||||
decrypted?: string;
|
||||
|
@ -262,41 +290,49 @@ export type StoryReadType = Readonly<{
|
|||
storyReadDate: number;
|
||||
}>;
|
||||
|
||||
export type ReactionResultType = Pick<
|
||||
ReactionType,
|
||||
'targetAuthorUuid' | 'targetTimestamp' | 'messageId'
|
||||
> & { rowid: number };
|
||||
|
||||
export type GetUnreadByConversationAndMarkReadResultType = Array<
|
||||
{ originalReadStatus: ReadStatus | undefined } & Pick<
|
||||
MessageType,
|
||||
| 'id'
|
||||
| 'source'
|
||||
| 'sourceUuid'
|
||||
| 'sent_at'
|
||||
| 'type'
|
||||
| 'readStatus'
|
||||
| 'seenStatus'
|
||||
>
|
||||
>;
|
||||
|
||||
export type GetConversationRangeCenteredOnMessageResultType<Message> =
|
||||
Readonly<{
|
||||
older: Array<Message>;
|
||||
newer: Array<Message>;
|
||||
metrics: ConversationMetricsType;
|
||||
}>;
|
||||
|
||||
export type DataInterface = {
|
||||
close: () => Promise<void>;
|
||||
removeDB: () => Promise<void>;
|
||||
removeIndexedDBFiles: () => Promise<void>;
|
||||
|
||||
createOrUpdateIdentityKey: (data: IdentityKeyType) => Promise<void>;
|
||||
getIdentityKeyById: (
|
||||
id: IdentityKeyIdType
|
||||
) => Promise<IdentityKeyType | undefined>;
|
||||
bulkAddIdentityKeys: (array: Array<IdentityKeyType>) => Promise<void>;
|
||||
removeIdentityKeyById: (id: IdentityKeyIdType) => Promise<void>;
|
||||
removeAllIdentityKeys: () => Promise<void>;
|
||||
getAllIdentityKeys: () => Promise<Array<IdentityKeyType>>;
|
||||
|
||||
createOrUpdatePreKey: (data: PreKeyType) => Promise<void>;
|
||||
getPreKeyById: (id: PreKeyIdType) => Promise<PreKeyType | undefined>;
|
||||
bulkAddPreKeys: (array: Array<PreKeyType>) => Promise<void>;
|
||||
removePreKeyById: (id: PreKeyIdType) => Promise<void>;
|
||||
removePreKeysByUuid: (uuid: UUIDStringType) => Promise<void>;
|
||||
removeAllPreKeys: () => Promise<void>;
|
||||
getAllPreKeys: () => Promise<Array<PreKeyType>>;
|
||||
|
||||
createOrUpdateSignedPreKey: (data: SignedPreKeyType) => Promise<void>;
|
||||
getSignedPreKeyById: (
|
||||
id: SignedPreKeyIdType
|
||||
) => Promise<SignedPreKeyType | undefined>;
|
||||
bulkAddSignedPreKeys: (array: Array<SignedPreKeyType>) => Promise<void>;
|
||||
removeSignedPreKeyById: (id: SignedPreKeyIdType) => Promise<void>;
|
||||
removeSignedPreKeysByUuid: (uuid: UUIDStringType) => Promise<void>;
|
||||
removeAllSignedPreKeys: () => 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>;
|
||||
removeItemById: (id: ItemKeyType) => Promise<void>;
|
||||
removeAllItems: () => Promise<void>;
|
||||
getAllItems: () => Promise<AllItemsType>;
|
||||
removeItemById: (id: ItemKeyType) => Promise<void>;
|
||||
|
||||
createOrUpdateSenderKey: (key: SenderKeyType) => Promise<void>;
|
||||
getSenderKeyById: (id: SenderKeyIdType) => Promise<SenderKeyType | undefined>;
|
||||
|
@ -402,29 +438,12 @@ export type DataInterface = {
|
|||
newestUnreadAt: number;
|
||||
readAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
}) => Promise<
|
||||
Array<
|
||||
{ originalReadStatus: ReadStatus | undefined } & Pick<
|
||||
MessageType,
|
||||
| 'id'
|
||||
| 'readStatus'
|
||||
| 'seenStatus'
|
||||
| 'sent_at'
|
||||
| 'source'
|
||||
| 'sourceUuid'
|
||||
| 'type'
|
||||
>
|
||||
>
|
||||
>;
|
||||
}) => Promise<GetUnreadByConversationAndMarkReadResultType>;
|
||||
getUnreadReactionsAndMarkRead: (options: {
|
||||
conversationId: string;
|
||||
newestUnreadAt: number;
|
||||
storyId?: UUIDStringType;
|
||||
}) => Promise<
|
||||
Array<
|
||||
Pick<ReactionType, 'targetAuthorUuid' | 'targetTimestamp' | 'messageId'>
|
||||
>
|
||||
>;
|
||||
}) => Promise<Array<ReactionResultType>>;
|
||||
markReactionAsRead: (
|
||||
targetAuthorUuid: string,
|
||||
targetTimestamp: number
|
||||
|
@ -671,11 +690,36 @@ export type ServerInterface = DataInterface & {
|
|||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}) => Promise<{
|
||||
older: Array<MessageTypeUnhydrated>;
|
||||
newer: Array<MessageTypeUnhydrated>;
|
||||
metrics: ConversationMetricsType;
|
||||
}>;
|
||||
}) => Promise<
|
||||
GetConversationRangeCenteredOnMessageResultType<MessageTypeUnhydrated>
|
||||
>;
|
||||
|
||||
createOrUpdateIdentityKey: (data: StoredIdentityKeyType) => Promise<void>;
|
||||
getIdentityKeyById: (
|
||||
id: IdentityKeyIdType
|
||||
) => Promise<StoredIdentityKeyType | undefined>;
|
||||
bulkAddIdentityKeys: (array: Array<StoredIdentityKeyType>) => Promise<void>;
|
||||
getAllIdentityKeys: () => Promise<Array<StoredIdentityKeyType>>;
|
||||
|
||||
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
|
||||
|
||||
|
@ -744,11 +788,30 @@ export type ClientInterface = DataInterface & {
|
|||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}) => Promise<{
|
||||
older: Array<MessageAttributesType>;
|
||||
newer: Array<MessageAttributesType>;
|
||||
metrics: ConversationMetricsType;
|
||||
}>;
|
||||
}) => Promise<GetConversationRangeCenteredOnMessageResultType<MessageType>>;
|
||||
|
||||
createOrUpdateIdentityKey: (data: IdentityKeyType) => Promise<void>;
|
||||
getIdentityKeyById: (
|
||||
id: IdentityKeyIdType
|
||||
) => Promise<IdentityKeyType | undefined>;
|
||||
bulkAddIdentityKeys: (array: Array<IdentityKeyType>) => Promise<void>;
|
||||
getAllIdentityKeys: () => Promise<Array<IdentityKeyType>>;
|
||||
|
||||
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
|
||||
|
||||
|
@ -774,10 +837,10 @@ export type ClientInterface = DataInterface & {
|
|||
export type ClientJobType = {
|
||||
fnName: string;
|
||||
start: number;
|
||||
resolve?: Function;
|
||||
reject?: Function;
|
||||
resolve?: (value: unknown) => void;
|
||||
reject?: (error: Error) => void;
|
||||
|
||||
// Only in DEBUG mode
|
||||
complete?: boolean;
|
||||
args?: Array<any>;
|
||||
args?: ReadonlyArray<unknown>;
|
||||
};
|
||||
|
|
|
@ -71,22 +71,25 @@ import {
|
|||
import { updateSchema } from './migrations';
|
||||
|
||||
import type {
|
||||
AllItemsType,
|
||||
StoredAllItemsType,
|
||||
AttachmentDownloadJobType,
|
||||
ConversationMetricsType,
|
||||
ConversationType,
|
||||
DeleteSentProtoRecipientOptionsType,
|
||||
EmojiType,
|
||||
GetConversationRangeCenteredOnMessageResultType,
|
||||
GetUnreadByConversationAndMarkReadResultType,
|
||||
IdentityKeyIdType,
|
||||
IdentityKeyType,
|
||||
StoredIdentityKeyType,
|
||||
ItemKeyType,
|
||||
ItemType,
|
||||
StoredItemType,
|
||||
ConversationMessageStatsType,
|
||||
MessageMetricsType,
|
||||
MessageType,
|
||||
MessageTypeUnhydrated,
|
||||
PreKeyIdType,
|
||||
PreKeyType,
|
||||
ReactionResultType,
|
||||
StoredPreKeyType,
|
||||
ServerSearchResultMessageType,
|
||||
SenderKeyIdType,
|
||||
SenderKeyType,
|
||||
|
@ -100,7 +103,7 @@ import type {
|
|||
SessionIdType,
|
||||
SessionType,
|
||||
SignedPreKeyIdType,
|
||||
SignedPreKeyType,
|
||||
StoredSignedPreKeyType,
|
||||
StickerPackStatusType,
|
||||
StickerPackType,
|
||||
StickerType,
|
||||
|
@ -149,6 +152,7 @@ const dataInterface: ServerInterface = {
|
|||
getPreKeyById,
|
||||
bulkAddPreKeys,
|
||||
removePreKeyById,
|
||||
removePreKeysByUuid,
|
||||
removeAllPreKeys,
|
||||
getAllPreKeys,
|
||||
|
||||
|
@ -156,6 +160,7 @@ const dataInterface: ServerInterface = {
|
|||
getSignedPreKeyById,
|
||||
bulkAddSignedPreKeys,
|
||||
removeSignedPreKeyById,
|
||||
removeSignedPreKeysByUuid,
|
||||
removeAllSignedPreKeys,
|
||||
getAllSignedPreKeys,
|
||||
|
||||
|
@ -634,16 +639,18 @@ function getInstance(): Database {
|
|||
}
|
||||
|
||||
const IDENTITY_KEYS_TABLE = 'identityKeys';
|
||||
async function createOrUpdateIdentityKey(data: IdentityKeyType): Promise<void> {
|
||||
async function createOrUpdateIdentityKey(
|
||||
data: StoredIdentityKeyType
|
||||
): Promise<void> {
|
||||
return createOrUpdate(getInstance(), IDENTITY_KEYS_TABLE, data);
|
||||
}
|
||||
async function getIdentityKeyById(
|
||||
id: IdentityKeyIdType
|
||||
): Promise<IdentityKeyType | undefined> {
|
||||
): Promise<StoredIdentityKeyType | undefined> {
|
||||
return getById(getInstance(), IDENTITY_KEYS_TABLE, id);
|
||||
}
|
||||
async function bulkAddIdentityKeys(
|
||||
array: Array<IdentityKeyType>
|
||||
array: Array<StoredIdentityKeyType>
|
||||
): Promise<void> {
|
||||
return bulkAdd(getInstance(), IDENTITY_KEYS_TABLE, array);
|
||||
}
|
||||
|
@ -653,55 +660,67 @@ async function removeIdentityKeyById(id: IdentityKeyIdType): Promise<void> {
|
|||
async function removeAllIdentityKeys(): Promise<void> {
|
||||
return removeAllFromTable(getInstance(), IDENTITY_KEYS_TABLE);
|
||||
}
|
||||
async function getAllIdentityKeys(): Promise<Array<IdentityKeyType>> {
|
||||
async function getAllIdentityKeys(): Promise<Array<StoredIdentityKeyType>> {
|
||||
return getAllFromTable(getInstance(), IDENTITY_KEYS_TABLE);
|
||||
}
|
||||
|
||||
const PRE_KEYS_TABLE = 'preKeys';
|
||||
async function createOrUpdatePreKey(data: PreKeyType): Promise<void> {
|
||||
async function createOrUpdatePreKey(data: StoredPreKeyType): Promise<void> {
|
||||
return createOrUpdate(getInstance(), PRE_KEYS_TABLE, data);
|
||||
}
|
||||
async function getPreKeyById(
|
||||
id: PreKeyIdType
|
||||
): Promise<PreKeyType | undefined> {
|
||||
): Promise<StoredPreKeyType | undefined> {
|
||||
return getById(getInstance(), PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function bulkAddPreKeys(array: Array<PreKeyType>): Promise<void> {
|
||||
async function bulkAddPreKeys(array: Array<StoredPreKeyType>): Promise<void> {
|
||||
return bulkAdd(getInstance(), PRE_KEYS_TABLE, array);
|
||||
}
|
||||
async function removePreKeyById(id: PreKeyIdType): Promise<void> {
|
||||
return removeById(getInstance(), PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function removePreKeysByUuid(uuid: UUIDStringType): Promise<void> {
|
||||
const db = getInstance();
|
||||
db.prepare<Query>('DELETE FROM preKeys WHERE ourUuid IS $uuid;').run({
|
||||
uuid,
|
||||
});
|
||||
}
|
||||
async function removeAllPreKeys(): Promise<void> {
|
||||
return removeAllFromTable(getInstance(), PRE_KEYS_TABLE);
|
||||
}
|
||||
async function getAllPreKeys(): Promise<Array<PreKeyType>> {
|
||||
async function getAllPreKeys(): Promise<Array<StoredPreKeyType>> {
|
||||
return getAllFromTable(getInstance(), PRE_KEYS_TABLE);
|
||||
}
|
||||
|
||||
const SIGNED_PRE_KEYS_TABLE = 'signedPreKeys';
|
||||
async function createOrUpdateSignedPreKey(
|
||||
data: SignedPreKeyType
|
||||
data: StoredSignedPreKeyType
|
||||
): Promise<void> {
|
||||
return createOrUpdate(getInstance(), SIGNED_PRE_KEYS_TABLE, data);
|
||||
}
|
||||
async function getSignedPreKeyById(
|
||||
id: SignedPreKeyIdType
|
||||
): Promise<SignedPreKeyType | undefined> {
|
||||
): Promise<StoredSignedPreKeyType | undefined> {
|
||||
return getById(getInstance(), SIGNED_PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function bulkAddSignedPreKeys(
|
||||
array: Array<SignedPreKeyType>
|
||||
array: Array<StoredSignedPreKeyType>
|
||||
): Promise<void> {
|
||||
return bulkAdd(getInstance(), SIGNED_PRE_KEYS_TABLE, array);
|
||||
}
|
||||
async function removeSignedPreKeyById(id: SignedPreKeyIdType): Promise<void> {
|
||||
return removeById(getInstance(), SIGNED_PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function removeSignedPreKeysByUuid(uuid: UUIDStringType): Promise<void> {
|
||||
const db = getInstance();
|
||||
db.prepare<Query>('DELETE FROM signedPreKeys WHERE ourUuid IS $uuid;').run({
|
||||
uuid,
|
||||
});
|
||||
}
|
||||
async function removeAllSignedPreKeys(): Promise<void> {
|
||||
return removeAllFromTable(getInstance(), SIGNED_PRE_KEYS_TABLE);
|
||||
}
|
||||
async function getAllSignedPreKeys(): Promise<Array<SignedPreKeyType>> {
|
||||
async function getAllSignedPreKeys(): Promise<Array<StoredSignedPreKeyType>> {
|
||||
const db = getInstance();
|
||||
const rows: JSONRows = db
|
||||
.prepare<EmptyQuery>(
|
||||
|
@ -718,16 +737,16 @@ async function getAllSignedPreKeys(): Promise<Array<SignedPreKeyType>> {
|
|||
|
||||
const ITEMS_TABLE = 'items';
|
||||
async function createOrUpdateItem<K extends ItemKeyType>(
|
||||
data: ItemType<K>
|
||||
data: StoredItemType<K>
|
||||
): Promise<void> {
|
||||
return createOrUpdate(getInstance(), ITEMS_TABLE, data);
|
||||
}
|
||||
async function getItemById<K extends ItemKeyType>(
|
||||
id: K
|
||||
): Promise<ItemType<K> | undefined> {
|
||||
): Promise<StoredItemType<K> | undefined> {
|
||||
return getById(getInstance(), ITEMS_TABLE, id);
|
||||
}
|
||||
async function getAllItems(): Promise<AllItemsType> {
|
||||
async function getAllItems(): Promise<StoredAllItemsType> {
|
||||
const db = getInstance();
|
||||
const rows: JSONRows = db
|
||||
.prepare<EmptyQuery>('SELECT json FROM items ORDER BY id ASC;')
|
||||
|
@ -743,7 +762,7 @@ async function getAllItems(): Promise<AllItemsType> {
|
|||
result[id] = value;
|
||||
}
|
||||
|
||||
return result as unknown as AllItemsType;
|
||||
return result as unknown as StoredAllItemsType;
|
||||
}
|
||||
async function removeItemById(id: ItemKeyType): Promise<void> {
|
||||
return removeById(getInstance(), ITEMS_TABLE, id);
|
||||
|
@ -2097,20 +2116,7 @@ async function getUnreadByConversationAndMarkRead({
|
|||
newestUnreadAt: number;
|
||||
storyId?: UUIDStringType;
|
||||
readAt?: number;
|
||||
}): Promise<
|
||||
Array<
|
||||
{ originalReadStatus: ReadStatus | undefined } & Pick<
|
||||
MessageType,
|
||||
| 'id'
|
||||
| 'source'
|
||||
| 'sourceUuid'
|
||||
| 'sent_at'
|
||||
| 'type'
|
||||
| 'readStatus'
|
||||
| 'seenStatus'
|
||||
>
|
||||
>
|
||||
> {
|
||||
}): Promise<GetUnreadByConversationAndMarkReadResultType> {
|
||||
const db = getInstance();
|
||||
return db.transaction(() => {
|
||||
const expirationStartTimestamp = Math.min(Date.now(), readAt ?? Infinity);
|
||||
|
@ -2203,10 +2209,6 @@ async function getUnreadByConversationAndMarkRead({
|
|||
})();
|
||||
}
|
||||
|
||||
type ReactionResultType = Pick<
|
||||
ReactionType,
|
||||
'targetAuthorUuid' | 'targetTimestamp' | 'messageId'
|
||||
> & { rowid: number };
|
||||
async function getUnreadReactionsAndMarkRead({
|
||||
conversationId,
|
||||
newestUnreadAt,
|
||||
|
@ -2869,11 +2871,9 @@ async function getConversationRangeCenteredOnMessage({
|
|||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}): Promise<{
|
||||
older: Array<MessageTypeUnhydrated>;
|
||||
newer: Array<MessageTypeUnhydrated>;
|
||||
metrics: ConversationMetricsType;
|
||||
}> {
|
||||
}): Promise<
|
||||
GetConversationRangeCenteredOnMessageResultType<MessageTypeUnhydrated>
|
||||
> {
|
||||
const db = getInstance();
|
||||
|
||||
return db.transaction(() => {
|
||||
|
|
38
ts/sql/migrations/64-uuid-column-for-pre-keys.ts
Normal file
38
ts/sql/migrations/64-uuid-column-for-pre-keys.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from 'better-sqlite3';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
export default function updateToSchemaVersion64(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 64) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(
|
||||
`
|
||||
ALTER TABLE preKeys
|
||||
ADD COLUMN ourUuid STRING
|
||||
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'));
|
||||
|
||||
CREATE INDEX preKeys_ourUuid ON preKeys (ourUuid);
|
||||
|
||||
ALTER TABLE signedPreKeys
|
||||
ADD COLUMN ourUuid STRING
|
||||
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'));
|
||||
|
||||
CREATE INDEX signedPreKeys_ourUuid ON signedPreKeys (ourUuid);
|
||||
`
|
||||
);
|
||||
|
||||
db.pragma('user_version = 64');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion64: success!');
|
||||
}
|
|
@ -39,6 +39,7 @@ import updateToSchemaVersion60 from './60-update-expiring-index';
|
|||
import updateToSchemaVersion61 from './61-distribution-list-storage';
|
||||
import updateToSchemaVersion62 from './62-add-urgent-to-send-log';
|
||||
import updateToSchemaVersion63 from './63-add-urgent-to-unprocessed';
|
||||
import updateToSchemaVersion64 from './64-uuid-column-for-pre-keys';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -1941,6 +1942,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion61,
|
||||
updateToSchemaVersion62,
|
||||
updateToSchemaVersion63,
|
||||
updateToSchemaVersion64,
|
||||
];
|
||||
|
||||
export function updateSchema(db: Database, logger: LoggerType): void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue