@@ -19,7 +19,7 @@ import { Optional } from "matrix-events-sdk";
1919import { MatrixClient } from "../client" ;
2020import { TypedReEmitter } from "../ReEmitter" ;
2121import { RelationType } from "../@types/event" ;
22- import { IThreadBundledRelationship , MatrixEvent , MatrixEventEvent } from "./event" ;
22+ import { EventStatus , IThreadBundledRelationship , MatrixEvent , MatrixEventEvent } from "./event" ;
2323import { EventTimeline } from "./event-timeline" ;
2424import { EventTimelineSet , EventTimelineSetHandlerMap } from './event-timeline-set' ;
2525import { NotificationCountType , Room , RoomEvent } from './room' ;
@@ -88,6 +88,8 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
8888
8989 private lastEvent : MatrixEvent | undefined ;
9090 private replyCount = 0 ;
91+ private lastPendingEvent : MatrixEvent | undefined ;
92+ private pendingReplyCount = 0 ;
9193
9294 public readonly room : Room ;
9395 public readonly client : MatrixClient ;
@@ -300,6 +302,15 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
300302 bundledRelationship = this . getRootEventBundledRelationship ( ) ;
301303 }
302304
305+ const pendingEvents = this . room . getPendingEvents ( ) . filter ( ( ev ) => {
306+ const isNotSent = ev . status === EventStatus . NOT_SENT ;
307+ const belongsToTheThread = this . id === ev . threadRootId ;
308+ return isNotSent && belongsToTheThread ;
309+ } ) ;
310+ pendingEvents . map ( ( ev ) => this . processEvent ( ev ) ) ;
311+ this . lastPendingEvent = pendingEvents . length ? pendingEvents [ pendingEvents . length - 1 ] : undefined ;
312+ this . pendingReplyCount = pendingEvents . length ;
313+
303314 if ( Thread . hasServerSideSupport && bundledRelationship ) {
304315 this . replyCount = bundledRelationship . count ;
305316 this . _currentUserParticipated = ! ! bundledRelationship . current_user_participated ;
@@ -393,14 +404,14 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
393404 * exclude annotations from that number
394405 */
395406 public get length ( ) : number {
396- return this . replyCount ;
407+ return this . replyCount + this . pendingReplyCount ;
397408 }
398409
399410 /**
400411 * A getter for the last event added to the thread, if known.
401412 */
402413 public get replyToEvent ( ) : Optional < MatrixEvent > {
403- return this . lastEvent ?? this . lastReply ( ) ;
414+ return this . lastPendingEvent ?? this . lastEvent ?? this . lastReply ( ) ;
404415 }
405416
406417 public get events ( ) : MatrixEvent [ ] {
0 commit comments