Split keys out of stored data types

This commit is contained in:
Danila Fedorin 2021-08-31 15:12:09 -07:00
parent f5943ced97
commit bef02d238f
2 changed files with 19 additions and 15 deletions

View file

@ -24,13 +24,14 @@ function encodeKey(roomId: string, sessionId: string, messageIndex: number | str
interface GroupSessionDecryption {
eventId: string;
timestamp: number;
key: string;
}
export class GroupSessionDecryptionStore {
private _store: Store<GroupSessionDecryption>;
type GroupSessionEntry = GroupSessionDecryption & { key: string }
constructor(store: Store<GroupSessionDecryption>) {
export class GroupSessionDecryptionStore {
private _store: Store<GroupSessionEntry>;
constructor(store: Store<GroupSessionEntry>) {
this._store = store;
}
@ -39,8 +40,8 @@ export class GroupSessionDecryptionStore {
}
set(roomId: string, sessionId: string, messageIndex: number, decryption: GroupSessionDecryption): void {
decryption.key = encodeKey(roomId, sessionId, messageIndex);
this._store.put(decryption);
(decryption as GroupSessionEntry).key = encodeKey(roomId, sessionId, messageIndex);
this._store.put(decryption as GroupSessionEntry);
}
removeAllForRoom(roomId: string): Promise<undefined> {

View file

@ -20,15 +20,18 @@ export function encodeScopeTypeKey(scope: string, type: string): string {
return `${scope}|${type}`;
}
interface Operation {
interface BaseOperation {
id: string;
type: string;
scope: string;
userIds: string[];
scopeTypeKey: string;
roomKeyMessage: RoomKeyMessage;
}
type OperationType = { type: "share_room_key"; roomKeyMessage: RoomKeyMessage; }
type Operation = BaseOperation & OperationType
type OperationEntry = Operation & { scopeTypeKey: string; }
interface RoomKeyMessage {
room_id: string;
session_id: string;
@ -38,9 +41,9 @@ interface RoomKeyMessage {
}
export class OperationStore {
private _store: Store<Operation>;
private _store: Store<OperationEntry>;
constructor(store: Store<Operation>) {
constructor(store: Store<OperationEntry>) {
this._store = store;
}
@ -62,12 +65,12 @@ export class OperationStore {
}
add(operation: Operation): void {
operation.scopeTypeKey = encodeScopeTypeKey(operation.scope, operation.type);
this._store.add(operation);
(operation as OperationEntry).scopeTypeKey = encodeScopeTypeKey(operation.scope, operation.type);
this._store.add(operation as OperationEntry);
}
update(operation: Operation): void {
this._store.put(operation);
this._store.put(operation as OperationEntry);
}
remove(id: string): Promise<undefined> {