From 6f2a00a2ce937c25f3448e40636d2f0fee4b2ac1 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 6 Nov 2023 12:33:30 +0000 Subject: [PATCH] Review comments --- state/storage.go | 11 +++++++---- tests-e2e/timeline_test.go | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/state/storage.go b/state/storage.go index a97cd3c..76b0825 100644 --- a/state/storage.go +++ b/state/storage.go @@ -7,6 +7,8 @@ import ( "os" "strings" + "golang.org/x/exp/slices" + "github.com/matrix-org/sliding-sync/sync2" "github.com/getsentry/sentry-go" @@ -716,17 +718,18 @@ func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64, if err != nil { return fmt.Errorf("room %s failed to SelectEventsBetween: %s", roomID, err) } - // keep pushing to the front so we end up with A,B,C for _, ev := range events { if latestEventNID == 0 { // set first time and never again latestEventNID = ev.NID } - roomEvents = append([]json.RawMessage{ev.JSON}, roomEvents...) + roomEvents = append(roomEvents, ev.JSON) earliestEventNID = ev.NID if len(roomEvents) >= limit { break } } + // we want the most recent event to be last, so reverse the slice now in-place. + slices.Reverse(roomEvents) latestEvents := LatestEvents{ LatestNID: latestEventNID, Timeline: roomEvents, @@ -747,8 +750,8 @@ func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64, } // visibleEventNIDsBetweenForRooms determines which events a given user has permission to see. -// It accepts a nid range [from, to]. For each given room, it calculates the NID ranges -// [A1, B1], [A2, B2], ... within [from, to] in which the user has permission to see events. +// It accepts a nid range [from, to]. For each given room, it calculates the NID range +// [A1, B1] within [from, to] in which the user has permission to see events. func (s *Storage) visibleEventNIDsBetweenForRooms(userID string, roomIDs []string, from, to int64) (map[string][2]int64, error) { // load *THESE* joined rooms for this user at from (inclusive) var membershipEvents []Event diff --git a/tests-e2e/timeline_test.go b/tests-e2e/timeline_test.go index 6eb973b..0a8f9c4 100644 --- a/tests-e2e/timeline_test.go +++ b/tests-e2e/timeline_test.go @@ -11,7 +11,7 @@ import ( ) // Regression test to make sure that given: -// - Alice invite Bob +// - Alice invite Bob (shared history visibility) // - Alice send message // - Bob join room // The proxy returns: