@@ -63,6 +63,12 @@ export default class ReplyThread extends React.Component {
6363 err : false ,
6464 } ;
6565
66+ this . unmounted = false ;
67+ this . context . on ( "Event.replaced" , this . onEventReplaced ) ;
68+ this . room = this . context . getRoom ( this . props . parentEv . getRoomId ( ) ) ;
69+ this . room . on ( "Room.redaction" , this . onRoomRedaction ) ;
70+ this . room . on ( "Room.redactionCancelled" , this . onRoomRedaction ) ;
71+
6672 this . onQuoteClick = this . onQuoteClick . bind ( this ) ;
6773 this . canCollapse = this . canCollapse . bind ( this ) ;
6874 this . collapse = this . collapse . bind ( this ) ;
@@ -217,11 +223,6 @@ export default class ReplyThread extends React.Component {
217223 }
218224
219225 componentDidMount ( ) {
220- this . unmounted = false ;
221- this . room = this . context . getRoom ( this . props . parentEv . getRoomId ( ) ) ;
222- this . room . on ( "Room.redaction" , this . onRoomRedaction ) ;
223- // same event handler as Room.redaction as for both we just do forceUpdate
224- this . room . on ( "Room.redactionCancelled" , this . onRoomRedaction ) ;
225226 this . initialize ( ) ;
226227 }
227228
@@ -231,19 +232,34 @@ export default class ReplyThread extends React.Component {
231232
232233 componentWillUnmount ( ) {
233234 this . unmounted = true ;
235+ this . context . removeListener ( "Event.replaced" , this . onEventReplaced ) ;
234236 if ( this . room ) {
235237 this . room . removeListener ( "Room.redaction" , this . onRoomRedaction ) ;
236238 this . room . removeListener ( "Room.redactionCancelled" , this . onRoomRedaction ) ;
237239 }
238240 }
239241
240- onRoomRedaction = ( ev , room ) => {
242+ updateForEventId = ( eventId ) => {
243+ if ( this . state . events . some ( event => event . getId ( ) === eventId ) ) {
244+ this . forceUpdate ( ) ;
245+ }
246+ } ;
247+
248+ onEventReplaced = ( ev ) => {
249+ if ( this . unmounted ) return ;
250+
251+ // If one of the events we are rendering gets replaced, force a re-render
252+ this . updateForEventId ( ev . getId ( ) ) ;
253+ } ;
254+
255+ onRoomRedaction = ( ev ) => {
241256 if ( this . unmounted ) return ;
242257
258+ const eventId = ev . getAssociatedId ( ) ;
259+ if ( ! eventId ) return ;
260+
243261 // If one of the events we are rendering gets redacted, force a re-render
244- if ( this . state . events . some ( event => event . getId ( ) === ev . getId ( ) ) ) {
245- this . forceUpdate ( ) ;
246- }
262+ this . updateForEventId ( eventId ) ;
247263 } ;
248264
249265 async initialize ( ) {
@@ -372,6 +388,7 @@ export default class ReplyThread extends React.Component {
372388 isTwelveHour = { SettingsStore . getValue ( "showTwelveHourTimestamps" ) }
373389 useIRCLayout = { this . props . useIRCLayout }
374390 enableFlair = { SettingsStore . getValue ( UIFeature . Flair ) }
391+ replacingEventId = { ev . replacingEventId ( ) }
375392 />
376393 </ blockquote > ;
377394 } ) ;
0 commit comments