aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authordevonh <devon.dmytro@gmail.com>2024-01-09 19:06:02 +0000
committerGitHub <noreply@github.com>2024-01-09 19:06:02 +0000
commit57646d5b86a929469f8ada9b9168fc19e09d9f2e (patch)
tree3dcb397d935c6b14a6fe8f447fb5a99c0184ac9a /syncapi
parent9510fa00cce80882d7a59e036eb87646e279ac41 (diff)
Handle empty from in /messages as per MSC3567 (#3298)
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/routing/messages.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go
index 3333cb54..7ea01c7d 100644
--- a/syncapi/routing/messages.go
+++ b/syncapi/routing/messages.go
@@ -135,13 +135,6 @@ func OnIncomingMessagesRequest(
var fromStream *types.StreamingToken
fromQuery := req.URL.Query().Get("from")
toQuery := req.URL.Query().Get("to")
- 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()
- fromQuery = currPos.String()
- }
// Direction to return events from.
dir := req.URL.Query().Get("dir")
@@ -155,6 +148,23 @@ func OnIncomingMessagesRequest(
// to have one of the two accepted values (so dir == "f" <=> !backwardOrdering).
backwardOrdering := (dir == "b")
+ emptyFromSupplied := fromQuery == ""
+ if emptyFromSupplied {
+ // If "from" isn't provided, it defaults to either the earliest stream
+ // position (if we're going forward) or to the latest one (if we're
+ // going backward).
+
+ var from types.TopologyToken
+ if backwardOrdering {
+ from = types.TopologyToken{Depth: math.MaxInt64, PDUPosition: math.MaxInt64}
+ } else {
+ // go 1 earlier than the first event so we correctly fetch the earliest event
+ // this is because Database.GetEventsInTopologicalRange is exclusive of the lower-bound.
+ from = types.TopologyToken{}
+ }
+ fromQuery = from.String()
+ }
+
from, err := types.NewTopologyTokenFromString(fromQuery)
if err != nil {
var streamToken types.StreamingToken