def compute_event_context(self, event, old_state=None): """ Fills out the context with the `current state` of the graph. The `current state` here is defined to be the state of the event graph just before the event - i.e. it never includes `event` If `event` has `auth_events` then this will also fill out the `auth_events` field on `context` from the `current_state`. Args: event (EventBase) Returns: an EventContext """ context = EventContext() yield run_on_reactor() if old_state: context.current_state = {(s.type, s.state_key): s for s in old_state} context.state_group = None if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] if replaces.event_id != event.event_id: # Paranoia check event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = [] defer.returnValue(context) if event.is_state(): ret = yield self.resolve_state_groups( [e for e, _ in event.prev_events], event_type=event.type, state_key=event.state_key, ) else: ret = yield self.resolve_state_groups( [e for e, _ in event.prev_events], ) group, curr_state, prev_state = ret context.current_state = curr_state context.state_group = group if not event.is_state() else None prev_state = yield self.store.add_event_hashes(prev_state) if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = prev_state defer.returnValue(context)
def compute_event_context(self, event, old_state=None): """ Fills out the context with the `current state` of the graph. The `current state` here is defined to be the state of the event graph just before the event - i.e. it never includes `event` If `event` has `auth_events` then this will also fill out the `auth_events` field on `context` from the `current_state`. Args: event (EventBase) Returns: an EventContext """ context = EventContext() yield run_on_reactor() if old_state: context.current_state = { (s.type, s.state_key): s for s in old_state } context.state_group = None if hasattr(event, "auth_events") and event.auth_events: auth_ids = zip(*event.auth_events)[0] context.auth_events = { k: v for k, v in context.current_state.items() if v.event_id in auth_ids } else: context.auth_events = {} if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] if replaces.event_id != event.event_id: # Paranoia check event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = [] defer.returnValue(context) if event.is_state(): ret = yield self.resolve_state_groups( [e for e, _ in event.prev_events], event_type=event.type, state_key=event.state_key, ) else: ret = yield self.resolve_state_groups( [e for e, _ in event.prev_events], ) group, curr_state, prev_state = ret context.current_state = curr_state context.state_group = group if not event.is_state() else None prev_state = yield self.store.add_event_hashes( prev_state ) if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] event.unsigned["replaces_state"] = replaces.event_id if hasattr(event, "auth_events") and event.auth_events: auth_ids = zip(*event.auth_events)[0] context.auth_events = { k: v for k, v in context.current_state.items() if v.event_id in auth_ids } else: context.auth_events = {} context.prev_state_events = prev_state defer.returnValue(context)
def compute_event_context(self, event, old_state=None, outlier=False): """ Fills out the context with the `current state` of the graph. The `current state` here is defined to be the state of the event graph just before the event - i.e. it never includes `event` If `event` has `auth_events` then this will also fill out the `auth_events` field on `context` from the `current_state`. Args: event (EventBase) Returns: an EventContext """ yield run_on_reactor() context = EventContext() if outlier: # If this is an outlier, then we know it shouldn't have any current # state. Certainly store.get_current_state won't return any, and # persisting the event won't store the state group. if old_state: context.current_state = {(s.type, s.state_key): s for s in old_state} else: context.current_state = {} context.prev_state_events = [] context.state_group = None defer.returnValue(context) if old_state: context.current_state = {(s.type, s.state_key): s for s in old_state} context.state_group = None if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] if replaces.event_id != event.event_id: # Paranoia check event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = [] defer.returnValue(context) if event.is_state(): ret = yield self.resolve_state_groups( [e for e, _ in event.prev_events], event_type=event.type, state_key=event.state_key, ) else: ret = yield self.resolve_state_groups( [e for e, _ in event.prev_events], ) group, curr_state, prev_state = ret context.current_state = curr_state context.state_group = group if not event.is_state() else None if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = prev_state defer.returnValue(context)
def compute_event_context(self, event, old_state=None, outlier=False): """ Fills out the context with the `current state` of the graph. The `current state` here is defined to be the state of the event graph just before the event - i.e. it never includes `event` If `event` has `auth_events` then this will also fill out the `auth_events` field on `context` from the `current_state`. Args: event (EventBase) Returns: an EventContext """ yield run_on_reactor() context = EventContext() if outlier: # If this is an outlier, then we know it shouldn't have any current # state. Certainly store.get_current_state won't return any, and # persisting the event won't store the state group. if old_state: context.current_state = { (s.type, s.state_key): s for s in old_state } else: context.current_state = {} context.prev_state_events = [] context.state_group = None defer.returnValue(context) if old_state: context.current_state = { (s.type, s.state_key): s for s in old_state } context.state_group = None if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] if replaces.event_id != event.event_id: # Paranoia check event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = [] defer.returnValue(context) if event.is_state(): ret = yield self.resolve_state_groups( event.room_id, [e for e, _ in event.prev_events], event_type=event.type, state_key=event.state_key, ) else: ret = yield self.resolve_state_groups( event.room_id, [e for e, _ in event.prev_events], ) group, curr_state, prev_state = ret context.current_state = curr_state context.state_group = group if not event.is_state() else None if event.is_state(): key = (event.type, event.state_key) if key in context.current_state: replaces = context.current_state[key] event.unsigned["replaces_state"] = replaces.event_id context.prev_state_events = prev_state defer.returnValue(context)