@@ -95,6 +95,7 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
95
95
] ) ;
96
96
97
97
this . room . on ( MatrixEventEvent . BeforeRedaction , this . onBeforeRedaction ) ;
98
+ this . room . on ( RoomEvent . Redaction , this . onRedaction ) ;
98
99
this . room . on ( RoomEvent . LocalEchoUpdated , this . onEcho ) ;
99
100
this . timelineSet . on ( RoomEvent . Timeline , this . onEcho ) ;
100
101
@@ -115,23 +116,24 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
115
116
}
116
117
}
117
118
118
- private onBeforeRedaction = ( event : MatrixEvent ) => {
119
+ private onBeforeRedaction = ( event : MatrixEvent , redaction : MatrixEvent ) => {
119
120
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
121
123
) {
122
124
this . replyCount -- ;
123
125
this . emit ( ThreadEvent . Update , this ) ;
124
126
}
127
+ } ;
125
128
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 ) ;
135
137
} ;
136
138
137
139
private onEcho = ( event : MatrixEvent ) => {
@@ -142,7 +144,7 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
142
144
// when threads are used over federation. That could result in the reply
143
145
// count value drifting away from the value returned by the server
144
146
const isThreadReply = event . isRelation ( THREAD_RELATION_TYPE . name ) ;
145
- if ( ! this . lastEvent || ( isThreadReply
147
+ if ( ! this . lastEvent || this . lastEvent . isRedacted ( ) || ( isThreadReply
146
148
&& ( event . getId ( ) !== this . lastEvent . getId ( ) )
147
149
&& ( event . localTimestamp > this . lastEvent . localTimestamp ) )
148
150
) {
0 commit comments