Review comments

This commit is contained in:
Kegan Dougal 2023-11-06 12:33:30 +00:00
parent 7e06813fe2
commit 6f2a00a2ce
2 changed files with 8 additions and 5 deletions

View File

@ -7,6 +7,8 @@ import (
"os" "os"
"strings" "strings"
"golang.org/x/exp/slices"
"github.com/matrix-org/sliding-sync/sync2" "github.com/matrix-org/sliding-sync/sync2"
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
@ -716,17 +718,18 @@ func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64,
if err != nil { if err != nil {
return fmt.Errorf("room %s failed to SelectEventsBetween: %s", roomID, err) 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 { for _, ev := range events {
if latestEventNID == 0 { // set first time and never again if latestEventNID == 0 { // set first time and never again
latestEventNID = ev.NID latestEventNID = ev.NID
} }
roomEvents = append([]json.RawMessage{ev.JSON}, roomEvents...) roomEvents = append(roomEvents, ev.JSON)
earliestEventNID = ev.NID earliestEventNID = ev.NID
if len(roomEvents) >= limit { if len(roomEvents) >= limit {
break break
} }
} }
// we want the most recent event to be last, so reverse the slice now in-place.
slices.Reverse(roomEvents)
latestEvents := LatestEvents{ latestEvents := LatestEvents{
LatestNID: latestEventNID, LatestNID: latestEventNID,
Timeline: roomEvents, 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. // 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 // It accepts a nid range [from, to]. For each given room, it calculates the NID range
// [A1, B1], [A2, B2], ... within [from, to] in which the user has permission to see events. // [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) { 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) // load *THESE* joined rooms for this user at from (inclusive)
var membershipEvents []Event var membershipEvents []Event

View File

@ -11,7 +11,7 @@ import (
) )
// Regression test to make sure that given: // Regression test to make sure that given:
// - Alice invite Bob // - Alice invite Bob (shared history visibility)
// - Alice send message // - Alice send message
// - Bob join room // - Bob join room
// The proxy returns: // The proxy returns: