@@ -23,7 +23,7 @@ import { InvalidStoreError } from "matrix-js-sdk/src/errors";
23
23
import { IEncryptedPayload } from "matrix-js-sdk/src/crypto/aes" ;
24
24
import { QueryDict } from "matrix-js-sdk/src/utils" ;
25
25
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" ;
27
27
28
28
import { IMatrixClientCreds , MatrixClientPeg } from "./MatrixClientPeg" ;
29
29
import SecurityCustomisations from "./customisations/Security" ;
@@ -635,7 +635,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
635
635
} ,
636
636
false ,
637
637
) ;
638
- checkServerVersions ( ) ;
638
+ await checkServerVersions ( ) ;
639
639
return true ;
640
640
} else {
641
641
logger . log ( "No previous session found." ) ;
@@ -644,29 +644,34 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
644
644
}
645
645
646
646
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
+ } ) ;
670
675
}
671
676
672
677
async function handleLoadSessionFailure ( e : unknown ) : Promise < boolean > {
0 commit comments