synapse.state module¶
-
class
synapse.state.
KeyStateTuple
(context, type, state_key)¶ Bases:
tuple
-
property
context
¶ Alias for field number 0
-
property
state_key
¶ Alias for field number 2
-
property
type
¶ Alias for field number 1
-
property
-
class
synapse.state.
StateHandler
(hs)¶ Bases:
object
Fetches bits of state from the stores, and does state resolution where necessary
-
compute_event_context
(event: synapse.events.EventBase, old_state: Optional[Iterable[synapse.events.EventBase]] = None)¶ Build an EventContext structure for the event.
This works out what the current state should be for the event, and generates a new state group if necessary.
- Parameters
event –
old_state – The state at the event if it can’t be calculated from existing events. This is normally only specified when receiving an event from federation where we don’t have the prev events for, e.g. when backfilling.
- Returns
- Return type
synapse.events.snapshot.EventContext
-
get_current_hosts_in_room
(room_id)¶
-
get_current_state
(room_id, event_type=None, state_key='', latest_event_ids=None)¶ Retrieves the current state for the room. This is done by calling get_latest_events_in_room to get the leading edges of the event graph and then resolving any of the state conflicts.
This is equivalent to getting the state of an event that were to send next before receiving any new events.
If event_type is specified, then the method returns only the one event (or None) with that event_type and state_key.
- Returns
map from (type, state_key) to event
-
get_current_state_ids
(room_id, latest_event_ids=None)¶ Get the current state, or the state at a set of events, for a room
-
get_current_users_in_room
(room_id, latest_event_ids=None)¶ Get the users who are currently in a room.
-
get_hosts_in_room_at_events
(room_id, event_ids)¶ Get the hosts that were in a room at the given event ids
-
resolve_events
(room_version, state_sets, event)¶
-
resolve_state_groups_for_events
(room_id, event_ids)¶ Given a list of event_ids this method fetches the state at each event, resolves conflicts between them and returns them.
-
-
class
synapse.state.
StateResolutionHandler
(hs)¶ Bases:
object
Responsible for doing state conflict resolution.
Note that the storage layer depends on this handler, so all functions must be storage-independent.
-
resolve_state_groups
(room_id, room_version, state_groups_ids, event_map, state_res_store)¶ Resolves conflicts between a set of state groups
Always generates a new state group (unless we hit the cache), so should not be called for a single state group
- Parameters
room_id (str) – room we are resolving for (used for logging and sanity checks)
room_version (str) – version of the room
state_groups_ids (dict[int, dict[(str, str), str]]) – map from state group id to the state in that state group (where ‘state’ is a map from state key to event id)
event_map (dict[str,FrozenEvent]|None) –
a dict from event_id to event, for any events that we happen to have in flight (eg, those currently being persisted). This will be used as a starting point fof finding the state we need; any missing events will be requested via state_res_store.
If None, all events will be fetched via state_res_store.
state_res_store (StateResolutionStore) –
- Returns
resolved state
- Return type
Deferred[_StateCacheEntry]
-
-
class
synapse.state.
StateResolutionStore
(store)¶ Bases:
object
Interface that allows state resolution algorithms to access the database in well defined way.
- Parameters
store (DataStore) –
-
get_auth_chain
(event_ids)¶ Gets the full auth chain for a set of events (including rejected events).
Includes the given event IDs in the result.
- Note that:
All events must be state events.
For v1 rooms this may not have the full auth chain in the presence of rejected events
-
synapse.state.
resolve_events_with_store
(room_id: str, room_version: str, state_sets: List[Dict[Tuple[str, str], str]], event_map: Optional[Dict[str, synapse.events.EventBase]], state_res_store: synapse.state.StateResolutionStore)¶ - Parameters
room_id – the room we are working in
room_version – Version of the room
state_sets – List of dicts of (type, state_key) -> event_id, which are the different state groups to resolve.
event_map –
a dict from event_id to event, for any events that we happen to have in flight (eg, those currently being persisted). This will be used as a starting point fof finding the state we need; any missing events will be requested via state_map_factory.
If None, all events will be fetched via state_res_store.
state_res_store – a place to fetch events from
- Returns
a map from (type, state_key) to event_id.
- Return type