mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 08:13:09 -06:00
Add exclude_rooms impl
This commit is contained in:
parent
9988a750b8
commit
cb5c62e5e5
|
|
@ -143,6 +143,15 @@ type walker struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *walker) roomIsExcluded(roomID string) bool {
|
||||||
|
for _, exclRoom := range w.req.ExcludeRooms {
|
||||||
|
if exclRoom == roomID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (w *walker) alreadySent(id string) bool {
|
func (w *walker) alreadySent(id string) bool {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
|
|
@ -195,7 +204,7 @@ func (w *walker) walk() *gomatrixserverlib.MSC2946SpacesResponse {
|
||||||
|
|
||||||
// If this room has not ever been in `rooms` (across multiple requests), extract the
|
// If this room has not ever been in `rooms` (across multiple requests), extract the
|
||||||
// `PublicRoomsChunk` for this room.
|
// `PublicRoomsChunk` for this room.
|
||||||
if !w.alreadySent(roomID) {
|
if !w.alreadySent(roomID) && !w.roomIsExcluded(roomID) {
|
||||||
pubRoom := w.publicRoomsChunk(roomID)
|
pubRoom := w.publicRoomsChunk(roomID)
|
||||||
roomType := ""
|
roomType := ""
|
||||||
create := w.stateEvent(roomID, gomatrixserverlib.MRoomCreate, "")
|
create := w.stateEvent(roomID, gomatrixserverlib.MRoomCreate, "")
|
||||||
|
|
@ -209,6 +218,7 @@ func (w *walker) walk() *gomatrixserverlib.MSC2946SpacesResponse {
|
||||||
NumRefs: refs.len(),
|
NumRefs: refs.len(),
|
||||||
RoomType: roomType,
|
RoomType: roomType,
|
||||||
})
|
})
|
||||||
|
w.markSent(roomID)
|
||||||
}
|
}
|
||||||
|
|
||||||
uniqueRooms := make(set)
|
uniqueRooms := make(set)
|
||||||
|
|
@ -239,6 +249,11 @@ func (w *walker) walk() *gomatrixserverlib.MSC2946SpacesResponse {
|
||||||
if w.alreadySent(ev.EventID()) {
|
if w.alreadySent(ev.EventID()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Skip the room if it's part of exclude_rooms but ONLY IF the source matches, as we still
|
||||||
|
// want to catch arrows which point to excluded rooms.
|
||||||
|
if w.roomIsExcluded(ev.RoomID()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
res.Events = append(res.Events, ev.Event)
|
res.Events = append(res.Events, ev.Event)
|
||||||
uniqueRooms[ev.RoomID()] = true
|
uniqueRooms[ev.RoomID()] = true
|
||||||
uniqueRooms[SpaceTarget(ev)] = true
|
uniqueRooms[SpaceTarget(ev)] = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue