@@ -44,6 +44,7 @@ import { type CallState, type MatrixCall } from "matrix-js-sdk/src/webrtc/call";
4444import { debounce , throttle } from "lodash" ;
4545import { CryptoEvent } from "matrix-js-sdk/src/crypto-api" ;
4646import { type ViewRoomOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle" ;
47+ import { type RoomViewProps } from "@element-hq/element-web-module-api" ;
4748
4849import shouldHideEvent from "../../shouldHideEvent" ;
4950import { _t } from "../../languageHandler" ;
@@ -148,7 +149,7 @@ if (DEBUG) {
148149 debuglog = logger . log . bind ( console ) ;
149150}
150151
151- interface IRoomProps {
152+ interface IRoomProps extends RoomViewProps {
152153 threepidInvite ?: IThreepidInvite ;
153154 oobData ?: IOOBData ;
154155
@@ -158,19 +159,17 @@ interface IRoomProps {
158159
159160 // Called with the credentials of a registered user (if they were a ROU that transitioned to PWLU)
160161 onRegistered ?( credentials : IMatrixClientCreds ) : void ;
162+
161163 /**
162- * The RoomViewStore instance for the room to be displayed.
164+ * Only necessary if RoomView should get it's RoomViewStore through the MultiRoomViewStore.
165+ * Omitting this will mean that RoomView renders for the room held in SDKContext.RoomViewStore.
163166 */
164- roomViewStore : RoomViewStore ;
167+ roomId ?: string ;
165168}
166169
167170export { MainSplitContentType } ;
168171
169172export interface IRoomState {
170- /**
171- * The RoomViewStore instance for the room we are displaying
172- */
173- roomViewStore : RoomViewStore ;
174173 room ?: Room ;
175174 roomId ?: string ;
176175 roomAlias ?: string ;
@@ -389,6 +388,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
389388 private messagePanel : TimelinePanel | null = null ;
390389 private roomViewBody = createRef < HTMLDivElement > ( ) ;
391390
391+ private roomViewStore : RoomViewStore ;
392+
392393 public static contextType = SDKContext ;
393394 declare public context : React . ContextType < typeof SDKContext > ;
394395
@@ -401,9 +402,14 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
401402 throw new Error ( "Unable to create RoomView without MatrixClient" ) ;
402403 }
403404
405+ if ( props . roomId ) {
406+ this . roomViewStore = this . context . multiRoomViewStore . getRoomViewStoreForRoom ( props . roomId ) ;
407+ } else {
408+ this . roomViewStore = context . roomViewStore ;
409+ }
410+
404411 const llMembers = context . client . hasLazyLoadMembersEnabled ( ) ;
405412 this . state = {
406- roomViewStore : props . roomViewStore ,
407413 roomId : undefined ,
408414 roomLoading : true ,
409415 peekLoading : false ,
@@ -535,7 +541,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
535541 } ;
536542
537543 private getMainSplitContentType = ( room : Room ) : MainSplitContentType => {
538- if ( this . state . roomViewStore . isViewingCall ( ) || isVideoRoom ( room ) ) {
544+ if ( this . roomViewStore . isViewingCall ( ) || isVideoRoom ( room ) ) {
539545 return MainSplitContentType . Call ;
540546 }
541547 if ( this . context . widgetLayoutStore . hasMaximisedWidget ( room ) ) {
@@ -549,8 +555,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
549555 return ;
550556 }
551557
552- const roomLoadError = this . state . roomViewStore . getRoomLoadError ( ) ?? undefined ;
553- if ( ! initial && ! roomLoadError && this . state . roomId !== this . state . roomViewStore . getRoomId ( ) ) {
558+ const roomLoadError = this . roomViewStore . getRoomLoadError ( ) ?? undefined ;
559+ if ( ! initial && ! roomLoadError && this . state . roomId !== this . roomViewStore . getRoomId ( ) ) {
554560 // RoomView explicitly does not support changing what room
555561 // is being viewed: instead it should just be re-mounted when
556562 // switching rooms. Therefore, if the room ID changes, we
@@ -564,7 +570,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
564570 // it was, it means we're about to be unmounted.
565571 return ;
566572 }
567- const roomViewStore = this . state . roomViewStore ;
573+ const roomViewStore = this . roomViewStore ;
568574 const roomId = roomViewStore . getRoomId ( ) ?? null ;
569575 const roomAlias = roomViewStore . getRoomAlias ( ) ?? undefined ;
570576 const roomLoading = roomViewStore . isRoomLoading ( ) ;
@@ -611,7 +617,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
611617 newState . showRightPanel = false ;
612618 }
613619
614- const initialEventId = this . state . roomViewStore . getInitialEventId ( ) ?? this . state . initialEventId ;
620+ const initialEventId = this . roomViewStore . getInitialEventId ( ) ?? this . state . initialEventId ;
615621 if ( initialEventId ) {
616622 let initialEvent = room ?. findEventById ( initialEventId ) ;
617623 // The event does not exist in the current sync data
@@ -637,13 +643,13 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
637643 action : Action . ShowThread ,
638644 rootEvent : thread . rootEvent ,
639645 initialEvent,
640- highlighted : this . state . roomViewStore . isInitialEventHighlighted ( ) ,
641- scroll_into_view : this . state . roomViewStore . initialEventScrollIntoView ( ) ,
646+ highlighted : this . roomViewStore . isInitialEventHighlighted ( ) ,
647+ scroll_into_view : this . roomViewStore . initialEventScrollIntoView ( ) ,
642648 } ) ;
643649 } else {
644650 newState . initialEventId = initialEventId ;
645- newState . isInitialEventHighlighted = this . state . roomViewStore . isInitialEventHighlighted ( ) ;
646- newState . initialEventScrollIntoView = this . state . roomViewStore . initialEventScrollIntoView ( ) ;
651+ newState . isInitialEventHighlighted = this . roomViewStore . isInitialEventHighlighted ( ) ;
652+ newState . initialEventScrollIntoView = this . roomViewStore . initialEventScrollIntoView ( ) ;
647653 }
648654 }
649655
@@ -903,7 +909,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
903909 this . context . client . on ( MatrixEventEvent . Decrypted , this . onEventDecrypted ) ;
904910 }
905911 // Start listening for RoomViewStore updates
906- this . state . roomViewStore . on ( UPDATE_EVENT , this . onRoomViewStoreUpdate ) ;
912+ this . roomViewStore . on ( UPDATE_EVENT , this . onRoomViewStoreUpdate ) ;
907913
908914 this . context . rightPanelStore . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
909915
@@ -1020,7 +1026,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
10201026
10211027 window . removeEventListener ( "beforeunload" , this . onPageUnload ) ;
10221028
1023- this . state . roomViewStore . off ( UPDATE_EVENT , this . onRoomViewStoreUpdate ) ;
1029+ this . roomViewStore . off ( UPDATE_EVENT , this . onRoomViewStoreUpdate ) ;
10241030
10251031 this . context . rightPanelStore . off ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
10261032 WidgetEchoStore . removeListener ( UPDATE_EVENT , this . onWidgetEchoStoreUpdate ) ;
@@ -1048,6 +1054,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
10481054 // clean up if this was a local room
10491055 this . context . client ?. store . removeRoom ( this . state . room . roomId ) ;
10501056 }
1057+
1058+ if ( this . props . roomId ) this . context . multiRoomViewStore . removeRoomViewStore ( this . props . roomId ) ;
10511059 }
10521060
10531061 private onRightPanelStoreUpdate = ( ) : void => {
@@ -2070,7 +2078,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20702078 if ( ! this . state . room || ! this . context ?. client ) return null ;
20712079 const names = this . state . room . getDefaultRoomName ( this . context . client . getSafeUserId ( ) ) ;
20722080 return (
2073- < ScopedRoomContextProvider { ...this . state } >
2081+ < ScopedRoomContextProvider { ...this . state } roomViewStore = { this . roomViewStore } >
20742082 < LocalRoomCreateLoader
20752083 localRoom = { localRoom }
20762084 names = { names }
@@ -2082,7 +2090,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20822090
20832091 private renderLocalRoomView ( localRoom : LocalRoom ) : ReactNode {
20842092 return (
2085- < ScopedRoomContextProvider { ...this . state } >
2093+ < ScopedRoomContextProvider { ...this . state } roomViewStore = { this . roomViewStore } >
20862094 < LocalRoomView
20872095 e2eStatus = { this . state . e2eStatus }
20882096 localRoom = { localRoom }
@@ -2098,7 +2106,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20982106
20992107 private renderWaitingForThirdPartyRoomView ( inviteEvent : MatrixEvent ) : ReactNode {
21002108 return (
2101- < ScopedRoomContextProvider { ...this . state } >
2109+ < ScopedRoomContextProvider { ...this . state } roomViewStore = { this . roomViewStore } >
21022110 < WaitingForThirdPartyRoomView
21032111 resizeNotifier = { this . context . resizeNotifier }
21042112 roomView = { this . roomView }
@@ -2640,7 +2648,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
26402648 }
26412649
26422650 return (
2643- < ScopedRoomContextProvider { ...this . state } >
2651+ < ScopedRoomContextProvider { ...this . state } roomViewStore = { this . roomViewStore } >
26442652 < div className = { mainClasses } ref = { this . roomView } onKeyDown = { this . onReactKeyDown } >
26452653 { showChatEffects && this . roomView . current && (
26462654 < EffectsOverlay roomWidth = { this . roomView . current . offsetWidth } />
0 commit comments