Skip to content

Commit

Permalink
add ability to filter by state event type to admin state endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Dec 16, 2024
1 parent 29d5863 commit e96111f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ The API is:
GET /_synapse/admin/v1/rooms/<room_id>/state
```

**Parameters**

The following query parameter is available:

* `type` - The type of room state event to filter by, eg "m.room.create". If provided, only state events
of this type will be returned.

A response body like the following is returned:

```json
Expand Down
19 changes: 18 additions & 1 deletion synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import TYPE_CHECKING, List, Optional, Tuple, cast

import attr
from immutabledict import immutabledict

from synapse.api.constants import Direction, EventTypes, JoinRules, Membership
from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError
Expand Down Expand Up @@ -463,7 +464,23 @@ async def on_GET(
if not room:
raise NotFoundError("Room not found")

event_ids = await self._storage_controllers.state.get_current_state_ids(room_id)
state_filter = None
type = parse_string(request, "type")

if type:
if not type.startswith("m.room."):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Type must be a room state event.",
)
state_filter = StateFilter(
types=immutabledict({type: None}),
include_others=False,
)

event_ids = await self._storage_controllers.state.get_current_state_ids(
room_id, state_filter
)
events = await self.store.get_events(event_ids.values())
now = self.clock.time_msec()
room_state = await self._event_serializer.serialize_events(events.values(), now)
Expand Down

0 comments on commit e96111f

Please sign in to comment.