@@ -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,35 @@ 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+ if r .Get ("type" ).Str != "m.read" {
68+ return false
69+ }
70+
71+ // Ensure that the `room_id` field does NOT exist.
72+ if r .Get ("room_id" ).Exists () {
73+ t .Fatalf ("Read receipt included `room_id` field down sync: %s" , r .Raw )
74+ }
75+
76+ // Exit the /sync loop.
77+ return true ;
78+ }),
79+ )
80+ })
4981}
5082
5183// sytest: POST /rooms/:room_id/read_markers can create read marker
0 commit comments