Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Remove unused sessionStorage layer (#8834)
Browse files Browse the repository at this point in the history
* Remove unused sessionStorage layer

* Update global.d.ts

* Fix tests
  • Loading branch information
t3chguy authored Jun 14, 2022
1 parent 7da8c51 commit d81e2ce
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 78 deletions.
2 changes: 0 additions & 2 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -49,7 +48,6 @@ declare global {
MatrixScheduler: typeof MatrixScheduler;
MemoryStore: typeof MemoryStore;
MemoryCryptoStore: typeof MemoryCryptoStore;
WebStorageSessionStore: typeof WebStorageSessionStore;
Visibility: typeof Visibility;
Preset: typeof Preset;
};
Expand Down
2 changes: 0 additions & 2 deletions cypress/support/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down
58 changes: 0 additions & 58 deletions cypress/support/storage.ts

This file was deleted.

24 changes: 16 additions & 8 deletions src/utils/createMatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
};
Expand All @@ -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({
Expand Down
13 changes: 5 additions & 8 deletions test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([]),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d81e2ce

Please sign in to comment.