Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 76becac

Browse files
authored
Add start_stream to /messages (#1648)
1 parent 42e9cbf commit 76becac

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

syncapi/routing/messages.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ type messagesReq struct {
5050
}
5151

5252
type messagesResp struct {
53-
Start string `json:"start"`
54-
End string `json:"end"`
55-
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
53+
Start string `json:"start"`
54+
StartStream string `json:"start_stream,omitempty"` // NOTSPEC: so clients can hit /messages then immediately /sync with a latest sync token
55+
End string `json:"end"`
56+
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
5657
}
5758

5859
const defaultMessagesLimit = 10
@@ -87,7 +88,8 @@ func OnIncomingMessagesRequest(
8788
// Pagination tokens.
8889
var fromStream *types.StreamingToken
8990
fromQuery := req.URL.Query().Get("from")
90-
if fromQuery == "" {
91+
emptyFromSupplied := fromQuery == ""
92+
if emptyFromSupplied {
9193
// NOTSPEC: We will pretend they used the latest sync token if no ?from= was provided.
9294
// We do this to allow clients to get messages without having to call `/sync` e.g Cerulean
9395
currPos := srp.Notifier.CurrentPosition()
@@ -195,14 +197,19 @@ func OnIncomingMessagesRequest(
195197
"return_end": end.String(),
196198
}).Info("Responding")
197199

200+
res := messagesResp{
201+
Chunk: clientEvents,
202+
Start: start.String(),
203+
End: end.String(),
204+
}
205+
if emptyFromSupplied {
206+
res.StartStream = fromStream.String()
207+
}
208+
198209
// Respond with the events.
199210
return util.JSONResponse{
200211
Code: http.StatusOK,
201-
JSON: messagesResp{
202-
Chunk: clientEvents,
203-
Start: start.String(),
204-
End: end.String(),
205-
},
212+
JSON: res,
206213
}
207214
}
208215

0 commit comments

Comments
 (0)