mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Migrate RoomStateStore.js to TypeScript
This commit is contained in:
parent
af70269169
commit
5d4454734a
@ -22,7 +22,7 @@ import {RoomSummaryStore} from "./stores/RoomSummaryStore";
|
|||||||
import {InviteStore} from "./stores/InviteStore";
|
import {InviteStore} from "./stores/InviteStore";
|
||||||
import {TimelineEventStore} from "./stores/TimelineEventStore";
|
import {TimelineEventStore} from "./stores/TimelineEventStore";
|
||||||
import {TimelineRelationStore} from "./stores/TimelineRelationStore";
|
import {TimelineRelationStore} from "./stores/TimelineRelationStore";
|
||||||
import {RoomStateStore} from "./stores/RoomStateStore.js";
|
import {RoomStateStore} from "./stores/RoomStateStore";
|
||||||
import {RoomMemberStore} from "./stores/RoomMemberStore";
|
import {RoomMemberStore} from "./stores/RoomMemberStore";
|
||||||
import {TimelineFragmentStore} from "./stores/TimelineFragmentStore.js";
|
import {TimelineFragmentStore} from "./stores/TimelineFragmentStore.js";
|
||||||
import {PendingEventStore} from "./stores/PendingEventStore.js";
|
import {PendingEventStore} from "./stores/PendingEventStore.js";
|
||||||
|
@ -16,31 +16,41 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {MAX_UNICODE} from "./common";
|
import {MAX_UNICODE} from "./common";
|
||||||
|
import {Store} from "../Store";
|
||||||
|
import {StateEvent} from "../../types";
|
||||||
|
|
||||||
function encodeKey(roomId, eventType, stateKey) {
|
function encodeKey(roomId: string, eventType: string, stateKey: string) {
|
||||||
return `${roomId}|${eventType}|${stateKey}`;
|
return `${roomId}|${eventType}|${stateKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RoomStateEntry {
|
||||||
|
roomId: string;
|
||||||
|
event: StateEvent;
|
||||||
|
key: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class RoomStateStore {
|
export class RoomStateStore {
|
||||||
constructor(idbStore) {
|
private _roomStateStore: Store<RoomStateEntry>;
|
||||||
|
|
||||||
|
constructor(idbStore: Store<RoomStateEntry>) {
|
||||||
this._roomStateStore = idbStore;
|
this._roomStateStore = idbStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
get(roomId, type, stateKey) {
|
get(roomId: string, type: string, stateKey: string): Promise<RoomStateEntry | null> {
|
||||||
const key = encodeKey(roomId, type, stateKey);
|
const key = encodeKey(roomId, type, stateKey);
|
||||||
return this._roomStateStore.get(key);
|
return this._roomStateStore.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
set(roomId, event) {
|
set(roomId: string, event: StateEvent): Promise<IDBValidKey> {
|
||||||
const key = encodeKey(roomId, event.type, event.state_key);
|
const key = encodeKey(roomId, event.type, event.state_key);
|
||||||
const entry = {roomId, event, key};
|
const entry = {roomId, event, key};
|
||||||
return this._roomStateStore.put(entry);
|
return this._roomStateStore.put(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAllForRoom(roomId) {
|
removeAllForRoom(roomId: string): Promise<undefined> {
|
||||||
// exclude both keys as they are theoretical min and max,
|
// exclude both keys as they are theoretical min and max,
|
||||||
// but we should't have a match for just the room id, or room id with max
|
// but we should't have a match for just the room id, or room id with max
|
||||||
const range = this._roomStateStore.IDBKeyRange.bound(roomId, `${roomId}|${MAX_UNICODE}`, true, true);
|
const range = this._roomStateStore.IDBKeyRange.bound(roomId, `${roomId}|${MAX_UNICODE}`, true, true);
|
||||||
this._roomStateStore.delete(range);
|
return this._roomStateStore.delete(range);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user