@@ -17,15 +17,19 @@ func createRoomForReadReceipts(t *testing.T, c *client.CSAPI) (string, string) {
1717
1818 c .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (c .UserID , roomID ))
1919
20- eventID := c .SendEventSynced (t , roomID , b.Event {
20+ eventID := sendMessageIntoRoom (t , c , roomID )
21+
22+ return roomID , eventID
23+ }
24+
25+ func sendMessageIntoRoom (t * testing.T , c * client.CSAPI , roomID string ) string {
26+ return c .SendEventSynced (t , roomID , b.Event {
2127 Type : "m.room.message" ,
2228 Content : map [string ]interface {}{
2329 "msgtype" : "m.text" ,
2430 "body" : "Hello world!" ,
2531 },
2632 })
27-
28- return roomID , eventID
2933}
3034
3135func syncHasReadReceipt (roomID , userID , eventID string ) client.SyncCheckOpt {
@@ -45,7 +49,41 @@ func TestRoomReceipts(t *testing.T) {
4549 alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "v3" , "rooms" , roomID , "receipt" , "m.read" , eventID }, client .WithJSONBody (t , struct {}{}))
4650
4751 // Make sure the read receipt shows up in sync.
48- alice .MustSyncUntil (t , client.SyncReq {}, syncHasReadReceipt (roomID , alice .UserID , eventID ))
52+ sinceToken := alice .MustSyncUntil (t , client.SyncReq {}, syncHasReadReceipt (roomID , alice .UserID , eventID ))
53+
54+ // Receipt events include a `room_id` field over federation, but they should
55+ // not do so down `/sync` to clients. Ensure homeservers strip that field out.
56+ t .Run ("Receipts DO NOT include a `room_id` field" , func (t * testing.T ) {
57+ // Send another event to read.
58+ eventID2 := sendMessageIntoRoom (t , alice , roomID )
59+
60+ // Send a read receipt for the event.
61+ alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "v3" , "rooms" , roomID , "receipt" , "m.read" , eventID2 }, client .WithJSONBody (t , struct {}{}))
62+
63+ alice .MustSyncUntil (
64+ t ,
65+ client.SyncReq {Since : sinceToken },
66+ client .SyncEphemeralHas (roomID , func (r gjson.Result ) bool {
67+ // Check that this is a m.receipt ephemeral event.
68+ if r .Get ("type" ).Str != "m.receipt" {
69+ return false
70+ }
71+
72+ // Check that the receipt type is "m.read".
73+ if ! r .Get (`content.*.m\.read` ).Exists () {
74+ t .Fatalf ("Receipt was not of type 'm.read'" )
75+ }
76+
77+ // Ensure that the `room_id` field does NOT exist.
78+ if r .Get ("room_id" ).Exists () {
79+ t .Fatalf ("Read receipt should not contain 'room_id' field when syncing but saw: %s" , r .Raw )
80+ }
81+
82+ // Exit the /sync loop.
83+ return true ;
84+ }),
85+ )
86+ })
4987}
5088
5189// sytest: POST /rooms/:room_id/read_markers can create read marker
0 commit comments