Skip to content

Commit d2fee99

Browse files
Be tolerant of the the end key not existing in a /messages resposne (#489)
As spec'd: > If no further events are available (either because we have reached the start of the timeline, or because the user does not have permission to see any more events), this property is omitted from the response. > > *-- https://spec.matrix.org/v1.1/client-server-api/#get_matrixclientv3roomsroomidmessages* Split out from #214 Previously, it would throw the following error and potentially we found all of the events within that last response to satisfy everything, ``` JSONFieldStr: key 'end' missing ```
1 parent 0b7d990 commit d2fee99

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/msc2716_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,6 @@ func paginateUntilMessageCheckOff(t *testing.T, c *client.CSAPI, roomID string,
12541254
}))
12551255
callCounter++
12561256
messsageResBody := client.ParseJSON(t, messagesRes)
1257-
messageResEnd = client.GetJSONFieldStr(t, messsageResBody, "end")
12581257
// Since the original body can only be read once, create a new one from the body bytes we just read
12591258
messagesRes.Body = ioutil.NopCloser(bytes.NewBuffer(messsageResBody))
12601259

@@ -1294,6 +1293,12 @@ func paginateUntilMessageCheckOff(t *testing.T, c *client.CSAPI, roomID string,
12941293
if len(workingExpectedEventIDMap) == 0 {
12951294
return
12961295
}
1296+
1297+
// Since this will throw an error if they key does not exist, do this at the end of
1298+
// the loop. It's a valid scenario to be at the end of the room and have no more to
1299+
// paginate so we want to make sure the `return` above runs when we've found all of
1300+
// the expected events.
1301+
messageResEnd = client.GetJSONFieldStr(t, messsageResBody, "end")
12971302
}
12981303
}
12991304

0 commit comments

Comments
 (0)