@@ -116,22 +116,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
116
116
this . setupThread ( this . props . mxEvent ) ;
117
117
this . dispatcherRef = dis . register ( this . onAction ) ;
118
118
119
- const room = MatrixClientPeg . get ( ) . getRoom ( this . props . mxEvent . getRoomId ( ) ) ;
120
-
121
- if ( ! room ) {
122
- throw new Error (
123
- `Unable to find room ${ this . props . mxEvent . getRoomId ( ) } for thread ${ this . props . mxEvent . getId ( ) } ` ,
124
- ) ;
125
- }
126
-
127
- room . on ( ThreadEvent . New , this . onNewThread ) ;
119
+ this . props . room . on ( ThreadEvent . New , this . onNewThread ) ;
128
120
}
129
121
130
122
public componentWillUnmount ( ) : void {
131
123
if ( this . dispatcherRef ) dis . unregister ( this . dispatcherRef ) ;
132
124
const roomId = this . props . mxEvent . getRoomId ( ) ;
133
- const room = MatrixClientPeg . get ( ) . getRoom ( roomId ) ;
134
- room ?. removeListener ( ThreadEvent . New , this . onNewThread ) ;
135
125
SettingsStore . unwatchSetting ( this . layoutWatcherRef ) ;
136
126
137
127
const hasRoomChanged = SdkContextClass . instance . roomViewStore . getRoomId ( ) !== roomId ;
@@ -147,6 +137,10 @@ export default class ThreadView extends React.Component<IProps, IState> {
147
137
action : Action . ViewThread ,
148
138
thread_id : null ,
149
139
} ) ;
140
+
141
+ this . state . thread ?. off ( ThreadEvent . NewReply , this . updateThreadRelation ) ;
142
+ this . props . room . off ( RoomEvent . LocalEchoUpdated , this . updateThreadRelation ) ;
143
+ this . props . room . removeListener ( ThreadEvent . New , this . onNewThread ) ;
150
144
}
151
145
152
146
public componentDidUpdate ( prevProps : IProps ) : void {
0 commit comments