Only create call links from storage sync after refresh confirmed
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
This commit is contained in:
parent
6859b1a220
commit
23e3a847d1
9 changed files with 169 additions and 46 deletions
|
@ -35,6 +35,7 @@ import type {
|
|||
CallLinkRecord,
|
||||
CallLinkStateType,
|
||||
CallLinkType,
|
||||
DefunctCallLinkType,
|
||||
} from '../types/CallLink';
|
||||
import type { AttachmentDownloadJobType } from '../types/AttachmentDownload';
|
||||
import type {
|
||||
|
@ -580,6 +581,7 @@ type ReadableInterface = {
|
|||
eraId: string
|
||||
) => boolean;
|
||||
callLinkExists(roomId: string): boolean;
|
||||
defunctCallLinkExists(roomId: string): boolean;
|
||||
getAllCallLinks: () => ReadonlyArray<CallLinkType>;
|
||||
getCallLinkByRoomId: (roomId: string) => CallLinkType | undefined;
|
||||
getCallLinkRecordByRoomId: (roomId: string) => CallLinkRecord | undefined;
|
||||
|
@ -819,6 +821,7 @@ type WritableInterface = {
|
|||
deleteCallLinkAndHistory(roomId: string): void;
|
||||
finalizeDeleteCallLink(roomId: string): void;
|
||||
_removeAllCallLinks(): void;
|
||||
insertDefunctCallLink(callLink: DefunctCallLinkType): void;
|
||||
deleteCallLinkFromSync(roomId: string): void;
|
||||
migrateConversationMessages: (obsoleteId: string, currentId: string) => void;
|
||||
saveEditedMessage: (
|
||||
|
|
|
@ -172,6 +172,7 @@ import {
|
|||
} from '../types/CallDisposition';
|
||||
import {
|
||||
callLinkExists,
|
||||
defunctCallLinkExists,
|
||||
getAllCallLinks,
|
||||
getCallLinkByRoomId,
|
||||
getCallLinkRecordByRoomId,
|
||||
|
@ -189,6 +190,7 @@ import {
|
|||
beginDeleteCallLink,
|
||||
deleteCallLinkFromSync,
|
||||
_removeAllCallLinks,
|
||||
insertDefunctCallLink,
|
||||
} from './server/callLinks';
|
||||
import {
|
||||
replaceAllEndorsementsForGroup,
|
||||
|
@ -313,6 +315,7 @@ export const DataReader: ServerReadableInterface = {
|
|||
hasGroupCallHistoryMessage,
|
||||
|
||||
callLinkExists,
|
||||
defunctCallLinkExists,
|
||||
getAllCallLinks,
|
||||
getCallLinkByRoomId,
|
||||
getCallLinkRecordByRoomId,
|
||||
|
@ -460,6 +463,7 @@ export const DataWriter: ServerWritableInterface = {
|
|||
finalizeDeleteCallLink,
|
||||
_removeAllCallLinks,
|
||||
deleteCallLinkFromSync,
|
||||
insertDefunctCallLink,
|
||||
migrateConversationMessages,
|
||||
saveEditedMessage,
|
||||
saveEditedMessages,
|
||||
|
@ -6436,6 +6440,7 @@ function removeAll(db: WritableDB): void {
|
|||
DELETE FROM callLinks;
|
||||
DELETE FROM callsHistory;
|
||||
DELETE FROM conversations;
|
||||
DELETE FROM defunctCallLinks;
|
||||
DELETE FROM emojis;
|
||||
DELETE FROM groupCallRingCancellations;
|
||||
DELETE FROM groupSendCombinedEndorsement;
|
||||
|
|
35
ts/sql/migrations/1240-defunct-call-links-table.ts
Normal file
35
ts/sql/migrations/1240-defunct-call-links-table.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { sql } from '../util';
|
||||
|
||||
export const version = 1240;
|
||||
|
||||
export function updateToSchemaVersion1240(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1240) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
const [createTable] = sql`
|
||||
CREATE TABLE defunctCallLinks (
|
||||
roomId TEXT NOT NULL PRIMARY KEY,
|
||||
rootKey BLOB NOT NULL,
|
||||
adminKey BLOB
|
||||
) STRICT;
|
||||
`;
|
||||
|
||||
db.exec(createTable);
|
||||
|
||||
db.pragma('user_version = 1240');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion1240: success!');
|
||||
}
|
|
@ -99,10 +99,11 @@ import { updateToSchemaVersion1190 } from './1190-call-links-storage';
|
|||
import { updateToSchemaVersion1200 } from './1200-attachment-download-source-index';
|
||||
import { updateToSchemaVersion1210 } from './1210-call-history-started-id';
|
||||
import { updateToSchemaVersion1220 } from './1220-blob-sessions';
|
||||
import { updateToSchemaVersion1230 } from './1230-call-links-admin-key-index';
|
||||
import {
|
||||
updateToSchemaVersion1230,
|
||||
updateToSchemaVersion1240,
|
||||
version as MAX_VERSION,
|
||||
} from './1230-call-links-admin-key-index';
|
||||
} from './1240-defunct-call-links-table';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2071,6 +2072,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1210,
|
||||
updateToSchemaVersion1220,
|
||||
updateToSchemaVersion1230,
|
||||
updateToSchemaVersion1240,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
|
@ -6,6 +6,7 @@ import type {
|
|||
CallLinkRecord,
|
||||
CallLinkStateType,
|
||||
CallLinkType,
|
||||
DefunctCallLinkType,
|
||||
} from '../../types/CallLink';
|
||||
import {
|
||||
callLinkRestrictionsSchema,
|
||||
|
@ -15,6 +16,7 @@ import { toAdminKeyBytes } from '../../util/callLinks';
|
|||
import {
|
||||
callLinkToRecord,
|
||||
callLinkFromRecord,
|
||||
toRootKeyBytes,
|
||||
} from '../../util/callLinksRingrtc';
|
||||
import type { ReadableDB, WritableDB } from '../Interface';
|
||||
import { prepare } from '../Server';
|
||||
|
@ -376,3 +378,41 @@ export function _removeAllCallLinks(db: WritableDB): void {
|
|||
`;
|
||||
db.prepare(query).run(params);
|
||||
}
|
||||
|
||||
export function defunctCallLinkExists(db: ReadableDB, roomId: string): boolean {
|
||||
const [query, params] = sql`
|
||||
SELECT 1
|
||||
FROM defunctCallLinks
|
||||
WHERE roomId = ${roomId};
|
||||
`;
|
||||
return db.prepare(query).pluck(true).get(params) === 1;
|
||||
}
|
||||
|
||||
export function insertDefunctCallLink(
|
||||
db: WritableDB,
|
||||
callLink: DefunctCallLinkType
|
||||
): void {
|
||||
const { roomId, rootKey } = callLink;
|
||||
assertRoomIdMatchesRootKey(roomId, rootKey);
|
||||
|
||||
const rootKeyData = toRootKeyBytes(callLink.rootKey);
|
||||
const adminKeyData = callLink.adminKey
|
||||
? toAdminKeyBytes(callLink.adminKey)
|
||||
: null;
|
||||
|
||||
prepare(
|
||||
db,
|
||||
`
|
||||
INSERT INTO defunctCallLinks (
|
||||
roomId,
|
||||
rootKey,
|
||||
adminKey
|
||||
) VALUES (
|
||||
$roomId,
|
||||
$rootKeyData,
|
||||
$adminKeyData
|
||||
)
|
||||
ON CONFLICT (roomId) DO NOTHING;
|
||||
`
|
||||
).run({ roomId, rootKeyData, adminKeyData });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue