@@ -23,7 +23,7 @@ import { InvalidStoreError } from "matrix-js-sdk/src/errors";
2323import { IEncryptedPayload } from "matrix-js-sdk/src/crypto/aes" ;
2424import { QueryDict } from "matrix-js-sdk/src/utils" ;
2525import { 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
2828import { IMatrixClientCreds , MatrixClientPeg } from "./MatrixClientPeg" ;
2929import 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
646646async 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
672677async function handleLoadSessionFailure ( e : unknown ) : Promise < boolean > {
0 commit comments