From f8613e9e9664866bedee9fe6b0eb7b8cebf6c112 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 10 Aug 2021 16:28:47 -0700 Subject: [PATCH] Add initial translation of RoomSummaryStore.js --- src/matrix/storage/idb/QueryTarget.ts | 2 +- src/matrix/storage/idb/Transaction.js | 2 +- ...oomSummaryStore.js => RoomSummaryStore.ts} | 38 ++++++++++--------- 3 files changed, 23 insertions(+), 19 deletions(-) rename src/matrix/storage/idb/stores/{RoomSummaryStore.js => RoomSummaryStore.ts} (61%) diff --git a/src/matrix/storage/idb/QueryTarget.ts b/src/matrix/storage/idb/QueryTarget.ts index b2df0f9f..5d2d5bb4 100644 --- a/src/matrix/storage/idb/QueryTarget.ts +++ b/src/matrix/storage/idb/QueryTarget.ts @@ -94,7 +94,7 @@ export class QueryTarget { return this._selectWhile(range, predicate, "prev"); } - async selectAll(range: IDBKeyRange, direction: IDBCursorDirection): Promise { + async selectAll(range?: IDBKeyRange, direction?: IDBCursorDirection): Promise { const cursor = this._openCursor(range, direction); const results: T[] = []; await iterateCursor(cursor, (value) => { diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index d4949b02..c92999b8 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -18,7 +18,7 @@ import {txnAsPromise} from "./utils"; import {StorageError} from "../common"; import {Store} from "./Store"; import {SessionStore} from "./stores/SessionStore"; -import {RoomSummaryStore} from "./stores/RoomSummaryStore.js"; +import {RoomSummaryStore} from "./stores/RoomSummaryStore"; import {InviteStore} from "./stores/InviteStore.js"; import {TimelineEventStore} from "./stores/TimelineEventStore.js"; import {TimelineRelationStore} from "./stores/TimelineRelationStore.js"; diff --git a/src/matrix/storage/idb/stores/RoomSummaryStore.js b/src/matrix/storage/idb/stores/RoomSummaryStore.ts similarity index 61% rename from src/matrix/storage/idb/stores/RoomSummaryStore.js rename to src/matrix/storage/idb/stores/RoomSummaryStore.ts index 426a01bb..bacefa5c 100644 --- a/src/matrix/storage/idb/stores/RoomSummaryStore.js +++ b/src/matrix/storage/idb/stores/RoomSummaryStore.ts @@ -27,31 +27,35 @@ store contains: inviteCount joinCount */ +import {Store} from "../Store" +import {SummaryData} from "../../../room/RoomSummary" /** Used for both roomSummary and archivedRoomSummary stores */ export class RoomSummaryStore { - constructor(summaryStore) { - this._summaryStore = summaryStore; - } + private _summaryStore: Store - getAll() { - return this._summaryStore.selectAll(); - } + constructor(summaryStore: Store) { + this._summaryStore = summaryStore; + } - set(summary) { - return this._summaryStore.put(summary); - } + getAll() { + return this._summaryStore.selectAll(); + } - get(roomId) { - return this._summaryStore.get(roomId); - } + set(summary: SummaryData) { + return this._summaryStore.put(summary); + } - async has(roomId) { + get(roomId: string) { + return this._summaryStore.get(roomId); + } + + async has(roomId: string) { const fetchedKey = await this._summaryStore.getKey(roomId); return roomId === fetchedKey; - } + } - remove(roomId) { - return this._summaryStore.delete(roomId); - } + remove(roomId: string) { + return this._summaryStore.delete(roomId); + } }