Skip to content

Commit

Permalink
Ask InternalRequestLists if room is Visible
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Jul 25, 2023
1 parent 5cf4413 commit ad3a7ca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sync3/handler/connstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,15 @@ func (s *ConnState) OnRoomUpdate(ctx context.Context, up caches.RoomUpdate) {
}
}

func (s *ConnState) subscribedOrVisible(roomID string) bool {
_, subscribed := s.roomSubscriptions[roomID]
if subscribed {
return true
}

return s.lists.Visible(roomID, s.muxedReq.Lists)
}

// clampSliceRangeToListSize helps us to send client-friendly SYNC and INVALIDATE ranges.
//
// Suppose the client asks for a window on positions [10, 19]. If the list
Expand Down
28 changes: 28 additions & 0 deletions sync3/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,34 @@ func (s *InternalRequestLists) ListsByVisibleRoomIDs(muxedReqLists map[string]Re
return listsByRoomIDs
}

// Visible determines if a single room is currently visible in the given set of lists.
func (s *InternalRequestLists) Visible(roomID string, muxedReqLists map[string]RequestList) bool {
for listKey, reqList := range muxedReqLists {
sortedRooms := s.lists[listKey].SortableRooms
if sortedRooms == nil {
continue
}

var ranges SliceRanges
if reqList.SlowGetAllRooms != nil && *reqList.SlowGetAllRooms {
ranges = SliceRanges{{0, sortedRooms.Len() - 1}}
} else {
ranges = reqList.Ranges
}

subslices := ranges.SliceInto(sortedRooms)
for _, subslice := range subslices {
sortedSubslice := subslice.(*SortableRooms)
for _, otherRoomID := range sortedSubslice.RoomIDs() {
if roomID == otherRoomID {
return true
}
}
}
}
return false
}

// Assign a new list at the given key. If Overwrite, any existing list is replaced. If DoNotOverwrite, the existing
// list is returned if one exists, else a new list is created. Returns the list and true if the list was overwritten.
func (s *InternalRequestLists) AssignList(ctx context.Context, listKey string, filters *RequestFilters, sort []string, shouldOverwrite OverwriteVal) (*FilteredSortableRooms, bool) {
Expand Down

0 comments on commit ad3a7ca

Please sign in to comment.