Only create call links from storage sync after refresh confirmed

This commit is contained in:
ayumi-signal 2024-10-15 11:49:32 -07:00 committed by GitHub
parent 86abb43aec
commit 568c09c579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 169 additions and 46 deletions

View file

@ -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 });
}