Remove unused sessionStorage layer (#8834)
* Remove unused sessionStorage layer * Update global.d.ts * Fix tests
This commit is contained in:
parent
7da8c51c6b
commit
d81e2cea14
5 changed files with 21 additions and 78 deletions
2
cypress/global.d.ts
vendored
2
cypress/global.d.ts
vendored
|
@ -26,7 +26,6 @@ import type {
|
||||||
Visibility,
|
Visibility,
|
||||||
RoomMemberEvent,
|
RoomMemberEvent,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} 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 { MatrixDispatcher } from "../src/dispatcher/dispatcher";
|
||||||
import type PerformanceMonitor from "../src/performance";
|
import type PerformanceMonitor from "../src/performance";
|
||||||
|
|
||||||
|
@ -49,7 +48,6 @@ declare global {
|
||||||
MatrixScheduler: typeof MatrixScheduler;
|
MatrixScheduler: typeof MatrixScheduler;
|
||||||
MemoryStore: typeof MemoryStore;
|
MemoryStore: typeof MemoryStore;
|
||||||
MemoryCryptoStore: typeof MemoryCryptoStore;
|
MemoryCryptoStore: typeof MemoryCryptoStore;
|
||||||
WebStorageSessionStore: typeof WebStorageSessionStore;
|
|
||||||
Visibility: typeof Visibility;
|
Visibility: typeof Visibility;
|
||||||
Preset: typeof Preset;
|
Preset: typeof Preset;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,6 @@ import request from "browser-request";
|
||||||
|
|
||||||
import type { MatrixClient } from "matrix-js-sdk/src/client";
|
import type { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { SynapseInstance } from "../plugins/synapsedocker";
|
import { SynapseInstance } from "../plugins/synapsedocker";
|
||||||
import { MockStorage } from "./storage";
|
|
||||||
import Chainable = Cypress.Chainable;
|
import Chainable = Cypress.Chainable;
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -51,7 +50,6 @@ Cypress.Commands.add("getBot", (synapse: SynapseInstance, displayName?: string):
|
||||||
store: new win.matrixcs.MemoryStore(),
|
store: new win.matrixcs.MemoryStore(),
|
||||||
scheduler: new win.matrixcs.MatrixScheduler(),
|
scheduler: new win.matrixcs.MatrixScheduler(),
|
||||||
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
|
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
|
||||||
sessionStore: new win.matrixcs.WebStorageSessionStore(new MockStorage()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.on(win.matrixcs.RoomMemberEvent.Membership, (event, member) => {
|
cli.on(win.matrixcs.RoomMemberEvent.Membership, (event, member) => {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
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 { 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 { 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
|
// @ts-ignore - `.ts` is needed here to make TS happy
|
||||||
import IndexedDBWorker from "../workers/indexeddb.worker.ts";
|
import IndexedDBWorker from "../workers/indexeddb.worker.ts";
|
||||||
|
@ -39,7 +45,7 @@ try {
|
||||||
*
|
*
|
||||||
* @returns {MatrixClient} the newly-created MatrixClient
|
* @returns {MatrixClient} the newly-created MatrixClient
|
||||||
*/
|
*/
|
||||||
export default function createMatrixClient(opts: ICreateClientOpts) {
|
export default function createMatrixClient(opts: ICreateClientOpts): MatrixClient {
|
||||||
const storeOpts: Partial<ICreateClientOpts> = {
|
const storeOpts: Partial<ICreateClientOpts> = {
|
||||||
useAuthorizationHeader: true,
|
useAuthorizationHeader: true,
|
||||||
};
|
};
|
||||||
|
@ -48,19 +54,21 @@ export default function createMatrixClient(opts: ICreateClientOpts) {
|
||||||
storeOpts.store = new IndexedDBStore({
|
storeOpts.store = new IndexedDBStore({
|
||||||
indexedDB: indexedDB,
|
indexedDB: indexedDB,
|
||||||
dbName: "riot-web-sync",
|
dbName: "riot-web-sync",
|
||||||
localStorage: localStorage,
|
localStorage,
|
||||||
workerFactory: () => new IndexedDBWorker(),
|
workerFactory: () => new IndexedDBWorker(),
|
||||||
});
|
});
|
||||||
}
|
} else if (localStorage) {
|
||||||
|
storeOpts.store = new MemoryStore({ localStorage });
|
||||||
if (localStorage) {
|
|
||||||
storeOpts.sessionStore = new WebStorageSessionStore(localStorage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexedDB) {
|
if (indexedDB) {
|
||||||
storeOpts.cryptoStore = new IndexedDBCryptoStore(
|
storeOpts.cryptoStore = new IndexedDBCryptoStore(
|
||||||
indexedDB, "matrix-js-sdk:crypto",
|
indexedDB, "matrix-js-sdk:crypto",
|
||||||
);
|
);
|
||||||
|
} else if (localStorage) {
|
||||||
|
storeOpts.cryptoStore = new LocalStorageCryptoStore(localStorage);
|
||||||
|
} else {
|
||||||
|
storeOpts.cryptoStore = new MemoryCryptoStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
return createClient({
|
return createClient({
|
||||||
|
|
|
@ -82,6 +82,11 @@ export function createTestClient(): MatrixClient {
|
||||||
getDevices: jest.fn().mockResolvedValue({ devices: [{ device_id: "ABCDEFGHI" }] }),
|
getDevices: jest.fn().mockResolvedValue({ devices: [{ device_id: "ABCDEFGHI" }] }),
|
||||||
credentials: { userId: "@userId:matrix.rog" },
|
credentials: { userId: "@userId:matrix.rog" },
|
||||||
|
|
||||||
|
store: {
|
||||||
|
getPendingEvents: jest.fn().mockResolvedValue([]),
|
||||||
|
setPendingEvents: jest.fn().mockResolvedValue(undefined),
|
||||||
|
},
|
||||||
|
|
||||||
getPushActionsForEvent: jest.fn(),
|
getPushActionsForEvent: jest.fn(),
|
||||||
getRoom: jest.fn().mockImplementation(mkStubRoom),
|
getRoom: jest.fn().mockImplementation(mkStubRoom),
|
||||||
getRooms: jest.fn().mockReturnValue([]),
|
getRooms: jest.fn().mockReturnValue([]),
|
||||||
|
@ -129,14 +134,6 @@ export function createTestClient(): MatrixClient {
|
||||||
}),
|
}),
|
||||||
createRoom: jest.fn().mockResolvedValue({ room_id: "!1:example.org" }),
|
createRoom: jest.fn().mockResolvedValue({ room_id: "!1:example.org" }),
|
||||||
setPowerLevel: jest.fn().mockResolvedValue(undefined),
|
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: {},
|
pushRules: {},
|
||||||
decryptEventIfNeeded: () => Promise.resolve(),
|
decryptEventIfNeeded: () => Promise.resolve(),
|
||||||
isUserIgnored: jest.fn().mockReturnValue(false),
|
isUserIgnored: jest.fn().mockReturnValue(false),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue