From 155399a145f4a901343e64cf6a98263a922b74a4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 20 May 2022 11:55:04 +0100 Subject: Add helper function to get the current state event in the room --- synapse/storage/databases/main/state.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'synapse') 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 -- cgit 1.5.1