summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-15 17:01:12 +0000
committerErik Johnston <erik@matrix.org>2014-12-15 17:01:12 +0000
commitcf6e5f1dbf3cecf693e45f293535e71ee31801ed (patch)
treeea0f29cfd9168f1d1a7030ca66372cd42df64eb8
parentRemove unused functions (diff)
downloadsynapse-cf6e5f1dbf3cecf693e45f293535e71ee31801ed.tar.xz
Rename MessageHandler.handle_event. Add a few comments.
-rw-r--r--synapse/handlers/_base.py5
-rw-r--r--synapse/handlers/directory.py2
-rw-r--r--synapse/handlers/message.py14
-rw-r--r--synapse/handlers/profile.py2
-rw-r--r--synapse/handlers/room.py8
-rw-r--r--synapse/rest/room.py10
-rw-r--r--tests/handlers/test_room.py5
7 files changed, 32 insertions, 14 deletions
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index 14f75ecbc2..af8eb5f0f5 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 76fb897f20..4b0869cd9f 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 4fa4ffea25..1eed38c6d1 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 18fd0914e2..33a2c167ec 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 d317f2b30e..f7cc869225 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 25ee964555..1a527d27c1 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 9ae9335e29..9c63f2a882 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)