mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Refactor do_invite_join
This commit is contained in:
parent
eb700cdc38
commit
4678055173
@ -649,35 +649,10 @@ class FederationHandler(BaseHandler):
|
|||||||
# FIXME
|
# FIXME
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ev_infos = []
|
self._check_auth_tree(auth_chain, event)
|
||||||
for e in itertools.chain(state, auth_chain):
|
|
||||||
if e.event_id == event.event_id:
|
|
||||||
continue
|
|
||||||
|
|
||||||
e.internal_metadata.outlier = True
|
event_stream_id, max_stream_id = yield self._persist_auth_tree(
|
||||||
auth_ids = [e_id for e_id, _ in e.auth_events]
|
auth_chain, state, event
|
||||||
ev_infos.append({
|
|
||||||
"event": e,
|
|
||||||
"auth_events": {
|
|
||||||
(e.type, e.state_key): e for e in auth_chain
|
|
||||||
if e.event_id in auth_ids
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
yield self._handle_new_events(origin, ev_infos, outliers=True)
|
|
||||||
|
|
||||||
auth_ids = [e_id for e_id, _ in event.auth_events]
|
|
||||||
auth_events = {
|
|
||||||
(e.type, e.state_key): e for e in auth_chain
|
|
||||||
if e.event_id in auth_ids
|
|
||||||
}
|
|
||||||
|
|
||||||
_, event_stream_id, max_stream_id = yield self._handle_new_event(
|
|
||||||
origin,
|
|
||||||
new_event,
|
|
||||||
state=state,
|
|
||||||
current_state=state,
|
|
||||||
auth_events=auth_events,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with PreserveLoggingContext():
|
with PreserveLoggingContext():
|
||||||
@ -1026,6 +1001,59 @@ class FederationHandler(BaseHandler):
|
|||||||
is_new_state=(not outliers and not backfilled),
|
is_new_state=(not outliers and not backfilled),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _check_auth_tree(self, auth_events, event):
|
||||||
|
event_map = {
|
||||||
|
e.event_id: e
|
||||||
|
for e in auth_events
|
||||||
|
}
|
||||||
|
|
||||||
|
create_event = None
|
||||||
|
for e in auth_events:
|
||||||
|
if (e.type, e.state_key) == (EventTypes.Create, ""):
|
||||||
|
create_event = e
|
||||||
|
break
|
||||||
|
|
||||||
|
for e in auth_events + [event]:
|
||||||
|
a = {
|
||||||
|
(event_map[e_id].type, event_map[e_id].state_key): event_map[e_id]
|
||||||
|
for e_id, _ in e.auth_events
|
||||||
|
}
|
||||||
|
if create_event:
|
||||||
|
a[(EventTypes.Create, "")] = create_event
|
||||||
|
|
||||||
|
self.auth.check(e, auth_events=a)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def _persist_auth_tree(self, auth_events, state, event):
|
||||||
|
events_to_context = {}
|
||||||
|
for e in auth_events:
|
||||||
|
ctx = yield self.state_handler.compute_event_context(
|
||||||
|
e, outlier=True,
|
||||||
|
)
|
||||||
|
events_to_context[e.event_id] = ctx
|
||||||
|
e.internal_metadata.outlier = True
|
||||||
|
|
||||||
|
yield self.store.persist_events(
|
||||||
|
[
|
||||||
|
(e, events_to_context[e.event_id])
|
||||||
|
for e in auth_events
|
||||||
|
],
|
||||||
|
is_new_state=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
new_event_context = yield self.state_handler.compute_event_context(
|
||||||
|
event, old_state=state, outlier=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
event_stream_id, max_stream_id = yield self.store.persist_event(
|
||||||
|
event, new_event_context,
|
||||||
|
backfilled=False,
|
||||||
|
is_new_state=True,
|
||||||
|
current_state=state,
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue((event_stream_id, max_stream_id))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _prep_event(self, origin, event, state=None, backfilled=False,
|
def _prep_event(self, origin, event, state=None, backfilled=False,
|
||||||
current_state=None, auth_events=None):
|
current_state=None, auth_events=None):
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
from synapse.util.async import run_on_reactor
|
|
||||||
from synapse.util.caches.expiringcache import ExpiringCache
|
from synapse.util.caches.expiringcache import ExpiringCache
|
||||||
from synapse.api.constants import EventTypes
|
from synapse.api.constants import EventTypes
|
||||||
from synapse.api.errors import AuthError
|
from synapse.api.errors import AuthError
|
||||||
@ -119,8 +118,6 @@ class StateHandler(object):
|
|||||||
Returns:
|
Returns:
|
||||||
an EventContext
|
an EventContext
|
||||||
"""
|
"""
|
||||||
yield run_on_reactor()
|
|
||||||
|
|
||||||
context = EventContext()
|
context = EventContext()
|
||||||
|
|
||||||
if outlier:
|
if outlier:
|
||||||
|
Loading…
Reference in New Issue
Block a user