aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Abolivier <contact@brendanabolivier.com>2018-11-08 15:11:11 +0000
committerGitHub <noreply@github.com>2018-11-08 15:11:11 +0000
commit8b0f60a47099f9259c83410ef6729ea26811126c (patch)
tree7dab642c920343c0dde9529447cf9385e29da9b7
parent83c3c7e1db81c0e51e500d28df36a03227161a68 (diff)
Fill the prev_batch property in responses from /sync (#589)
* Fill the prev_batch property in responses from /sync * Set prev_batch to 1 (first possible value in the sequence) if it's about to hit 0
-rw-r--r--src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go
index 84417a34..ec973e2c 100644
--- a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go
+++ b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go
@@ -310,6 +310,11 @@ func (d *SyncServerDatabase) CompleteSync(
stateEvents = removeDuplicates(stateEvents, recentEvents)
jr := types.NewJoinResponse()
+ if prevBatch := recentStreamEvents[0].streamPosition - 1; prevBatch > 0 {
+ jr.Timeline.PrevBatch = types.StreamPosition(prevBatch).String()
+ } else {
+ jr.Timeline.PrevBatch = types.StreamPosition(1).String()
+ }
jr.Timeline.Events = gomatrixserverlib.ToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
jr.Timeline.Limited = true
jr.State.Events = gomatrixserverlib.ToClientEvents(stateEvents, gomatrixserverlib.FormatSync)
@@ -439,6 +444,11 @@ func (d *SyncServerDatabase) addRoomDeltaToResponse(
switch delta.membership {
case "join":
jr := types.NewJoinResponse()
+ if prevBatch := recentStreamEvents[0].streamPosition - 1; prevBatch > 0 {
+ jr.Timeline.PrevBatch = types.StreamPosition(prevBatch).String()
+ } else {
+ jr.Timeline.PrevBatch = types.StreamPosition(1).String()
+ }
jr.Timeline.Events = gomatrixserverlib.ToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
jr.Timeline.Limited = false // TODO: if len(events) >= numRecents + 1 and then set limited:true
jr.State.Events = gomatrixserverlib.ToClientEvents(delta.stateEvents, gomatrixserverlib.FormatSync)
@@ -449,6 +459,11 @@ func (d *SyncServerDatabase) addRoomDeltaToResponse(
// TODO: recentEvents may contain events that this user is not allowed to see because they are
// no longer in the room.
lr := types.NewLeaveResponse()
+ if prevBatch := recentStreamEvents[0].streamPosition - 1; prevBatch > 0 {
+ lr.Timeline.PrevBatch = types.StreamPosition(prevBatch).String()
+ } else {
+ lr.Timeline.PrevBatch = types.StreamPosition(1).String()
+ }
lr.Timeline.Events = gomatrixserverlib.ToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
lr.Timeline.Limited = false // TODO: if len(events) >= numRecents + 1 and then set limited:true
lr.State.Events = gomatrixserverlib.ToClientEvents(delta.stateEvents, gomatrixserverlib.FormatSync)