From cf6e5f1dbf3cecf693e45f293535e71ee31801ed Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 15 Dec 2014 17:01:12 +0000 Subject: [PATCH] Rename MessageHandler.handle_event. Add a few comments. --- synapse/handlers/_base.py | 5 +++++ synapse/handlers/directory.py | 2 +- synapse/handlers/message.py | 14 +++++++++++++- synapse/handlers/profile.py | 2 +- synapse/handlers/room.py | 8 ++++---- synapse/rest/room.py | 10 +++++----- tests/handlers/test_room.py | 5 +++-- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py index 14f75ecbc..af8eb5f0f 100644 --- a/synapse/handlers/_base.py +++ b/synapse/handlers/_base.py @@ -122,10 +122,15 @@ class BaseHandler(object): if event.content["membership"] == Membership.INVITE: invitee = self.hs.parse_userid(event.state_key) if not self.hs.is_mine(invitee): + # TODO: Can we add signature from remote server in a nicer + # way? If we have been invited by a remote server, we need + # to get them to sign the event. returned_invite = yield federation_handler.send_invite( invitee.domain, event, ) + + # TODO: Make sure the signatures actually are correct. event.signatures.update( returned_invite.signatures ) diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py index 76fb897f2..4b0869cd9 100644 --- a/synapse/handlers/directory.py +++ b/synapse/handlers/directory.py @@ -149,7 +149,7 @@ class DirectoryHandler(BaseHandler): aliases = yield self.store.get_aliases_for_room(room_id) msg_handler = self.hs.get_handlers().message_handler - yield msg_handler.handle_event({ + yield msg_handler.create_and_send_event({ "type": RoomAliasesEvent.TYPE, "state_key": self.hs.hostname, "room_id": room_id, diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 4fa4ffea2..1eed38c6d 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -138,7 +138,19 @@ class MessageHandler(BaseHandler): defer.returnValue(chunk) @defer.inlineCallbacks - def handle_event(self, event_dict): + def create_and_send_event(self, event_dict): + """ Given a dict from a client, create and handle a new event. + + Creates an FrozenEvent object, filling out auth_events, prev_events, + etc. + + Adds display names to Join membership events. + + Persists and notifies local clients and federation. + + Args: + event_dict (dict): An entire event + """ builder = self.event_builder_factory.new(event_dict) self.validator.validate_new(builder) diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index 18fd0914e..33a2c167e 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -209,7 +209,7 @@ class ProfileHandler(BaseHandler): ) msg_handler = self.hs.get_handlers().message_handler - yield msg_handler.handle_event({ + yield msg_handler.create_and_send_event({ "type": j.type, "room_id": j.room_id, "state_key": j.state_key, diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index d317f2b30..f7cc86922 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -126,11 +126,11 @@ class RoomCreationHandler(BaseHandler): msg_handler = self.hs.get_handlers().message_handler for event in creation_events: - yield msg_handler.handle_event(event) + yield msg_handler.create_and_send_event(event) if "name" in config: name = config["name"] - yield msg_handler.handle_event({ + yield msg_handler.create_and_send_event({ "type": RoomNameEvent.TYPE, "room_id": room_id, "sender": user_id, @@ -139,7 +139,7 @@ class RoomCreationHandler(BaseHandler): if "topic" in config: topic = config["topic"] - yield msg_handler.handle_event({ + yield msg_handler.create_and_send_event({ "type": RoomTopicEvent.TYPE, "room_id": room_id, "sender": user_id, @@ -147,7 +147,7 @@ class RoomCreationHandler(BaseHandler): }) for invitee in invite_list: - yield msg_handler.handle_event({ + yield msg_handler.create_and_send_event({ "type": RoomMemberEvent.TYPE, "state_key": invitee, "room_id": room_id, diff --git a/synapse/rest/room.py b/synapse/rest/room.py index 25ee96455..1a527d27c 100644 --- a/synapse/rest/room.py +++ b/synapse/rest/room.py @@ -157,7 +157,7 @@ class RoomStateEventRestServlet(RestServlet): event_dict["state_key"] = state_key msg_handler = self.handlers.message_handler - yield msg_handler.handle_event(event_dict) + yield msg_handler.create_and_send_event(event_dict) defer.returnValue((200, {})) @@ -176,7 +176,7 @@ class RoomSendEventRestServlet(RestServlet): content = _parse_json(request) msg_handler = self.handlers.message_handler - event = yield msg_handler.handle_event( + event = yield msg_handler.create_and_send_event( { "type": event_type, "content": content, @@ -237,7 +237,7 @@ class JoinRoomAliasServlet(RestServlet): defer.returnValue((200, ret_dict)) else: # room id msg_handler = self.handlers.message_handler - yield msg_handler.handle_event( + yield msg_handler.create_and_send_event( { "type": RoomMemberEvent.TYPE, "content": {"membership": Membership.JOIN}, @@ -401,7 +401,7 @@ class RoomMembershipRestServlet(RestServlet): membership_action = "leave" msg_handler = self.handlers.message_handler - yield msg_handler.handle_event( + yield msg_handler.create_and_send_event( { "type": RoomMemberEvent.TYPE, "content": {"membership": unicode(membership_action)}, @@ -439,7 +439,7 @@ class RoomRedactEventRestServlet(RestServlet): content = _parse_json(request) msg_handler = self.handlers.message_handler - event = yield msg_handler.handle_event( + event = yield msg_handler.create_and_send_event( { "type": RoomRedactionEvent.TYPE, "content": content, diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py index 9ae9335e2..9c63f2a88 100644 --- a/tests/handlers/test_room.py +++ b/tests/handlers/test_room.py @@ -369,10 +369,11 @@ class RoomCreationTest(unittest.TestCase): config=config, ) - self.assertTrue(self.message_handler.handle_event.called) + self.assertTrue(self.message_handler.create_and_send_event.called) event_dicts = [ - e[0][0] for e in self.message_handler.handle_event.call_args_list + e[0][0] + for e in self.message_handler.create_and_send_event.call_args_list ] self.assertTrue(len(event_dicts) > 3)