def persist(self, sender=USER_ID, room_id=ROOM_ID, type={}, key=None, internal={}, state=None, reset_state=False, backfill=False, depth=None, prev_events=[], auth_events=[], prev_state=[], redacts=None, push_actions=[], **content): """ Returns: synapse.events.FrozenEvent: The event that was persisted. """ if depth is None: depth = self.event_id event_dict = { "sender": sender, "type": type, "content": content, "event_id": "$%d:blue" % (self.event_id, ), "room_id": room_id, "depth": depth, "origin_server_ts": self.event_id, "prev_events": prev_events, "auth_events": auth_events, } if key is not None: event_dict["state_key"] = key event_dict["prev_state"] = prev_state if redacts is not None: event_dict["redacts"] = redacts event = FrozenEvent(event_dict, internal_metadata_dict=internal) self.event_id += 1 context = EventContext(current_state=state) context.push_actions = push_actions ordering = None if backfill: yield self.master_store.persist_events([(event, context)], backfilled=True) else: ordering, _ = yield self.master_store.persist_event( event, context, current_state=reset_state) if ordering: event.internal_metadata.stream_ordering = ordering defer.returnValue(event)
def persist( self, sender=USER_ID, room_id=ROOM_ID, type={}, key=None, internal={}, state=None, reset_state=False, backfill=False, depth=None, prev_events=[], auth_events=[], prev_state=[], redacts=None, push_actions=[], **content ): """ Returns: synapse.events.FrozenEvent: The event that was persisted. """ if depth is None: depth = self.event_id event_dict = { "sender": sender, "type": type, "content": content, "event_id": "$%d:blue" % (self.event_id,), "room_id": room_id, "depth": depth, "origin_server_ts": self.event_id, "prev_events": prev_events, "auth_events": auth_events, } if key is not None: event_dict["state_key"] = key event_dict["prev_state"] = prev_state if redacts is not None: event_dict["redacts"] = redacts event = FrozenEvent(event_dict, internal_metadata_dict=internal) self.event_id += 1 context = EventContext(current_state=state) context.push_actions = push_actions ordering = None if backfill: yield self.master_store.persist_events( [(event, context)], backfilled=True ) else: ordering, _ = yield self.master_store.persist_event( event, context, current_state=reset_state ) if ordering: event.internal_metadata.stream_ordering = ordering defer.returnValue(event)
def persist( self, sender=USER_ID, room_id=ROOM_ID, type={}, key=None, internal={}, state=None, reset_state=False, backfill=False, depth=None, prev_events=[], auth_events=[], prev_state=[], redacts=None, push_actions=[], **content ): """ Returns: synapse.events.FrozenEvent: The event that was persisted. """ if depth is None: depth = self.event_id if not prev_events: latest_event_ids = yield self.master_store.get_latest_event_ids_in_room( room_id ) prev_events = [(ev_id, {}) for ev_id in latest_event_ids] event_dict = { "sender": sender, "type": type, "content": content, "event_id": "$%d:blue" % (self.event_id,), "room_id": room_id, "depth": depth, "origin_server_ts": self.event_id, "prev_events": prev_events, "auth_events": auth_events, } if key is not None: event_dict["state_key"] = key event_dict["prev_state"] = prev_state if redacts is not None: event_dict["redacts"] = redacts event = FrozenEvent(event_dict, internal_metadata_dict=internal) self.event_id += 1 if state is not None: state_ids = { key: e.event_id for key, e in state.items() } context = EventContext() context.current_state_ids = state_ids context.prev_state_ids = state_ids elif not backfill: state_handler = self.hs.get_state_handler() context = yield state_handler.compute_event_context(event) else: context = EventContext() context.push_actions = push_actions ordering = None if backfill: yield self.master_store.persist_events( [(event, context)], backfilled=True ) else: ordering, _ = yield self.master_store.persist_event( event, context, ) if ordering: event.internal_metadata.stream_ordering = ordering defer.returnValue(event)