@@ -16,10 +16,10 @@ limitations under the License.
16
16
17
17
import { Optional } from "matrix-events-sdk" ;
18
18
19
- import { MatrixClient } from "../client" ;
19
+ import { MatrixClient , PendingEventOrdering } from "../client" ;
20
20
import { TypedReEmitter } from "../ReEmitter" ;
21
21
import { RelationType } from "../@types/event" ;
22
- import { IThreadBundledRelationship , MatrixEvent , MatrixEventEvent } from "./event" ;
22
+ import { EventStatus , IThreadBundledRelationship , MatrixEvent , MatrixEventEvent } from "./event" ;
23
23
import { EventTimeline } from "./event-timeline" ;
24
24
import { EventTimelineSet , EventTimelineSetHandlerMap } from './event-timeline-set' ;
25
25
import { NotificationCountType , Room , RoomEvent } from './room' ;
@@ -51,6 +51,7 @@ export type EventHandlerMap = {
51
51
interface IThreadOpts {
52
52
room : Room ;
53
53
client : MatrixClient ;
54
+ pendingEventOrdering ?: PendingEventOrdering ;
54
55
}
55
56
56
57
export enum FeatureSupport {
@@ -88,9 +89,12 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
88
89
89
90
private lastEvent : MatrixEvent | undefined ;
90
91
private replyCount = 0 ;
92
+ private lastPendingEvent : MatrixEvent | undefined ;
93
+ private pendingReplyCount = 0 ;
91
94
92
95
public readonly room : Room ;
93
96
public readonly client : MatrixClient ;
97
+ private readonly pendingEventOrdering : PendingEventOrdering ;
94
98
95
99
public initialEventsFetched = ! Thread . hasServerSideSupport ;
96
100
@@ -109,6 +113,7 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
109
113
110
114
this . room = opts . room ;
111
115
this . client = opts . client ;
116
+ this . pendingEventOrdering = opts . pendingEventOrdering ?? PendingEventOrdering . Chronological ;
112
117
this . timelineSet = new EventTimelineSet ( this . room , {
113
118
timelineSupport : true ,
114
119
pendingEvents : true ,
@@ -300,6 +305,18 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
300
305
bundledRelationship = this . getRootEventBundledRelationship ( ) ;
301
306
}
302
307
308
+ let pendingEvents : MatrixEvent [ ] = [ ] ;
309
+ if ( this . pendingEventOrdering === PendingEventOrdering . Detached ) {
310
+ pendingEvents = this . room . getPendingEvents ( ) . filter ( ( ev ) => {
311
+ const isNotSent = ev . status === EventStatus . NOT_SENT ;
312
+ const belongsToTheThread = this . id === ev . threadRootId ;
313
+ return isNotSent && belongsToTheThread ;
314
+ } ) ;
315
+ pendingEvents . map ( ( ev ) => this . processEvent ( ev ) ) ;
316
+ }
317
+ this . lastPendingEvent = pendingEvents . length ? pendingEvents [ pendingEvents . length - 1 ] : undefined ;
318
+ this . pendingReplyCount = pendingEvents . length ;
319
+
303
320
if ( Thread . hasServerSideSupport && bundledRelationship ) {
304
321
this . replyCount = bundledRelationship . count ;
305
322
this . _currentUserParticipated = ! ! bundledRelationship . current_user_participated ;
@@ -393,14 +410,14 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
393
410
* exclude annotations from that number
394
411
*/
395
412
public get length ( ) : number {
396
- return this . replyCount ;
413
+ return this . replyCount + this . pendingReplyCount ;
397
414
}
398
415
399
416
/**
400
417
* A getter for the last event added to the thread, if known.
401
418
*/
402
419
public get replyToEvent ( ) : Optional < MatrixEvent > {
403
- return this . lastEvent ?? this . lastReply ( ) ;
420
+ return this . lastPendingEvent ?? this . lastEvent ?? this . lastReply ( ) ;
404
421
}
405
422
406
423
public get events ( ) : MatrixEvent [ ] {
0 commit comments