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
|
@ -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