@@ -9,16 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
9
9
Please see LICENSE files in the repository root for full details.
10
10
*/
11
11
12
- import React , {
13
- ChangeEvent ,
14
- ComponentProps ,
15
- createRef ,
16
- ReactElement ,
17
- ReactNode ,
18
- RefObject ,
19
- useContext ,
20
- JSX ,
21
- } from "react" ;
12
+ import React , { ChangeEvent , ComponentProps , createRef , ReactElement , ReactNode , RefObject , JSX } from "react" ;
22
13
import classNames from "classnames" ;
23
14
import {
24
15
IRecommendedVersion ,
@@ -64,7 +55,7 @@ import WidgetEchoStore from "../../stores/WidgetEchoStore";
64
55
import SettingsStore from "../../settings/SettingsStore" ;
65
56
import { Layout } from "../../settings/enums/Layout" ;
66
57
import AccessibleButton , { ButtonEvent } from "../views/elements/AccessibleButton" ;
67
- import RoomContext , { TimelineRenderingType , MainSplitContentType } from "../../contexts/RoomContext" ;
58
+ import { TimelineRenderingType , MainSplitContentType } from "../../contexts/RoomContext" ;
68
59
import { E2EStatus , shieldStatusForRoom } from "../../utils/ShieldUtils" ;
69
60
import { Action } from "../../dispatcher/actions" ;
70
61
import { IMatrixClientCreds } from "../../MatrixClientPeg" ;
@@ -136,6 +127,7 @@ import RightPanelStore from "../../stores/right-panel/RightPanelStore";
136
127
import { onView3pidInvite } from "../../stores/right-panel/action-handlers" ;
137
128
import RoomSearchAuxPanel from "../views/rooms/RoomSearchAuxPanel" ;
138
129
import { PinnedMessageBanner } from "../views/rooms/PinnedMessageBanner" ;
130
+ import { ScopedRoomContextProvider , useScopedRoomContext } from "../../contexts/ScopedRoomContext" ;
139
131
140
132
const DEBUG = false ;
141
133
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000 ;
@@ -261,6 +253,7 @@ interface LocalRoomViewProps {
261
253
permalinkCreator : RoomPermalinkCreator ;
262
254
roomView : RefObject < HTMLElement > ;
263
255
onFileDrop : ( dataTransfer : DataTransfer ) => Promise < void > ;
256
+ mainSplitContentType : MainSplitContentType ;
264
257
}
265
258
266
259
/**
@@ -270,7 +263,7 @@ interface LocalRoomViewProps {
270
263
* @returns {ReactElement }
271
264
*/
272
265
function LocalRoomView ( props : LocalRoomViewProps ) : ReactElement {
273
- const context = useContext ( RoomContext ) ;
266
+ const context = useScopedRoomContext ( "room" ) ;
274
267
const room = context . room as LocalRoom ;
275
268
const encryptionEvent = props . localRoom . currentState . getStateEvents ( EventType . RoomEncryption ) [ 0 ] ;
276
269
let encryptionTile : ReactNode ;
@@ -338,6 +331,7 @@ interface ILocalRoomCreateLoaderProps {
338
331
localRoom : LocalRoom ;
339
332
names : string ;
340
333
resizeNotifier : ResizeNotifier ;
334
+ mainSplitContentType : MainSplitContentType ;
341
335
}
342
336
343
337
/**
@@ -2007,35 +2001,41 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
2007
2001
if ( ! this . state . room || ! this . context ?. client ) return null ;
2008
2002
const names = this . state . room . getDefaultRoomName ( this . context . client . getSafeUserId ( ) ) ;
2009
2003
return (
2010
- < RoomContext . Provider value = { this . state } >
2011
- < LocalRoomCreateLoader localRoom = { localRoom } names = { names } resizeNotifier = { this . props . resizeNotifier } />
2012
- </ RoomContext . Provider >
2004
+ < ScopedRoomContextProvider { ...this . state } >
2005
+ < LocalRoomCreateLoader
2006
+ localRoom = { localRoom }
2007
+ names = { names }
2008
+ resizeNotifier = { this . props . resizeNotifier }
2009
+ mainSplitContentType = { this . state . mainSplitContentType }
2010
+ />
2011
+ </ ScopedRoomContextProvider >
2013
2012
) ;
2014
2013
}
2015
2014
2016
2015
private renderLocalRoomView ( localRoom : LocalRoom ) : ReactNode {
2017
2016
return (
2018
- < RoomContext . Provider value = { this . state } >
2017
+ < ScopedRoomContextProvider { ... this . state } >
2019
2018
< LocalRoomView
2020
2019
localRoom = { localRoom }
2021
2020
resizeNotifier = { this . props . resizeNotifier }
2022
2021
permalinkCreator = { this . permalinkCreator }
2023
2022
roomView = { this . roomView }
2024
2023
onFileDrop = { this . onFileDrop }
2024
+ mainSplitContentType = { this . state . mainSplitContentType }
2025
2025
/>
2026
- </ RoomContext . Provider >
2026
+ </ ScopedRoomContextProvider >
2027
2027
) ;
2028
2028
}
2029
2029
2030
2030
private renderWaitingForThirdPartyRoomView ( inviteEvent : MatrixEvent ) : ReactNode {
2031
2031
return (
2032
- < RoomContext . Provider value = { this . state } >
2032
+ < ScopedRoomContextProvider { ... this . state } >
2033
2033
< WaitingForThirdPartyRoomView
2034
2034
resizeNotifier = { this . props . resizeNotifier }
2035
2035
roomView = { this . roomView }
2036
2036
inviteEvent = { inviteEvent }
2037
2037
/>
2038
- </ RoomContext . Provider >
2038
+ </ ScopedRoomContextProvider >
2039
2039
) ;
2040
2040
}
2041
2041
@@ -2573,7 +2573,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
2573
2573
}
2574
2574
2575
2575
return (
2576
- < RoomContext . Provider value = { this . state } >
2576
+ < ScopedRoomContextProvider { ... this . state } >
2577
2577
< div className = { mainClasses } ref = { this . roomView } onKeyDown = { this . onReactKeyDown } >
2578
2578
{ showChatEffects && this . roomView . current && (
2579
2579
< EffectsOverlay roomWidth = { this . roomView . current . offsetWidth } />
@@ -2600,7 +2600,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
2600
2600
</ MainSplit >
2601
2601
</ ErrorBoundary >
2602
2602
</ div >
2603
- </ RoomContext . Provider >
2603
+ </ ScopedRoomContextProvider >
2604
2604
) ;
2605
2605
}
2606
2606
}
0 commit comments