@@ -39,6 +39,7 @@ import {
3939 UNSTABLE_ELEMENT_FUNCTIONAL_USERS ,
4040 EVENT_VISIBILITY_CHANGE_TYPE ,
4141 RelationType ,
42+ UNSIGNED_THREAD_ID_FIELD ,
4243} from "../@types/event" ;
4344import { IRoomVersionsCapability , MatrixClient , PendingEventOrdering , RoomVersionStability } from "../client" ;
4445import { GuestAccess , HistoryVisibility , JoinRule , ResizeMethod } from "../@types/partials" ;
@@ -2113,12 +2114,11 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
21132114 }
21142115
21152116 // A thread relation is always only shown in a thread
2116- const threadRootId = event . threadRootId ;
2117- if ( threadRootId != undefined ) {
2117+ if ( event . isRelation ( THREAD_RELATION_TYPE . name ) ) {
21182118 return {
21192119 shouldLiveInRoom : false ,
21202120 shouldLiveInThread : true ,
2121- threadId : threadRootId ,
2121+ threadId : event . threadRootId ,
21222122 } ;
21232123 }
21242124
@@ -2149,6 +2149,15 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
21492149 } ;
21502150 }
21512151
2152+ const unsigned = event . getUnsigned ( ) ;
2153+ if ( typeof unsigned [ UNSIGNED_THREAD_ID_FIELD . name ] === "string" ) {
2154+ return {
2155+ shouldLiveInRoom : false ,
2156+ shouldLiveInThread : true ,
2157+ threadId : unsigned [ UNSIGNED_THREAD_ID_FIELD . name ] ,
2158+ } ;
2159+ }
2160+
21522161 // We've exhausted all scenarios,
21532162 // we cannot assume that it lives in the main timeline as this may be a relation for an unknown thread
21542163 // adding the event in the wrong timeline causes stuck notifications and can break ability to send read receipts
@@ -2804,7 +2813,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
28042813 if ( parentEvent . threadRootId ) {
28052814 threadRoots . add ( parentEvent . threadRootId ) ;
28062815 const unsigned = event . getUnsigned ( ) ;
2807- unsigned [ "org.matrix.msc4023.thread_id" ] = parentEvent . threadRootId ;
2816+ unsigned [ UNSIGNED_THREAD_ID_FIELD . name ] = parentEvent . threadRootId ;
28082817 event . setUnsigned ( unsigned ) ;
28092818 }
28102819
@@ -2881,9 +2890,12 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
28812890 private findThreadRoots ( events : MatrixEvent [ ] ) : Set < string > {
28822891 const threadRoots = new Set < string > ( ) ;
28832892 for ( const event of events ) {
2884- const threadRootId = event . threadRootId ;
2885- if ( threadRootId != undefined ) {
2886- threadRoots . add ( threadRootId ) ;
2893+ if ( event . isRelation ( THREAD_RELATION_TYPE . name ) ) {
2894+ threadRoots . add ( event . relationEventId ?? "" ) ;
2895+ }
2896+ const unsigned = event . getUnsigned ( ) ;
2897+ if ( typeof unsigned [ UNSIGNED_THREAD_ID_FIELD . name ] === "string" ) {
2898+ threadRoots . add ( unsigned [ UNSIGNED_THREAD_ID_FIELD . name ] ! ) ;
28872899 }
28882900 }
28892901 return threadRoots ;
0 commit comments