diff options
author | Kegsay <kegan@matrix.org> | 2020-12-16 18:10:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-16 18:10:39 +0000 |
commit | 76becac003bdfe2c3bcf37f6f5f6024d1aac7d73 (patch) | |
tree | ba1a57b56b636fb2026ce6c5962d0bda519ae9d4 | |
parent | 42e9cbf342d2d16194b10f6e0b44b0b1c01e8810 (diff) |
Add start_stream to /messages (#1648)
-rw-r--r-- | syncapi/routing/messages.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go index 64e0fa68..14389ebb 100644 --- a/syncapi/routing/messages.go +++ b/syncapi/routing/messages.go @@ -50,9 +50,10 @@ type messagesReq struct { } type messagesResp struct { - Start string `json:"start"` - End string `json:"end"` - Chunk []gomatrixserverlib.ClientEvent `json:"chunk"` + Start string `json:"start"` + StartStream string `json:"start_stream,omitempty"` // NOTSPEC: so clients can hit /messages then immediately /sync with a latest sync token + End string `json:"end"` + Chunk []gomatrixserverlib.ClientEvent `json:"chunk"` } const defaultMessagesLimit = 10 @@ -87,7 +88,8 @@ func OnIncomingMessagesRequest( // Pagination tokens. var fromStream *types.StreamingToken fromQuery := req.URL.Query().Get("from") - if fromQuery == "" { + emptyFromSupplied := fromQuery == "" + if emptyFromSupplied { // NOTSPEC: We will pretend they used the latest sync token if no ?from= was provided. // We do this to allow clients to get messages without having to call `/sync` e.g Cerulean currPos := srp.Notifier.CurrentPosition() @@ -195,14 +197,19 @@ func OnIncomingMessagesRequest( "return_end": end.String(), }).Info("Responding") + res := messagesResp{ + Chunk: clientEvents, + Start: start.String(), + End: end.String(), + } + if emptyFromSupplied { + res.StartStream = fromStream.String() + } + // Respond with the events. return util.JSONResponse{ Code: http.StatusOK, - JSON: messagesResp{ - Chunk: clientEvents, - Start: start.String(), - End: end.String(), - }, + JSON: res, } } |