@@ -36,7 +36,7 @@ import { RoomState } from "../../src/models/room-state";
3636import { UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "../../src/@types/event" ;
3737import { TestClient } from "../TestClient" ;
3838import { emitPromise } from "../test-utils/test-utils" ;
39- import { ThreadEvent } from "../../src/models/thread" ;
39+ import { Thread , ThreadEvent } from "../../src/models/thread" ;
4040
4141describe ( "Room" , function ( ) {
4242 const roomId = "!foo:bar" ;
@@ -1914,7 +1914,7 @@ describe("Room", function() {
19141914 } ,
19151915 } ) ;
19161916
1917- room . createThread ( undefined , [ eventWithoutARootEvent ] ) ;
1917+ room . createThread ( "$000" , undefined , [ eventWithoutARootEvent ] ) ;
19181918
19191919 const rootEvent = new MatrixEvent ( {
19201920 event_id : "$666" ,
@@ -1932,7 +1932,7 @@ describe("Room", function() {
19321932 } ,
19331933 } ) ;
19341934
1935- expect ( ( ) => room . createThread ( rootEvent , [ ] ) ) . not . toThrow ( ) ;
1935+ expect ( ( ) => room . createThread ( rootEvent . getId ( ) , rootEvent , [ ] ) ) . not . toThrow ( ) ;
19361936 } ) ;
19371937
19381938 it ( "Edits update the lastReply event" , async ( ) => {
@@ -1959,14 +1959,16 @@ describe("Room", function() {
19591959 } ,
19601960 } ) ;
19611961
1962+ let prom = emitPromise ( room , ThreadEvent . New ) ;
19621963 room . addLiveEvents ( [ randomMessage , threadRoot , threadResponse ] ) ;
1963- const thread = await emitPromise ( room , ThreadEvent . New ) ;
1964+ const thread = await prom ;
19641965
19651966 expect ( thread . replyToEvent ) . toBe ( threadResponse ) ;
19661967 expect ( thread . replyToEvent . getContent ( ) . body ) . toBe ( threadResponse . getContent ( ) . body ) ;
19671968
1969+ prom = emitPromise ( thread , ThreadEvent . Update ) ;
19681970 room . addLiveEvents ( [ threadResponseEdit ] ) ;
1969- await emitPromise ( thread , ThreadEvent . Update ) ;
1971+ await prom ;
19701972 expect ( thread . replyToEvent . getContent ( ) . body ) . toBe ( threadResponseEdit . getContent ( ) [ "m.new_content" ] . body ) ;
19711973 } ) ;
19721974
@@ -1993,15 +1995,17 @@ describe("Room", function() {
19931995 } ,
19941996 } ) ;
19951997
1998+ let prom = emitPromise ( room , ThreadEvent . New ) ;
19961999 room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 ] ) ;
1997- const thread = await emitPromise ( room , ThreadEvent . New ) ;
2000+ const thread = await prom ;
19982001
19992002 expect ( thread ) . toHaveLength ( 2 ) ;
20002003 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
20012004
2005+ prom = emitPromise ( thread , ThreadEvent . Update ) ;
20022006 const threadResponse1Redaction = mkRedaction ( threadResponse1 ) ;
20032007 room . addLiveEvents ( [ threadResponse1Redaction ] ) ;
2004- await emitPromise ( thread , ThreadEvent . Update ) ;
2008+ await prom ;
20052009 expect ( thread ) . toHaveLength ( 1 ) ;
20062010 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
20072011 } ) ;
@@ -2030,15 +2034,17 @@ describe("Room", function() {
20302034 } ,
20312035 } ) ;
20322036
2037+ let prom = emitPromise ( room , ThreadEvent . New ) ;
20332038 room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 , threadResponse2Reaction ] ) ;
2034- const thread = await emitPromise ( room , ThreadEvent . New ) ;
2039+ const thread = await prom ;
20352040
20362041 expect ( thread ) . toHaveLength ( 2 ) ;
20372042 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
20382043
2044+ prom = emitPromise ( thread , ThreadEvent . Update ) ;
20392045 const threadResponse2ReactionRedaction = mkRedaction ( threadResponse2Reaction ) ;
20402046 room . addLiveEvents ( [ threadResponse2ReactionRedaction ] ) ;
2041- await emitPromise ( thread , ThreadEvent . Update ) ;
2047+ await prom ;
20422048 expect ( thread ) . toHaveLength ( 2 ) ;
20432049 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
20442050 } ) ;
@@ -2067,15 +2073,17 @@ describe("Room", function() {
20672073 } ,
20682074 } ) ;
20692075
2076+ let prom = emitPromise ( room , ThreadEvent . New ) ;
20702077 room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 , threadResponse2Reaction ] ) ;
2071- const thread = await emitPromise ( room , ThreadEvent . New ) ;
2078+ const thread = await prom ;
20722079
20732080 expect ( thread ) . toHaveLength ( 2 ) ;
20742081 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
20752082
2083+ prom = emitPromise ( room , ThreadEvent . Update ) ;
20762084 const threadRootRedaction = mkRedaction ( threadRoot ) ;
20772085 room . addLiveEvents ( [ threadRootRedaction ] ) ;
2078- await emitPromise ( thread , ThreadEvent . Update ) ;
2086+ await prom ;
20792087 expect ( thread ) . toHaveLength ( 2 ) ;
20802088 } ) ;
20812089
@@ -2102,21 +2110,24 @@ describe("Room", function() {
21022110 } ,
21032111 } ) ;
21042112
2113+ let prom = emitPromise ( room , ThreadEvent . New ) ;
21052114 room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 ] ) ;
2106- const thread = await emitPromise ( room , ThreadEvent . New ) ;
2115+ const thread = await prom ;
21072116
21082117 expect ( thread ) . toHaveLength ( 2 ) ;
21092118 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
21102119
2120+ prom = emitPromise ( room , ThreadEvent . Update ) ;
21112121 const threadResponse2Redaction = mkRedaction ( threadResponse2 ) ;
21122122 room . addLiveEvents ( [ threadResponse2Redaction ] ) ;
2113- await emitPromise ( thread , ThreadEvent . Update ) ;
2123+ await prom ;
21142124 expect ( thread ) . toHaveLength ( 1 ) ;
21152125 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse1 . getId ( ) ) ;
21162126
2127+ prom = emitPromise ( room , ThreadEvent . Update ) ;
21172128 const threadResponse1Redaction = mkRedaction ( threadResponse1 ) ;
21182129 room . addLiveEvents ( [ threadResponse1Redaction ] ) ;
2119- await emitPromise ( thread , ThreadEvent . Update ) ;
2130+ await prom ;
21202131 expect ( thread ) . toHaveLength ( 0 ) ;
21212132 expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadRoot . getId ( ) ) ;
21222133 } ) ;
@@ -2234,5 +2245,45 @@ describe("Room", function() {
22342245 expect ( room . eventShouldLiveIn ( reply2 , events , roots ) . shouldLiveInRoom ) . toBeTruthy ( ) ;
22352246 expect ( room . eventShouldLiveIn ( reply2 , events , roots ) . shouldLiveInThread ) . toBeFalsy ( ) ;
22362247 } ) ;
2248+
2249+ it ( "should aggregate relations in thread event timeline set" , ( ) => {
2250+ Thread . setServerSideSupport ( true , true ) ;
2251+ const threadRoot = mkMessage ( ) ;
2252+ const rootReaction = mkReaction ( threadRoot ) ;
2253+ const threadResponse = mkThreadResponse ( threadRoot ) ;
2254+ const threadReaction = mkReaction ( threadResponse ) ;
2255+
2256+ const events = [
2257+ threadRoot ,
2258+ rootReaction ,
2259+ threadResponse ,
2260+ threadReaction ,
2261+ ] ;
2262+
2263+ room . addLiveEvents ( events ) ;
2264+
2265+ const thread = threadRoot . getThread ( ) ;
2266+ expect ( thread . rootEvent ) . toBe ( threadRoot ) ;
2267+
2268+ const rootRelations = thread . timelineSet . getRelationsForEvent (
2269+ threadRoot . getId ( ) ,
2270+ RelationType . Annotation ,
2271+ EventType . Reaction ,
2272+ ) . getSortedAnnotationsByKey ( ) ;
2273+ expect ( rootRelations ) . toHaveLength ( 1 ) ;
2274+ expect ( rootRelations [ 0 ] [ 0 ] ) . toEqual ( rootReaction . getRelation ( ) . key ) ;
2275+ expect ( rootRelations [ 0 ] [ 1 ] . size ) . toEqual ( 1 ) ;
2276+ expect ( rootRelations [ 0 ] [ 1 ] . has ( rootReaction ) ) . toBeTruthy ( ) ;
2277+
2278+ const responseRelations = thread . timelineSet . getRelationsForEvent (
2279+ threadResponse . getId ( ) ,
2280+ RelationType . Annotation ,
2281+ EventType . Reaction ,
2282+ ) . getSortedAnnotationsByKey ( ) ;
2283+ expect ( responseRelations ) . toHaveLength ( 1 ) ;
2284+ expect ( responseRelations [ 0 ] [ 0 ] ) . toEqual ( threadReaction . getRelation ( ) . key ) ;
2285+ expect ( responseRelations [ 0 ] [ 1 ] . size ) . toEqual ( 1 ) ;
2286+ expect ( responseRelations [ 0 ] [ 1 ] . has ( threadReaction ) ) . toBeTruthy ( ) ;
2287+ } ) ;
22372288 } ) ;
22382289} ) ;
0 commit comments