@@ -26,7 +26,7 @@ import { type MatrixDispatcher } from "../dispatcher/dispatcher";
2626import { MatrixClientPeg } from "../MatrixClientPeg" ;
2727import Modal from "../Modal" ;
2828import { _t } from "../languageHandler" ;
29- import { getCachedRoomIDForAlias , storeRoomAliasInCache } from "../RoomAliasCache" ;
29+ import { getCachedRoomIdForAlias , storeRoomAliasInCache } from "../RoomAliasCache" ;
3030import { Action } from "../dispatcher/actions" ;
3131import { retry } from "../utils/promise" ;
3232import { TimelineRenderingType } from "../contexts/RoomContext" ;
@@ -438,17 +438,24 @@ export class RoomViewStore extends EventEmitter {
438438 action : Action . JoinRoom ,
439439 roomId : payload . room_id ,
440440 metricsTrigger : payload . metricsTrigger as JoinRoomPayload [ "metricsTrigger" ] ,
441+ canAskToJoin : SettingsStore . getValue ( "feature_ask_to_join" ) ,
441442 } ) ;
442443 }
443444
444445 if ( room ) {
445446 await setMarkedUnreadState ( room , MatrixClientPeg . safeGet ( ) , false ) ;
446447 }
447448 } else if ( payload . room_alias ) {
449+ let roomId : string ;
450+ let viaServers : string [ ] | undefined ;
451+
448452 // Try the room alias to room ID navigation cache first to avoid
449453 // blocking room navigation on the homeserver.
450- let roomId = getCachedRoomIDForAlias ( payload . room_alias ) ;
451- if ( ! roomId ) {
454+ const cachedResult = getCachedRoomIdForAlias ( payload . room_alias ) ;
455+ if ( cachedResult ) {
456+ roomId = cachedResult . roomId ;
457+ viaServers = cachedResult . viaServers ;
458+ } else {
452459 // Room alias cache miss, so let's ask the homeserver. Resolve the alias
453460 // and then do a second dispatch with the room ID acquired.
454461 this . setState ( {
@@ -467,8 +474,9 @@ export class RoomViewStore extends EventEmitter {
467474 } ) ;
468475 try {
469476 const result = await MatrixClientPeg . safeGet ( ) . getRoomIdForAlias ( payload . room_alias ) ;
470- storeRoomAliasInCache ( payload . room_alias , result . room_id ) ;
477+ storeRoomAliasInCache ( payload . room_alias , result . room_id , result . servers ) ;
471478 roomId = result . room_id ;
479+ viaServers = result . servers ;
472480 } catch ( err ) {
473481 logger . error ( "RVS failed to get room id for alias: " , err ) ;
474482 this . dis ?. dispatch < ViewRoomErrorPayload > ( {
@@ -485,6 +493,7 @@ export class RoomViewStore extends EventEmitter {
485493 this . dis ?. dispatch ( {
486494 ...payload ,
487495 room_id : roomId ,
496+ via_servers : viaServers ,
488497 } ) ;
489498 }
490499 }
@@ -509,12 +518,13 @@ export class RoomViewStore extends EventEmitter {
509518 joining : true ,
510519 } ) ;
511520
512- // take a copy of roomAlias & roomId as they may change by the time the join is complete
513- const { roomAlias, roomId } = this . state ;
514- const address = payload . roomId || roomAlias || roomId ! ;
521+ // take a copy of roomAlias, roomId & viaServers as they may change by the time the join is complete
522+ const { roomAlias, roomId = payload . roomId , viaServers = [ ] } = this . state ;
523+ // prefer the room alias if we have one as it allows joining over federation even with no viaServers
524+ const address = roomAlias || roomId ! ;
515525
516526 const joinOpts : IJoinRoomOpts = {
517- viaServers : this . state . viaServers || [ ] ,
527+ viaServers,
518528 ...( payload . opts ?? { } ) ,
519529 } ;
520530 if ( SettingsStore . getValue ( "feature_share_history_on_invite" ) ) {
@@ -547,7 +557,7 @@ export class RoomViewStore extends EventEmitter {
547557 canAskToJoin : payload . canAskToJoin ,
548558 } ) ;
549559
550- if ( payload . canAskToJoin ) {
560+ if ( payload . canAskToJoin && err instanceof MatrixError && err . httpStatus === 403 ) {
551561 this . dis ?. dispatch ( { action : Action . PromptAskToJoin } ) ;
552562 }
553563 }
0 commit comments