mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Implement invite part of invite join dance
This commit is contained in:
parent
328dab2463
commit
d2fb2b8095
@ -413,7 +413,7 @@ class ReplicationLayer(object):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_invite_request(self, origin, content):
|
def on_invite_request(self, origin, content):
|
||||||
pdu = Pdu(**content)
|
pdu = Pdu(**content)
|
||||||
ret_pdu = yield self.handler.on_send_join_request(origin, pdu)
|
ret_pdu = yield self.handler.on_invite_request(origin, pdu)
|
||||||
defer.returnValue((200, ret_pdu.get_dict()))
|
defer.returnValue((200, ret_pdu.get_dict()))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@ -460,6 +460,19 @@ class ReplicationLayer(object):
|
|||||||
|
|
||||||
defer.returnValue(state)
|
defer.returnValue(state)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def send_invite(self, destination, context, event_id, pdu):
|
||||||
|
code, pdu_dict = yield self.transport_layer.send_invite(
|
||||||
|
destination=destination,
|
||||||
|
context=context,
|
||||||
|
event_id=event_id,
|
||||||
|
content=pdu.get_dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug("Got response to send_invite: %s", pdu_dict)
|
||||||
|
|
||||||
|
defer.returnValue(Pdu(**pdu_dict))
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def _get_persisted_pdu(self, event_id):
|
def _get_persisted_pdu(self, event_id):
|
||||||
""" Get a PDU from the database with given origin and id.
|
""" Get a PDU from the database with given origin and id.
|
||||||
|
@ -56,7 +56,8 @@ class BaseHandler(object):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _on_new_room_event(self, event, snapshot, extra_destinations=[],
|
def _on_new_room_event(self, event, snapshot, extra_destinations=[],
|
||||||
extra_users=[], suppress_auth=False):
|
extra_users=[], suppress_auth=False,
|
||||||
|
do_invite_host=None):
|
||||||
yield run_on_reactor()
|
yield run_on_reactor()
|
||||||
|
|
||||||
snapshot.fill_out_prev_events(event)
|
snapshot.fill_out_prev_events(event)
|
||||||
@ -80,6 +81,16 @@ class BaseHandler(object):
|
|||||||
else:
|
else:
|
||||||
logger.debug("Suppressed auth.")
|
logger.debug("Suppressed auth.")
|
||||||
|
|
||||||
|
if do_invite_host:
|
||||||
|
federation_handler = self.hs.get_handlers().federation_handler
|
||||||
|
invite_event = yield federation_handler.send_invite(
|
||||||
|
do_invite_host,
|
||||||
|
event
|
||||||
|
)
|
||||||
|
|
||||||
|
# FIXME: We need to check if the remote changed anything else
|
||||||
|
event.signatures = invite_event.signatures
|
||||||
|
|
||||||
yield self.store.persist_event(event)
|
yield self.store.persist_event(event)
|
||||||
|
|
||||||
destinations = set(extra_destinations)
|
destinations = set(extra_destinations)
|
||||||
|
@ -23,6 +23,7 @@ from synapse.api.constants import Membership
|
|||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
from synapse.federation.pdu_codec import PduCodec
|
from synapse.federation.pdu_codec import PduCodec
|
||||||
from synapse.util.async import run_on_reactor
|
from synapse.util.async import run_on_reactor
|
||||||
|
from synapse.crypto.event_signing import compute_event_signature
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
@ -212,6 +213,17 @@ class FederationHandler(BaseHandler):
|
|||||||
|
|
||||||
defer.returnValue(events)
|
defer.returnValue(events)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def send_invite(self, target_host, event):
|
||||||
|
pdu = yield self.replication_layer.send_invite(
|
||||||
|
destination=target_host,
|
||||||
|
context=event.room_id,
|
||||||
|
event_id=event.event_id,
|
||||||
|
pdu=self.pdu_codec.pdu_from_event(event)
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue(self.pdu_codec.event_from_pdu(pdu))
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def do_invite_join(self, target_host, room_id, joinee, content, snapshot):
|
def do_invite_join(self, target_host, room_id, joinee, content, snapshot):
|
||||||
@ -380,6 +392,31 @@ class FederationHandler(BaseHandler):
|
|||||||
"auth_chain": pdu_auth_chain,
|
"auth_chain": pdu_auth_chain,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def on_invite_request(self, origin, pdu):
|
||||||
|
event = self.pdu_codec.event_from_pdu(pdu)
|
||||||
|
|
||||||
|
event.outlier = True
|
||||||
|
|
||||||
|
event.signatures.update(
|
||||||
|
compute_event_signature(
|
||||||
|
event,
|
||||||
|
self.hs.hostname,
|
||||||
|
self.hs.config.signing_key[0]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
yield self.state_handler.annotate_state_groups(event)
|
||||||
|
|
||||||
|
yield self.store.persist_event(
|
||||||
|
event,
|
||||||
|
backfilled=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield self.notifier.on_new_room_event(event)
|
||||||
|
|
||||||
|
defer.returnValue(self.pdu_codec.pdu_from_event(event))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_state_for_pdu(self, event_id):
|
def get_state_for_pdu(self, event_id):
|
||||||
yield run_on_reactor()
|
yield run_on_reactor()
|
||||||
|
@ -361,13 +361,6 @@ class RoomMemberHandler(BaseHandler):
|
|||||||
if prev_state:
|
if prev_state:
|
||||||
event.content["prev"] = prev_state.membership
|
event.content["prev"] = prev_state.membership
|
||||||
|
|
||||||
# if prev_state and prev_state.membership == event.membership:
|
|
||||||
# # treat this event as a NOOP.
|
|
||||||
# if do_auth: # This is mainly to fix a unit test.
|
|
||||||
# yield self.auth.check(event, raises=True)
|
|
||||||
# defer.returnValue({})
|
|
||||||
# return
|
|
||||||
|
|
||||||
room_id = event.room_id
|
room_id = event.room_id
|
||||||
|
|
||||||
# If we're trying to join a room then we have to do this differently
|
# If we're trying to join a room then we have to do this differently
|
||||||
@ -521,25 +514,24 @@ class RoomMemberHandler(BaseHandler):
|
|||||||
|
|
||||||
defer.returnValue([r.room_id for r in rooms])
|
defer.returnValue([r.room_id for r in rooms])
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def _do_local_membership_update(self, event, membership, snapshot,
|
def _do_local_membership_update(self, event, membership, snapshot,
|
||||||
do_auth):
|
do_auth):
|
||||||
destinations = []
|
|
||||||
|
|
||||||
# If we're inviting someone, then we should also send it to that
|
# If we're inviting someone, then we should also send it to that
|
||||||
# HS.
|
# HS.
|
||||||
target_user_id = event.state_key
|
target_user_id = event.state_key
|
||||||
target_user = self.hs.parse_userid(target_user_id)
|
target_user = self.hs.parse_userid(target_user_id)
|
||||||
if membership == Membership.INVITE:
|
if membership == Membership.INVITE and not target_user.is_mine:
|
||||||
host = target_user.domain
|
do_invite_host = target_user.domain
|
||||||
destinations.append(host)
|
else:
|
||||||
|
do_invite_host = None
|
||||||
|
|
||||||
# Always include target domain
|
yield self._on_new_room_event(
|
||||||
host = target_user.domain
|
event,
|
||||||
destinations.append(host)
|
snapshot,
|
||||||
|
extra_users=[target_user],
|
||||||
return self._on_new_room_event(
|
suppress_auth=(not do_auth),
|
||||||
event, snapshot, extra_destinations=destinations,
|
do_invite_host=do_invite_host,
|
||||||
extra_users=[target_user], suppress_auth=(not do_auth),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user