diff options
author | Erik Johnston <erik@matrix.org> | 2022-05-20 11:55:04 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2022-05-20 12:03:40 +0100 |
commit | 155399a145f4a901343e64cf6a98263a922b74a4 (patch) | |
tree | ea4a7272c4b5fdff26ec2ba093303361783c289f | |
parent | Update EventContext `get_current_event_ids` and `get_prev_event_ids` to accep... (diff) | |
download | synapse-155399a145f4a901343e64cf6a98263a922b74a4.tar.xz |
Add helper function to get the current state event in the room
-rw-r--r-- | synapse/storage/databases/main/state.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/state.py b/synapse/storage/databases/main/state.py index 18ae8aee29..c81fadbe9e 100644 --- a/synapse/storage/databases/main/state.py +++ b/synapse/storage/databases/main/state.py @@ -269,6 +269,23 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore): "get_filtered_current_state_ids", _get_filtered_current_state_ids_txn ) + async def get_current_state_event( + self, room_id: str, event_type: str, state_key: str + ) -> Optional[EventBase]: + """Get the current state event for the given type/state_key.""" + + key = (event_type, state_key) + state_map = await self.get_filtered_current_state_ids( + room_id, StateFilter.from_types((key,)) + ) + event_id = state_map.get(key) + + event = None + if event_id: + event = await self.get_event(event_id, allow_none=True) + + return event + async def get_canonical_alias_for_room(self, room_id: str) -> Optional[str]: """Get canonical alias for room, if any |