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:
automated-signal 2024-10-15 15:15:21 -05:00 committed by GitHub
parent 6859b1a220
commit 23e3a847d1
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 });
}