mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 19:51:39 +00:00
Add start_stream to /messages (#1648)
This commit is contained in:
parent
42e9cbf342
commit
76becac003
@ -51,6 +51,7 @@ type messagesReq struct {
|
|||||||
|
|
||||||
type messagesResp struct {
|
type messagesResp struct {
|
||||||
Start string `json:"start"`
|
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"`
|
End string `json:"end"`
|
||||||
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
|
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
|
||||||
}
|
}
|
||||||
@ -87,7 +88,8 @@ func OnIncomingMessagesRequest(
|
|||||||
// Pagination tokens.
|
// Pagination tokens.
|
||||||
var fromStream *types.StreamingToken
|
var fromStream *types.StreamingToken
|
||||||
fromQuery := req.URL.Query().Get("from")
|
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.
|
// 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
|
// We do this to allow clients to get messages without having to call `/sync` e.g Cerulean
|
||||||
currPos := srp.Notifier.CurrentPosition()
|
currPos := srp.Notifier.CurrentPosition()
|
||||||
@ -195,14 +197,19 @@ func OnIncomingMessagesRequest(
|
|||||||
"return_end": end.String(),
|
"return_end": end.String(),
|
||||||
}).Info("Responding")
|
}).Info("Responding")
|
||||||
|
|
||||||
// Respond with the events.
|
res := messagesResp{
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: messagesResp{
|
|
||||||
Chunk: clientEvents,
|
Chunk: clientEvents,
|
||||||
Start: start.String(),
|
Start: start.String(),
|
||||||
End: end.String(),
|
End: end.String(),
|
||||||
},
|
}
|
||||||
|
if emptyFromSupplied {
|
||||||
|
res.StartStream = fromStream.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Respond with the events.
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: res,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user