@@ -87,7 +87,7 @@ describe("MatrixClient", function() {
8787 // }
8888 // items are popped off when processed and block if no items left.
8989 ] ;
90- let acceptKeepalives ;
90+ let acceptKeepalives : boolean ;
9191 let pendingLookup = null ;
9292 function httpReq ( cb , method , path , qp , data , prefix ) {
9393 if ( path === KEEP_ALIVE_PATH && acceptKeepalives ) {
@@ -127,7 +127,7 @@ describe("MatrixClient", function() {
127127 ( next . error ? "BAD" : "GOOD" ) + " response" ,
128128 ) ;
129129 if ( next . expectBody ) {
130- expect ( next . expectBody ) . toEqual ( data ) ;
130+ expect ( data ) . toEqual ( next . expectBody ) ;
131131 }
132132 if ( next . expectQueryParams ) {
133133 Object . keys ( next . expectQueryParams ) . forEach ( function ( k ) {
@@ -777,7 +777,7 @@ describe("MatrixClient", function() {
777777 expectBody : content ,
778778 } ] ;
779779
780- await client . sendEvent ( roomId , EventType . RoomMessage , content , txnId ) ;
780+ await client . sendEvent ( roomId , EventType . RoomMessage , { ... content } , txnId ) ;
781781 } ) ;
782782
783783 it ( "overload with null threadId works" , async ( ) => {
@@ -790,20 +790,99 @@ describe("MatrixClient", function() {
790790 expectBody : content ,
791791 } ] ;
792792
793- await client . sendEvent ( roomId , null , EventType . RoomMessage , content , txnId ) ;
793+ await client . sendEvent ( roomId , null , EventType . RoomMessage , { ... content } , txnId ) ;
794794 } ) ;
795795
796796 it ( "overload with threadId works" , async ( ) => {
797797 const eventId = "$eventId:example.org" ;
798798 const txnId = client . makeTxnId ( ) ;
799+ const threadId = "$threadId:server" ;
799800 httpLookups = [ {
800801 method : "PUT" ,
801802 path : `/rooms/${ encodeURIComponent ( roomId ) } /send/m.room.message/${ txnId } ` ,
802803 data : { event_id : eventId } ,
803- expectBody : content ,
804+ expectBody : {
805+ ...content ,
806+ "m.relates_to" : {
807+ "event_id" : threadId ,
808+ "is_falling_back" : true ,
809+ "rel_type" : "m.thread" ,
810+ } ,
811+ } ,
812+ } ] ;
813+
814+ await client . sendEvent ( roomId , threadId , EventType . RoomMessage , { ...content } , txnId ) ;
815+ } ) ;
816+
817+ it ( "should add thread relation if threadId is passed and the relation is missing" , async ( ) => {
818+ const eventId = "$eventId:example.org" ;
819+ const threadId = "$threadId:server" ;
820+ const txnId = client . makeTxnId ( ) ;
821+
822+ const room = new Room ( roomId , client , userId ) ;
823+ store . getRoom . mockReturnValue ( room ) ;
824+
825+ const rootEvent = new MatrixEvent ( { event_id : threadId } ) ;
826+ room . createThread ( threadId , rootEvent , [ rootEvent ] , false ) ;
827+
828+ httpLookups = [ {
829+ method : "PUT" ,
830+ path : `/rooms/${ encodeURIComponent ( roomId ) } /send/m.room.message/${ txnId } ` ,
831+ data : { event_id : eventId } ,
832+ expectBody : {
833+ ...content ,
834+ "m.relates_to" : {
835+ "m.in_reply_to" : {
836+ event_id : threadId ,
837+ } ,
838+ "event_id" : threadId ,
839+ "is_falling_back" : true ,
840+ "rel_type" : "m.thread" ,
841+ } ,
842+ } ,
843+ } ] ;
844+
845+ await client . sendEvent ( roomId , threadId , EventType . RoomMessage , { ...content } , txnId ) ;
846+ } ) ;
847+
848+ it ( "should add thread relation if threadId is passed and the relation is missing with reply" , async ( ) => {
849+ const eventId = "$eventId:example.org" ;
850+ const threadId = "$threadId:server" ;
851+ const txnId = client . makeTxnId ( ) ;
852+
853+ const content = {
854+ body,
855+ "m.relates_to" : {
856+ "m.in_reply_to" : {
857+ event_id : "$other:event" ,
858+ } ,
859+ } ,
860+ } ;
861+
862+ const room = new Room ( roomId , client , userId ) ;
863+ store . getRoom . mockReturnValue ( room ) ;
864+
865+ const rootEvent = new MatrixEvent ( { event_id : threadId } ) ;
866+ room . createThread ( threadId , rootEvent , [ rootEvent ] , false ) ;
867+
868+ httpLookups = [ {
869+ method : "PUT" ,
870+ path : `/rooms/${ encodeURIComponent ( roomId ) } /send/m.room.message/${ txnId } ` ,
871+ data : { event_id : eventId } ,
872+ expectBody : {
873+ ...content ,
874+ "m.relates_to" : {
875+ "m.in_reply_to" : {
876+ event_id : "$other:event" ,
877+ } ,
878+ "event_id" : threadId ,
879+ "is_falling_back" : false ,
880+ "rel_type" : "m.thread" ,
881+ } ,
882+ } ,
804883 } ] ;
805884
806- await client . sendEvent ( roomId , "$ threadId:server" , EventType . RoomMessage , content , txnId ) ;
885+ await client . sendEvent ( roomId , threadId , EventType . RoomMessage , { ... content } , txnId ) ;
807886 } ) ;
808887 } ) ;
809888
0 commit comments