Remove unused sessionStorage layer (#8834)

* Remove unused sessionStorage layer

* Update global.d.ts

* Fix tests
pull/28217/head
Michael Telatynski 2022-06-14 21:29:24 +01:00 committed by GitHub
parent 7da8c51c6b
commit d81e2cea14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 78 deletions

2
cypress/global.d.ts vendored
View File

@ -26,7 +26,6 @@ import type {
Visibility,
RoomMemberEvent,
} from "matrix-js-sdk/src/matrix";
import type { WebStorageSessionStore } from "matrix-js-sdk/src/store/session/webstorage";
import type { MatrixDispatcher } from "../src/dispatcher/dispatcher";
import type PerformanceMonitor from "../src/performance";
@ -49,7 +48,6 @@ declare global {
MatrixScheduler: typeof MatrixScheduler;
MemoryStore: typeof MemoryStore;
MemoryCryptoStore: typeof MemoryCryptoStore;
WebStorageSessionStore: typeof WebStorageSessionStore;
Visibility: typeof Visibility;
Preset: typeof Preset;
};

View File

@ -20,7 +20,6 @@ import request from "browser-request";
import type { MatrixClient } from "matrix-js-sdk/src/client";
import { SynapseInstance } from "../plugins/synapsedocker";
import { MockStorage } from "./storage";
import Chainable = Cypress.Chainable;
declare global {
@ -51,7 +50,6 @@ Cypress.Commands.add("getBot", (synapse: SynapseInstance, displayName?: string):
store: new win.matrixcs.MemoryStore(),
scheduler: new win.matrixcs.MatrixScheduler(),
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
sessionStore: new win.matrixcs.WebStorageSessionStore(new MockStorage()),
});
cli.on(win.matrixcs.RoomMemberEvent.Membership, (event, member) => {

View File

@ -1,58 +0,0 @@
/*
Copyright 2022 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 MockStorage implements Storage {
private data: Record<string, string> = {};
private keys: string[] = [];
public length = 0;
constructor() {}
public setItem(k: string, v: string) {
this.data[k] = v;
this.recalc();
}
public getItem(k: string): string | null {
return this.data[k] || null;
}
public removeItem(k: string) {
delete this.data[k];
this.recalc();
}
public clear() {
this.data = {};
this.recalc();
}
public key(index: number): string {
return this.keys[index];
}
private recalc() {
const keys = [];
for (const k in this.data) {
if (!this.data.hasOwnProperty(k)) {
continue;
}
keys.push(k);
}
this.keys = keys;
this.length = keys.length;
}
}

View File

@ -13,10 +13,16 @@ 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.
*/
import { createClient, ICreateClientOpts } from "matrix-js-sdk/src/matrix";
import {
MatrixClient,
createClient,
ICreateClientOpts,
MemoryCryptoStore,
MemoryStore,
} from "matrix-js-sdk/src/matrix";
import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
import { WebStorageSessionStore } from "matrix-js-sdk/src/store/session/webstorage";
import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb";
import { LocalStorageCryptoStore } from "matrix-js-sdk/src/crypto/store/localStorage-crypto-store";
// @ts-ignore - `.ts` is needed here to make TS happy
import IndexedDBWorker from "../workers/indexeddb.worker.ts";
@ -39,7 +45,7 @@ try {
*
* @returns {MatrixClient} the newly-created MatrixClient
*/
export default function createMatrixClient(opts: ICreateClientOpts) {
export default function createMatrixClient(opts: ICreateClientOpts): MatrixClient {
const storeOpts: Partial<ICreateClientOpts> = {
useAuthorizationHeader: true,
};
@ -48,19 +54,21 @@ export default function createMatrixClient(opts: ICreateClientOpts) {
storeOpts.store = new IndexedDBStore({
indexedDB: indexedDB,
dbName: "riot-web-sync",
localStorage: localStorage,
localStorage,
workerFactory: () => new IndexedDBWorker(),
});
}
if (localStorage) {
storeOpts.sessionStore = new WebStorageSessionStore(localStorage);
} else if (localStorage) {
storeOpts.store = new MemoryStore({ localStorage });
}
if (indexedDB) {
storeOpts.cryptoStore = new IndexedDBCryptoStore(
indexedDB, "matrix-js-sdk:crypto",
);
} else if (localStorage) {
storeOpts.cryptoStore = new LocalStorageCryptoStore(localStorage);
} else {
storeOpts.cryptoStore = new MemoryCryptoStore();
}
return createClient({

View File

@ -82,6 +82,11 @@ export function createTestClient(): MatrixClient {
getDevices: jest.fn().mockResolvedValue({ devices: [{ device_id: "ABCDEFGHI" }] }),
credentials: { userId: "@userId:matrix.rog" },
store: {
getPendingEvents: jest.fn().mockResolvedValue([]),
setPendingEvents: jest.fn().mockResolvedValue(undefined),
},
getPushActionsForEvent: jest.fn(),
getRoom: jest.fn().mockImplementation(mkStubRoom),
getRooms: jest.fn().mockReturnValue([]),
@ -129,14 +134,6 @@ export function createTestClient(): MatrixClient {
}),
createRoom: jest.fn().mockResolvedValue({ room_id: "!1:example.org" }),
setPowerLevel: jest.fn().mockResolvedValue(undefined),
// Used by various internal bits we aren't concerned with (yet)
sessionStore: {
store: {
getItem: jest.fn(),
setItem: jest.fn(),
},
},
pushRules: {},
decryptEventIfNeeded: () => Promise.resolve(),
isUserIgnored: jest.fn().mockReturnValue(false),