Sync call link call history
This commit is contained in:
parent
ce83195170
commit
2785501f82
26 changed files with 800 additions and 175 deletions
|
@ -29,7 +29,7 @@ import type {
|
|||
CallHistoryGroup,
|
||||
CallHistoryPagination,
|
||||
} from '../types/CallDisposition';
|
||||
import type { CallLinkType, CallLinkRestrictions } from '../types/CallLink';
|
||||
import type { CallLinkStateType, CallLinkType } from '../types/CallLink';
|
||||
import type { AttachmentDownloadJobType } from '../types/AttachmentDownload';
|
||||
|
||||
export type AdjacentMessagesByConversationOptionsType = Readonly<{
|
||||
|
@ -681,13 +681,15 @@ export type DataInterface = {
|
|||
>;
|
||||
callLinkExists(roomId: string): Promise<boolean>;
|
||||
getAllCallLinks: () => Promise<ReadonlyArray<CallLinkType>>;
|
||||
getCallLinkByRoomId: (roomId: string) => Promise<CallLinkType | undefined>;
|
||||
insertCallLink(callLink: CallLinkType): Promise<void>;
|
||||
updateCallLinkAdminKeyByRoomId(
|
||||
roomId: string,
|
||||
adminKey: string
|
||||
): Promise<void>;
|
||||
updateCallLinkState(
|
||||
roomId: string,
|
||||
name: string,
|
||||
restrictions: CallLinkRestrictions,
|
||||
expiration: number | null,
|
||||
revoked: boolean
|
||||
callLinkState: CallLinkStateType
|
||||
): Promise<void>;
|
||||
migrateConversationMessages: (
|
||||
obsoleteId: string,
|
||||
|
|
|
@ -169,7 +169,9 @@ import {
|
|||
import {
|
||||
callLinkExists,
|
||||
getAllCallLinks,
|
||||
getCallLinkByRoomId,
|
||||
insertCallLink,
|
||||
updateCallLinkAdminKeyByRoomId,
|
||||
updateCallLinkState,
|
||||
} from './server/callLinks';
|
||||
import { CallMode } from '../types/Calling';
|
||||
|
@ -341,7 +343,9 @@ const dataInterface: ServerInterface = {
|
|||
getRecentStaleRingsAndMarkOlderMissed,
|
||||
callLinkExists,
|
||||
getAllCallLinks,
|
||||
getCallLinkByRoomId,
|
||||
insertCallLink,
|
||||
updateCallLinkAdminKeyByRoomId,
|
||||
updateCallLinkState,
|
||||
migrateConversationMessages,
|
||||
getMessagesBetween,
|
||||
|
|
|
@ -3,12 +3,16 @@
|
|||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import { CallLinkRootKey } from '@signalapp/ringrtc';
|
||||
import type { CallLinkRestrictions, CallLinkType } from '../../types/CallLink';
|
||||
import type { CallLinkStateType, CallLinkType } from '../../types/CallLink';
|
||||
import {
|
||||
callLinkRestrictionsSchema,
|
||||
callLinkRecordSchema,
|
||||
} from '../../types/CallLink';
|
||||
import { callLinkToRecord, callLinkFromRecord } from '../../util/callLinks';
|
||||
import {
|
||||
callLinkToRecord,
|
||||
callLinkFromRecord,
|
||||
toAdminKeyBytes,
|
||||
} from '../../util/callLinks';
|
||||
import { getReadonlyInstance, getWritableInstance, prepare } from '../Server';
|
||||
import { sql } from '../util';
|
||||
import { strictAssert } from '../../util/assert';
|
||||
|
@ -23,6 +27,23 @@ export async function callLinkExists(roomId: string): Promise<boolean> {
|
|||
return db.prepare(query).pluck(true).get(params) === 1;
|
||||
}
|
||||
|
||||
export async function getCallLinkByRoomId(
|
||||
roomId: string
|
||||
): Promise<CallLinkType | undefined> {
|
||||
const db = getReadonlyInstance();
|
||||
const row = prepare(db, 'SELECT * FROM callLinks WHERE roomId = $roomId').get(
|
||||
{
|
||||
roomId,
|
||||
}
|
||||
);
|
||||
|
||||
if (!row) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return callLinkFromRecord(callLinkRecordSchema.parse(row));
|
||||
}
|
||||
|
||||
export async function getAllCallLinks(): Promise<ReadonlyArray<CallLinkType>> {
|
||||
const db = getReadonlyInstance();
|
||||
const [query] = sql`
|
||||
|
@ -70,11 +91,9 @@ export async function insertCallLink(callLink: CallLinkType): Promise<void> {
|
|||
|
||||
export async function updateCallLinkState(
|
||||
roomId: string,
|
||||
name: string,
|
||||
restrictions: CallLinkRestrictions,
|
||||
expiration: number,
|
||||
revoked: boolean
|
||||
callLinkState: CallLinkStateType
|
||||
): Promise<void> {
|
||||
const { name, restrictions, expiration, revoked } = callLinkState;
|
||||
const db = await getWritableInstance();
|
||||
const restrictionsValue = callLinkRestrictionsSchema.parse(restrictions);
|
||||
const [query, params] = sql`
|
||||
|
@ -89,6 +108,22 @@ export async function updateCallLinkState(
|
|||
db.prepare(query).run(params);
|
||||
}
|
||||
|
||||
export async function updateCallLinkAdminKeyByRoomId(
|
||||
roomId: string,
|
||||
adminKey: string
|
||||
): Promise<void> {
|
||||
const db = await getWritableInstance();
|
||||
const adminKeyBytes = toAdminKeyBytes(adminKey);
|
||||
prepare(
|
||||
db,
|
||||
`
|
||||
UPDATE callLinks
|
||||
SET adminKey = $adminKeyBytes
|
||||
WHERE roomId = $roomId;
|
||||
`
|
||||
).run({ roomId, adminKeyBytes });
|
||||
}
|
||||
|
||||
function assertRoomIdMatchesRootKey(roomId: string, rootKey: string): void {
|
||||
const derivedRoomId = CallLinkRootKey.parse(rootKey)
|
||||
.deriveRoomId()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue