[Backport staging] Broaden support for matrix spec versions (#12159)

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
pull/28788/head^2
ElementRobot 2024-01-19 11:54:56 +01:00 committed by GitHub
parent 43b607f715
commit 19867d85f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 29 deletions

View File

@ -23,7 +23,7 @@ import { InvalidStoreError } from "matrix-js-sdk/src/errors";
import { IEncryptedPayload } from "matrix-js-sdk/src/crypto/aes"; import { IEncryptedPayload } from "matrix-js-sdk/src/crypto/aes";
import { QueryDict } from "matrix-js-sdk/src/utils"; import { QueryDict } from "matrix-js-sdk/src/utils";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { MINIMUM_MATRIX_VERSION } from "matrix-js-sdk/src/version-support"; import { MINIMUM_MATRIX_VERSION, SUPPORTED_MATRIX_VERSIONS } from "matrix-js-sdk/src/version-support";
import { IMatrixClientCreds, MatrixClientPeg } from "./MatrixClientPeg"; import { IMatrixClientCreds, MatrixClientPeg } from "./MatrixClientPeg";
import SecurityCustomisations from "./customisations/Security"; import SecurityCustomisations from "./customisations/Security";
@ -635,7 +635,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
}, },
false, false,
); );
checkServerVersions(); await checkServerVersions();
return true; return true;
} else { } else {
logger.log("No previous session found."); logger.log("No previous session found.");
@ -644,29 +644,34 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
} }
async function checkServerVersions(): Promise<void> { async function checkServerVersions(): Promise<void> {
MatrixClientPeg.get() const client = MatrixClientPeg.get();
?.getVersions() if (!client) return;
.then((response) => { for (const version of SUPPORTED_MATRIX_VERSIONS) {
if (!response.versions.includes(MINIMUM_MATRIX_VERSION)) { // Check if the server supports this spec version. (`isVersionSupported` caches the response, so this loop will
const toastKey = "LEGACY_SERVER"; // only make a single HTTP request).
ToastStore.sharedInstance().addOrReplaceToast({ if (await client.isVersionSupported(version)) {
key: toastKey, // we found a compatible spec version
title: _t("unsupported_server_title"), return;
props: { }
description: _t("unsupported_server_description", { }
version: MINIMUM_MATRIX_VERSION,
brand: SdkConfig.get().brand, const toastKey = "LEGACY_SERVER";
}), ToastStore.sharedInstance().addOrReplaceToast({
acceptLabel: _t("action|ok"), key: toastKey,
onAccept: () => { title: _t("unsupported_server_title"),
ToastStore.sharedInstance().dismissToast(toastKey); props: {
}, description: _t("unsupported_server_description", {
}, version: MINIMUM_MATRIX_VERSION,
component: GenericToast, brand: SdkConfig.get().brand,
priority: 98, }),
}); acceptLabel: _t("action|ok"),
} onAccept: () => {
}); ToastStore.sharedInstance().dismissToast(toastKey);
},
},
component: GenericToast,
priority: 98,
});
} }
async function handleLoadSessionFailure(e: unknown): Promise<boolean> { async function handleLoadSessionFailure(e: unknown): Promise<boolean> {

View File

@ -453,10 +453,7 @@ describe("Lifecycle", () => {
it("should show a toast if the matrix server version is unsupported", async () => { it("should show a toast if the matrix server version is unsupported", async () => {
const toastSpy = jest.spyOn(ToastStore.sharedInstance(), "addOrReplaceToast"); const toastSpy = jest.spyOn(ToastStore.sharedInstance(), "addOrReplaceToast");
mockClient.getVersions.mockResolvedValue({ mockClient.isVersionSupported.mockImplementation(async (version) => version == "r0.6.0");
versions: ["r0.6.0"],
unstable_features: {},
});
initLocalStorageMock({ ...localStorageSession }); initLocalStorageMock({ ...localStorageSession });
expect(await restoreFromLocalStorage()).toEqual(true); expect(await restoreFromLocalStorage()).toEqual(true);