forked from mystiq/hydrogen-web
Migrate InboundGroupSessionStore to TypeScript
This commit is contained in:
parent
914abda7c9
commit
100aee9dcc
2 changed files with 22 additions and 9 deletions
|
@ -29,7 +29,7 @@ import {PendingEventStore} from "./stores/PendingEventStore";
|
||||||
import {UserIdentityStore} from "./stores/UserIdentityStore";
|
import {UserIdentityStore} from "./stores/UserIdentityStore";
|
||||||
import {DeviceIdentityStore} from "./stores/DeviceIdentityStore";
|
import {DeviceIdentityStore} from "./stores/DeviceIdentityStore";
|
||||||
import {OlmSessionStore} from "./stores/OlmSessionStore";
|
import {OlmSessionStore} from "./stores/OlmSessionStore";
|
||||||
import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js";
|
import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore";
|
||||||
import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore";
|
import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore";
|
||||||
import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore";
|
import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore";
|
||||||
import {OperationStore} from "./stores/OperationStore";
|
import {OperationStore} from "./stores/OperationStore";
|
||||||
|
|
|
@ -15,36 +15,49 @@ 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, senderKey, sessionId) {
|
interface InboundGroupSession {
|
||||||
|
roomId: string;
|
||||||
|
senderKey: string;
|
||||||
|
sessionId: string;
|
||||||
|
session?: string;
|
||||||
|
claimedKeys?: { [algorithm : string] : string };
|
||||||
|
eventIds?: string[];
|
||||||
|
key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodeKey(roomId: string, senderKey: string, sessionId: string): string {
|
||||||
return `${roomId}|${senderKey}|${sessionId}`;
|
return `${roomId}|${senderKey}|${sessionId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InboundGroupSessionStore {
|
export class InboundGroupSessionStore {
|
||||||
constructor(store) {
|
private _store: Store<InboundGroupSession>;
|
||||||
|
|
||||||
|
constructor(store: Store<InboundGroupSession>) {
|
||||||
this._store = store;
|
this._store = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
async has(roomId, senderKey, sessionId) {
|
async has(roomId: string, senderKey: string, sessionId: string): Promise<boolean> {
|
||||||
const key = encodeKey(roomId, senderKey, sessionId);
|
const key = encodeKey(roomId, senderKey, sessionId);
|
||||||
const fetchedKey = await this._store.getKey(key);
|
const fetchedKey = await this._store.getKey(key);
|
||||||
return key === fetchedKey;
|
return key === fetchedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
get(roomId, senderKey, sessionId) {
|
get(roomId: string, senderKey: string, sessionId: string): Promise<InboundGroupSession | null> {
|
||||||
return this._store.get(encodeKey(roomId, senderKey, sessionId));
|
return this._store.get(encodeKey(roomId, senderKey, sessionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
set(session) {
|
set(session: InboundGroupSession): Promise<IDBValidKey> {
|
||||||
session.key = encodeKey(session.roomId, session.senderKey, session.sessionId);
|
session.key = encodeKey(session.roomId, session.senderKey, session.sessionId);
|
||||||
this._store.put(session);
|
return this._store.put(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue