@@ -95,6 +95,7 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
9595 ] ) ;
9696
9797 this . room . on ( MatrixEventEvent . BeforeRedaction , this . onBeforeRedaction ) ;
98+ this . room . on ( RoomEvent . Redaction , this . onRedaction ) ;
9899 this . room . on ( RoomEvent . LocalEchoUpdated , this . onEcho ) ;
99100 this . timelineSet . on ( RoomEvent . Timeline , this . onEcho ) ;
100101
@@ -115,23 +116,24 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
115116 }
116117 }
117118
118- private onBeforeRedaction = ( event : MatrixEvent ) => {
119+ private onBeforeRedaction = ( event : MatrixEvent , redaction : MatrixEvent ) => {
119120 if ( event ?. isRelation ( THREAD_RELATION_TYPE . name ) &&
120- this . room . eventShouldLiveIn ( event ) . threadId === this . id
121+ this . room . eventShouldLiveIn ( event ) . threadId === this . id &&
122+ ! redaction . status // only respect it when it succeeds
121123 ) {
122124 this . replyCount -- ;
123125 this . emit ( ThreadEvent . Update , this ) ;
124126 }
127+ } ;
125128
126- if ( this . lastEvent ?. getId ( ) === event . getId ( ) ) {
127- const events = [ ...this . timelineSet . getLiveTimeline ( ) . getEvents ( ) ] . reverse ( ) ;
128- this . lastEvent = events . find ( e => (
129- ! e . isRedacted ( ) &&
130- e . getId ( ) !== event . getId ( ) &&
131- e . isRelation ( THREAD_RELATION_TYPE . name )
132- ) ) ?? this . rootEvent ;
133- this . emit ( ThreadEvent . NewReply , this , this . lastEvent ) ;
134- }
129+ private onRedaction = ( event : MatrixEvent ) => {
130+ if ( event . threadRootId !== this . id ) return ; // ignore redactions for other timelines
131+ const events = [ ...this . timelineSet . getLiveTimeline ( ) . getEvents ( ) ] . reverse ( ) ;
132+ this . lastEvent = events . find ( e => (
133+ ! e . isRedacted ( ) &&
134+ e . isRelation ( THREAD_RELATION_TYPE . name )
135+ ) ) ?? this . rootEvent ;
136+ this . emit ( ThreadEvent . Update , this ) ;
135137 } ;
136138
137139 private onEcho = ( event : MatrixEvent ) => {
@@ -142,7 +144,7 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
142144 // when threads are used over federation. That could result in the reply
143145 // count value drifting away from the value returned by the server
144146 const isThreadReply = event . isRelation ( THREAD_RELATION_TYPE . name ) ;
145- if ( ! this . lastEvent || ( isThreadReply
147+ if ( ! this . lastEvent || this . lastEvent . isRedacted ( ) || ( isThreadReply
146148 && ( event . getId ( ) !== this . lastEvent . getId ( ) )
147149 && ( event . localTimestamp > this . lastEvent . localTimestamp ) )
148150 ) {
0 commit comments