Call link call history

This commit is contained in:
ayumi-signal 2024-04-01 12:19:35 -07:00 committed by GitHub
parent ed940f6f83
commit 00d6379bae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 1124 additions and 204 deletions

View file

@ -10,7 +10,16 @@ import {
} from './zkgroup';
import { getCheckedCallLinkAuthCredentialsForToday } from '../services/groupCredentialFetcher';
import * as durations from './durations';
import type { CallLinkConversationType, CallLinkType } from '../types/CallLink';
import * as Bytes from '../Bytes';
import type {
CallLinkConversationType,
CallLinkType,
CallLinkRecord,
} from '../types/CallLink';
import {
callLinkRecordSchema,
toCallLinkRestrictions,
} from '../types/CallLink';
import type { LocalizerType } from '../types/Util';
export function getRoomIdFromRootKey(rootKey: CallLinkRootKey): string {
@ -71,3 +80,47 @@ export function callLinkToConversation(
badges: [],
};
}
/**
* DB record conversions
*/
export function callLinkToRecord(callLink: CallLinkType): CallLinkRecord {
if (callLink.rootKey == null) {
throw new Error('CallLink.callLinkToRecord: rootKey is null');
}
// rootKey has a RingRTC parsing function, adminKey is just bytes
const rootKey = callLink.rootKey
? CallLinkRootKey.parse(callLink.rootKey).bytes
: null;
const adminKey = callLink.adminKey
? Bytes.fromBase64(callLink.adminKey)
: null;
return callLinkRecordSchema.parse({
roomId: callLink.roomId,
rootKey,
adminKey,
name: callLink.name,
restrictions: callLink.restrictions,
revoked: callLink.revoked ? 1 : 0,
expiration: callLink.expiration,
});
}
export function callLinkFromRecord(record: CallLinkRecord): CallLinkType {
// root keys in memory are strings for simplicity
const rootKey = CallLinkRootKey.fromBytes(
record.rootKey as Buffer
).toString();
const adminKey = record.adminKey ? Bytes.toBase64(record.adminKey) : null;
return {
roomId: record.roomId,
rootKey,
adminKey,
name: record.name,
restrictions: toCallLinkRestrictions(record.restrictions),
revoked: record.revoked === 1,
expiration: record.expiration,
};
}