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

Commit 19867d8

Browse files
RiotRobotrichvdh
andauthored
[Backport staging] Broaden support for matrix spec versions (#12159)
Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 43b607f commit 19867d8

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

src/Lifecycle.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { InvalidStoreError } from "matrix-js-sdk/src/errors";
2323
import { IEncryptedPayload } from "matrix-js-sdk/src/crypto/aes";
2424
import { QueryDict } from "matrix-js-sdk/src/utils";
2525
import { logger } from "matrix-js-sdk/src/logger";
26-
import { MINIMUM_MATRIX_VERSION } from "matrix-js-sdk/src/version-support";
26+
import { MINIMUM_MATRIX_VERSION, SUPPORTED_MATRIX_VERSIONS } from "matrix-js-sdk/src/version-support";
2727

2828
import { IMatrixClientCreds, MatrixClientPeg } from "./MatrixClientPeg";
2929
import SecurityCustomisations from "./customisations/Security";
@@ -635,7 +635,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
635635
},
636636
false,
637637
);
638-
checkServerVersions();
638+
await checkServerVersions();
639639
return true;
640640
} else {
641641
logger.log("No previous session found.");
@@ -644,29 +644,34 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
644644
}
645645

646646
async function checkServerVersions(): Promise<void> {
647-
MatrixClientPeg.get()
648-
?.getVersions()
649-
.then((response) => {
650-
if (!response.versions.includes(MINIMUM_MATRIX_VERSION)) {
651-
const toastKey = "LEGACY_SERVER";
652-
ToastStore.sharedInstance().addOrReplaceToast({
653-
key: toastKey,
654-
title: _t("unsupported_server_title"),
655-
props: {
656-
description: _t("unsupported_server_description", {
657-
version: MINIMUM_MATRIX_VERSION,
658-
brand: SdkConfig.get().brand,
659-
}),
660-
acceptLabel: _t("action|ok"),
661-
onAccept: () => {
662-
ToastStore.sharedInstance().dismissToast(toastKey);
663-
},
664-
},
665-
component: GenericToast,
666-
priority: 98,
667-
});
668-
}
669-
});
647+
const client = MatrixClientPeg.get();
648+
if (!client) return;
649+
for (const version of SUPPORTED_MATRIX_VERSIONS) {
650+
// Check if the server supports this spec version. (`isVersionSupported` caches the response, so this loop will
651+
// only make a single HTTP request).
652+
if (await client.isVersionSupported(version)) {
653+
// we found a compatible spec version
654+
return;
655+
}
656+
}
657+
658+
const toastKey = "LEGACY_SERVER";
659+
ToastStore.sharedInstance().addOrReplaceToast({
660+
key: toastKey,
661+
title: _t("unsupported_server_title"),
662+
props: {
663+
description: _t("unsupported_server_description", {
664+
version: MINIMUM_MATRIX_VERSION,
665+
brand: SdkConfig.get().brand,
666+
}),
667+
acceptLabel: _t("action|ok"),
668+
onAccept: () => {
669+
ToastStore.sharedInstance().dismissToast(toastKey);
670+
},
671+
},
672+
component: GenericToast,
673+
priority: 98,
674+
});
670675
}
671676

672677
async function handleLoadSessionFailure(e: unknown): Promise<boolean> {

test/Lifecycle-test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,7 @@ describe("Lifecycle", () => {
453453

454454
it("should show a toast if the matrix server version is unsupported", async () => {
455455
const toastSpy = jest.spyOn(ToastStore.sharedInstance(), "addOrReplaceToast");
456-
mockClient.getVersions.mockResolvedValue({
457-
versions: ["r0.6.0"],
458-
unstable_features: {},
459-
});
456+
mockClient.isVersionSupported.mockImplementation(async (version) => version == "r0.6.0");
460457
initLocalStorageMock({ ...localStorageSession });
461458

462459
expect(await restoreFromLocalStorage()).toEqual(true);

0 commit comments

Comments
 (0)