diff --git a/src/matrix/storage/common.js b/src/matrix/storage/common.js index 3e9aca4f..438cf6b3 100644 --- a/src/matrix/storage/common.js +++ b/src/matrix/storage/common.js @@ -18,6 +18,7 @@ export const STORE_NAMES = Object.freeze([ "session", "roomState", "roomSummary", + "invites", "roomMembers", "timelineEvents", "timelineFragments", diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index 8d5ba232..162f821f 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -19,6 +19,7 @@ import {StorageError} from "../common.js"; import {Store} from "./Store.js"; import {SessionStore} from "./stores/SessionStore.js"; import {RoomSummaryStore} from "./stores/RoomSummaryStore.js"; +import {InviteStore} from "./stores/InviteStore.js"; import {TimelineEventStore} from "./stores/TimelineEventStore.js"; import {RoomStateStore} from "./stores/RoomStateStore.js"; import {RoomMemberStore} from "./stores/RoomMemberStore.js"; @@ -64,6 +65,10 @@ export class Transaction { return this._store("roomSummary", idbStore => new RoomSummaryStore(idbStore)); } + get invites() { + return this._store("invites", idbStore => new InviteStore(idbStore)); + } + get timelineFragments() { return this._store("timelineFragments", idbStore => new TimelineFragmentStore(idbStore)); } diff --git a/src/matrix/storage/idb/schema.js b/src/matrix/storage/idb/schema.js index 4d0d45ac..7cf100aa 100644 --- a/src/matrix/storage/idb/schema.js +++ b/src/matrix/storage/idb/schema.js @@ -11,7 +11,8 @@ export const schema = [ migrateSession, createE2EEStores, migrateEncryptionFlag, - createAccountDataStore + createAccountDataStore, + createInviteStore ]; // TODO: how to deal with git merge conflicts of this array? @@ -103,3 +104,8 @@ async function migrateEncryptionFlag(db, txn) { function createAccountDataStore(db) { db.createObjectStore("accountData", {keyPath: "type"}); } + +// v7 +function createInviteStore(db) { + db.createObjectStore("invites", {keyPath: "roomId"}); +} diff --git a/src/matrix/storage/idb/stores/InviteStore.js b/src/matrix/storage/idb/stores/InviteStore.js new file mode 100644 index 00000000..a3c7517a --- /dev/null +++ b/src/matrix/storage/idb/stores/InviteStore.js @@ -0,0 +1,33 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export class InviteStore { + constructor(inviteStore) { + this._inviteStore = inviteStore; + } + + getAll() { + return this._inviteStore.selectAll(); + } + + set(invite) { + return this._inviteStore.put(invite); + } + + remove(roomId) { + this._store.delete(roomId); + } +}