Properly cut out join and leave events

This commit is contained in:
Eric Eastwood 2020-12-31 17:02:21 -06:00
parent 810dd7842c
commit 9e4fd0157f

View file

@ -991,7 +991,7 @@ func (d *Database) getLeaveResponseForCompleteSync(
} }
break break
} else if membership == gomatrixserverlib.Leave { } else if membership == gomatrixserverlib.Leave {
leaveEventIndex = i - 1 leaveEventIndex = i
} }
if joinEventIndex != -1 && leaveEventIndex != -1 { 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) // We can assume that if the person joined, they also left and will only show the events between (inclusive)
if joinEventIndex != -1 && leaveEventIndex != -1 { if joinEventIndex != -1 && leaveEventIndex != -1 {
// cut all events earlier than the join (but not the join itself) // cut all events earlier the join (exclude the join itself too)
// and cut all events after the person left // and cut all events after the person left (exclude the leave itself too)
recentStreamEvents = recentStreamEvents[joinEventIndex:leaveEventIndex] recentStreamEvents = recentStreamEvents[joinEventIndex+1 : leaveEventIndex]
limited = false // so clients know not to try to backpaginate limited = false // so clients know not to try to backpaginate
} }