@@ -18,6 +18,7 @@ import MockHttpBackend from 'matrix-mock-request';
1818
1919import { ReceiptType } from '../../src/@types/read_receipts' ;
2020import { MatrixClient } from "../../src/client" ;
21+ import { Feature , ServerSupport } from '../../src/feature' ;
2122import { EventType } from '../../src/matrix' ;
2223import { MAIN_ROOM_TIMELINE } from '../../src/models/read-receipt' ;
2324import { encodeUri } from '../../src/utils' ;
@@ -69,15 +70,8 @@ const roomEvent = utils.mkEvent({
6970 } ,
7071} ) ;
7172
72- function mockServerSideSupport ( client , hasServerSideSupport ) {
73- const doesServerSupportUnstableFeature = client . doesServerSupportUnstableFeature ;
74- client . doesServerSupportUnstableFeature = ( unstableFeature ) => {
75- if ( unstableFeature === "org.matrix.msc3771" ) {
76- return Promise . resolve ( hasServerSideSupport ) ;
77- } else {
78- return doesServerSupportUnstableFeature ( unstableFeature ) ;
79- }
80- } ;
73+ function mockServerSideSupport ( client , serverSideSupport : ServerSupport ) {
74+ client . canSupport . set ( Feature . ThreadUnreadNotifications , serverSideSupport ) ;
8175}
8276
8377describe ( "Read receipt" , ( ) => {
@@ -103,13 +97,31 @@ describe("Read receipt", () => {
10397 expect ( request . data . thread_id ) . toEqual ( THREAD_ID ) ;
10498 } ) . respond ( 200 , { } ) ;
10599
106- mockServerSideSupport ( client , true ) ;
100+ mockServerSideSupport ( client , ServerSupport . Stable ) ;
107101 client . sendReceipt ( threadEvent , ReceiptType . Read , { } ) ;
108102
109103 await httpBackend . flushAllExpected ( ) ;
110104 await flushPromises ( ) ;
111105 } ) ;
112106
107+ it ( "sends an unthreaded receipt" , async ( ) => {
108+ httpBackend . when (
109+ "POST" , encodeUri ( "/rooms/$roomId/receipt/$receiptType/$eventId" , {
110+ $roomId : ROOM_ID ,
111+ $receiptType : ReceiptType . Read ,
112+ $eventId : threadEvent . getId ( ) ! ,
113+ } ) ,
114+ ) . check ( ( request ) => {
115+ expect ( request . data . thread_id ) . toBeUndefined ( ) ;
116+ } ) . respond ( 200 , { } ) ;
117+
118+ mockServerSideSupport ( client , ServerSupport . Stable ) ;
119+ client . sendReadReceipt ( threadEvent , ReceiptType . Read , true ) ;
120+
121+ await httpBackend . flushAllExpected ( ) ;
122+ await flushPromises ( ) ;
123+ } ) ;
124+
113125 it ( "sends a room read receipt" , async ( ) => {
114126 httpBackend . when (
115127 "POST" , encodeUri ( "/rooms/$roomId/receipt/$receiptType/$eventId" , {
@@ -121,7 +133,7 @@ describe("Read receipt", () => {
121133 expect ( request . data . thread_id ) . toEqual ( MAIN_ROOM_TIMELINE ) ;
122134 } ) . respond ( 200 , { } ) ;
123135
124- mockServerSideSupport ( client , true ) ;
136+ mockServerSideSupport ( client , ServerSupport . Stable ) ;
125137 client . sendReceipt ( roomEvent , ReceiptType . Read , { } ) ;
126138
127139 await httpBackend . flushAllExpected ( ) ;
@@ -139,7 +151,7 @@ describe("Read receipt", () => {
139151 expect ( request . data . thread_id ) . toBeUndefined ( ) ;
140152 } ) . respond ( 200 , { } ) ;
141153
142- mockServerSideSupport ( client , false ) ;
154+ mockServerSideSupport ( client , ServerSupport . Unsupported ) ;
143155 client . sendReceipt ( threadEvent , ReceiptType . Read , { } ) ;
144156
145157 await httpBackend . flushAllExpected ( ) ;
@@ -157,7 +169,7 @@ describe("Read receipt", () => {
157169 expect ( request . data ) . toEqual ( { } ) ;
158170 } ) . respond ( 200 , { } ) ;
159171
160- mockServerSideSupport ( client , false ) ;
172+ mockServerSideSupport ( client , ServerSupport . Unsupported ) ;
161173 client . sendReceipt ( threadEvent , ReceiptType . Read , undefined ) ;
162174
163175 await httpBackend . flushAllExpected ( ) ;
0 commit comments