From 9e4fd0157f6899dd4ff23233ef7212b3fec7c134 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 31 Dec 2020 17:02:21 -0600 Subject: [PATCH] Properly cut out join and leave events --- syncapi/storage/shared/syncserver.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 0f8e09cd..156ada92 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -991,7 +991,7 @@ func (d *Database) getLeaveResponseForCompleteSync( } break } else if membership == gomatrixserverlib.Leave { - leaveEventIndex = i - 1 + leaveEventIndex = i } if joinEventIndex != -1 && leaveEventIndex != -1 { @@ -999,11 +999,12 @@ func (d *Database) getLeaveResponseForCompleteSync( } } } + // We can assume that if the person joined, they also left and will only show the events between (inclusive) if joinEventIndex != -1 && leaveEventIndex != -1 { - // cut all events earlier than the join (but not the join itself) - // and cut all events after the person left - recentStreamEvents = recentStreamEvents[joinEventIndex:leaveEventIndex] + // cut all events earlier the join (exclude the join itself too) + // and cut all events after the person left (exclude the leave itself too) + recentStreamEvents = recentStreamEvents[joinEventIndex+1 : leaveEventIndex] limited = false // so clients know not to try to backpaginate }