@@ -50,7 +50,7 @@ describe("Room", function() {
5050 event : true ,
5151 user : userA ,
5252 room : roomId ,
53- } ) as MatrixEvent ;
53+ } , room . client ) as MatrixEvent ;
5454
5555 const mkReply = ( target : MatrixEvent ) => utils . mkEvent ( {
5656 event : true ,
@@ -65,7 +65,7 @@ describe("Room", function() {
6565 } ,
6666 } ,
6767 } ,
68- } ) as MatrixEvent ;
68+ } , room . client ) as MatrixEvent ;
6969
7070 const mkEdit = ( target : MatrixEvent , salt = Math . random ( ) ) => utils . mkEvent ( {
7171 event : true ,
@@ -82,7 +82,7 @@ describe("Room", function() {
8282 event_id : target . getId ( ) ,
8383 } ,
8484 } ,
85- } ) as MatrixEvent ;
85+ } , room . client ) as MatrixEvent ;
8686
8787 const mkThreadResponse = ( root : MatrixEvent ) => utils . mkEvent ( {
8888 event : true ,
@@ -99,7 +99,7 @@ describe("Room", function() {
9999 "rel_type" : "m.thread" ,
100100 } ,
101101 } ,
102- } ) as MatrixEvent ;
102+ } , room . client ) as MatrixEvent ;
103103
104104 const mkReaction = ( target : MatrixEvent ) => utils . mkEvent ( {
105105 event : true ,
@@ -113,7 +113,7 @@ describe("Room", function() {
113113 "key" : Math . random ( ) . toString ( ) ,
114114 } ,
115115 } ,
116- } ) as MatrixEvent ;
116+ } , room . client ) as MatrixEvent ;
117117
118118 const mkRedaction = ( target : MatrixEvent ) => utils . mkEvent ( {
119119 event : true ,
@@ -122,7 +122,7 @@ describe("Room", function() {
122122 room : roomId ,
123123 redacts : target . getId ( ) ,
124124 content : { } ,
125- } ) as MatrixEvent ;
125+ } , room . client ) as MatrixEvent ;
126126
127127 beforeEach ( function ( ) {
128128 room = new Room ( roomId , new TestClient ( userA , "device" ) . client , userA ) ;
@@ -1899,6 +1899,7 @@ describe("Room", function() {
18991899 "@alice:example.com" , "alicedevice" ,
19001900 ) ) . client ;
19011901 room = new Room ( roomId , client , userA ) ;
1902+ client . getRoom = ( ) => room ;
19021903 } ) ;
19031904
19041905 it ( "allow create threads without a root event" , function ( ) {
@@ -1938,11 +1939,7 @@ describe("Room", function() {
19381939 } ) ;
19391940
19401941 it ( "Edits update the lastReply event" , async ( ) => {
1941- const client = ( new TestClient (
1942- "@alice:example.com" , "alicedevice" ,
1943- ) ) . client ;
1944- client . supportsExperimentalThreads = ( ) => true ;
1945- room = new Room ( roomId , client , userA ) ;
1942+ room . client . supportsExperimentalThreads = ( ) => true ;
19461943
19471944 const randomMessage = mkMessage ( ) ;
19481945 const threadRoot = mkMessage ( ) ;
@@ -1951,7 +1948,7 @@ describe("Room", function() {
19511948 const threadResponseEdit = mkEdit ( threadResponse ) ;
19521949 threadResponseEdit . localTimestamp += 2000 ;
19531950
1954- client . fetchRoomEvent = ( eventId : string ) => Promise . resolve ( {
1951+ room . client . fetchRoomEvent = ( eventId : string ) => Promise . resolve ( {
19551952 ...threadRoot . event ,
19561953 unsigned : {
19571954 "age" : 123 ,
@@ -1975,6 +1972,121 @@ describe("Room", function() {
19751972 await emitPromise ( thread , ThreadEvent . Update ) ;
19761973 expect ( thread . replyToEvent . getContent ( ) . body ) . toBe ( threadResponseEdit . getContent ( ) [ "m.new_content" ] . body ) ;
19771974 } ) ;
1975+
1976+ it ( "Redactions to thread responses decrement the length" , async ( ) => {
1977+ room . client . supportsExperimentalThreads = ( ) => true ;
1978+
1979+ const threadRoot = mkMessage ( ) ;
1980+ const threadResponse1 = mkThreadResponse ( threadRoot ) ;
1981+ threadResponse1 . localTimestamp += 1000 ;
1982+ const threadResponse2 = mkThreadResponse ( threadRoot ) ;
1983+ threadResponse2 . localTimestamp += 2000 ;
1984+
1985+ room . client . fetchRoomEvent = ( eventId : string ) => Promise . resolve ( {
1986+ ...threadRoot . event ,
1987+ unsigned : {
1988+ "age" : 123 ,
1989+ "m.relations" : {
1990+ "m.thread" : {
1991+ latest_event : threadResponse2 . event ,
1992+ count : 2 ,
1993+ current_user_participated : true ,
1994+ } ,
1995+ } ,
1996+ } ,
1997+ } ) ;
1998+
1999+ room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 ] ) ;
2000+ const thread = await emitPromise ( room , ThreadEvent . New ) ;
2001+
2002+ expect ( thread ) . toHaveLength ( 2 ) ;
2003+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
2004+
2005+ const threadResponse1Redaction = mkRedaction ( threadResponse1 ) ;
2006+ room . addLiveEvents ( [ threadResponse1Redaction ] ) ;
2007+ await emitPromise ( thread , ThreadEvent . Update ) ;
2008+ expect ( thread ) . toHaveLength ( 1 ) ;
2009+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
2010+ } ) ;
2011+
2012+ it ( "Redactions to reactions in threads do not decrement the length" , async ( ) => {
2013+ room . client . supportsExperimentalThreads = ( ) => true ;
2014+
2015+ const threadRoot = mkMessage ( ) ;
2016+ const threadResponse1 = mkThreadResponse ( threadRoot ) ;
2017+ threadResponse1 . localTimestamp += 1000 ;
2018+ const threadResponse2 = mkThreadResponse ( threadRoot ) ;
2019+ threadResponse2 . localTimestamp += 2000 ;
2020+ const threadResponse2Reaction = mkReaction ( threadResponse2 ) ;
2021+
2022+ room . client . fetchRoomEvent = ( eventId : string ) => Promise . resolve ( {
2023+ ...threadRoot . event ,
2024+ unsigned : {
2025+ "age" : 123 ,
2026+ "m.relations" : {
2027+ "m.thread" : {
2028+ latest_event : threadResponse2 . event ,
2029+ count : 2 ,
2030+ current_user_participated : true ,
2031+ } ,
2032+ } ,
2033+ } ,
2034+ } ) ;
2035+
2036+ room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 , threadResponse2Reaction ] ) ;
2037+ const thread = await emitPromise ( room , ThreadEvent . New ) ;
2038+
2039+ expect ( thread ) . toHaveLength ( 2 ) ;
2040+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
2041+
2042+ const threadResponse2ReactionRedaction = mkRedaction ( threadResponse2Reaction ) ;
2043+ room . addLiveEvents ( [ threadResponse2ReactionRedaction ] ) ;
2044+ await emitPromise ( thread , ThreadEvent . Update ) ;
2045+ expect ( thread ) . toHaveLength ( 2 ) ;
2046+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
2047+ } ) ;
2048+
2049+ it ( "Redacting the lastEvent finds a new lastEvent" , async ( ) => {
2050+ room . client . supportsExperimentalThreads = ( ) => true ;
2051+
2052+ const threadRoot = mkMessage ( ) ;
2053+ const threadResponse1 = mkThreadResponse ( threadRoot ) ;
2054+ threadResponse1 . localTimestamp += 1000 ;
2055+ const threadResponse2 = mkThreadResponse ( threadRoot ) ;
2056+ threadResponse2 . localTimestamp += 2000 ;
2057+
2058+ room . client . fetchRoomEvent = ( eventId : string ) => Promise . resolve ( {
2059+ ...threadRoot . event ,
2060+ unsigned : {
2061+ "age" : 123 ,
2062+ "m.relations" : {
2063+ "m.thread" : {
2064+ latest_event : threadResponse2 . event ,
2065+ count : 2 ,
2066+ current_user_participated : true ,
2067+ } ,
2068+ } ,
2069+ } ,
2070+ } ) ;
2071+
2072+ room . addLiveEvents ( [ threadRoot , threadResponse1 , threadResponse2 ] ) ;
2073+ const thread = await emitPromise ( room , ThreadEvent . New ) ;
2074+
2075+ expect ( thread ) . toHaveLength ( 2 ) ;
2076+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse2 . getId ( ) ) ;
2077+
2078+ const threadResponse2Redaction = mkRedaction ( threadResponse2 ) ;
2079+ room . addLiveEvents ( [ threadResponse2Redaction ] ) ;
2080+ await emitPromise ( thread , ThreadEvent . Update ) ;
2081+ expect ( thread ) . toHaveLength ( 1 ) ;
2082+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadResponse1 . getId ( ) ) ;
2083+
2084+ const threadResponse1Redaction = mkRedaction ( threadResponse1 ) ;
2085+ room . addLiveEvents ( [ threadResponse1Redaction ] ) ;
2086+ await emitPromise ( thread , ThreadEvent . Update ) ;
2087+ expect ( thread ) . toHaveLength ( 0 ) ;
2088+ expect ( thread . replyToEvent . getId ( ) ) . toBe ( threadRoot . getId ( ) ) ;
2089+ } ) ;
19782090 } ) ;
19792091
19802092 describe ( "eventShouldLiveIn" , ( ) => {
0 commit comments