Migrate GroupSessionDecryptionStore to TypeScript

This commit is contained in:
Danila Fedorin 2021-08-12 10:41:58 -07:00
parent 33d94b9497
commit 8c966627bc
2 changed files with 17 additions and 8 deletions

View file

@ -31,7 +31,7 @@ import {DeviceIdentityStore} from "./stores/DeviceIdentityStore.js";
import {OlmSessionStore} from "./stores/OlmSessionStore.js"; import {OlmSessionStore} from "./stores/OlmSessionStore.js";
import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js"; import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js";
import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore";
import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js"; import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore";
import {OperationStore} from "./stores/OperationStore.js"; import {OperationStore} from "./stores/OperationStore.js";
import {AccountDataStore} from "./stores/AccountDataStore.js"; import {AccountDataStore} from "./stores/AccountDataStore.js";

View file

@ -15,30 +15,39 @@ limitations under the License.
*/ */
import {MIN_UNICODE, MAX_UNICODE} from "./common"; import {MIN_UNICODE, MAX_UNICODE} from "./common";
import {Store} from "../Store";
function encodeKey(roomId, sessionId, messageIndex) { function encodeKey(roomId: string, sessionId: string, messageIndex: number | string): string {
return `${roomId}|${sessionId}|${messageIndex}`; return `${roomId}|${sessionId}|${messageIndex}`;
} }
interface GroupSessionDecryption {
eventId: string;
timestamp: number;
key: string;
}
export class GroupSessionDecryptionStore { export class GroupSessionDecryptionStore {
constructor(store) { private _store: Store<GroupSessionDecryption>;
constructor(store: Store<GroupSessionDecryption>) {
this._store = store; this._store = store;
} }
get(roomId, sessionId, messageIndex) { get(roomId: string, sessionId: string, messageIndex: number): Promise<GroupSessionDecryption | null> {
return this._store.get(encodeKey(roomId, sessionId, messageIndex)); return this._store.get(encodeKey(roomId, sessionId, messageIndex));
} }
set(roomId, sessionId, messageIndex, decryption) { set(roomId: string, sessionId: string, messageIndex: number, decryption: GroupSessionDecryption): Promise<IDBValidKey> {
decryption.key = encodeKey(roomId, sessionId, messageIndex); decryption.key = encodeKey(roomId, sessionId, messageIndex);
this._store.put(decryption); return this._store.put(decryption);
} }
removeAllForRoom(roomId) { removeAllForRoom(roomId: string): Promise<undefined> {
const range = this._store.IDBKeyRange.bound( const range = this._store.IDBKeyRange.bound(
encodeKey(roomId, MIN_UNICODE, MIN_UNICODE), encodeKey(roomId, MIN_UNICODE, MIN_UNICODE),
encodeKey(roomId, MAX_UNICODE, MAX_UNICODE) encodeKey(roomId, MAX_UNICODE, MAX_UNICODE)
); );
this._store.delete(range); return this._store.delete(range);
} }
} }