summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-16 11:29:05 +0000
committerErik Johnston <erik@matrix.org>2014-12-16 11:29:05 +0000
commit3c77d13aa5375274e267a0ea898ce6267fb67cdc (patch)
tree28b958507d705a5a92fd167191e1d62d98fe644c /synapse/handlers
parentAdd fixme to raising of AuthError in federation land (diff)
downloadsynapse-3c77d13aa5375274e267a0ea898ce6267fb67cdc.tar.xz
Kill off synapse.api.events.*
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/directory.py4
-rw-r--r--synapse/handlers/federation.py22
-rw-r--r--synapse/handlers/message.py1
-rw-r--r--synapse/handlers/room.py28
4 files changed, 25 insertions, 30 deletions
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 4b0869cd9f..404baea796 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -18,7 +18,7 @@ from twisted.internet import defer
 from ._base import BaseHandler
 
 from synapse.api.errors import SynapseError, Codes, CodeMessageException
-from synapse.api.events.room import RoomAliasesEvent
+from synapse.api.constants import EventTypes
 
 import logging
 
@@ -150,7 +150,7 @@ class DirectoryHandler(BaseHandler):
 
         msg_handler = self.hs.get_handlers().message_handler
         yield msg_handler.create_and_send_event({
-            "type": RoomAliasesEvent.TYPE,
+            "type": EventTypes.Aliases,
             "state_key": self.hs.hostname,
             "room_id": room_id,
             "sender": user_id,
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index c00f5a7031..16a104c0e2 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -22,8 +22,7 @@ from synapse.events.utils import prune_event
 from synapse.api.errors import (
     AuthError, FederationError, SynapseError, StoreError,
 )
-from synapse.api.events.room import RoomMemberEvent, RoomCreateEvent
-from synapse.api.constants import Membership
+from synapse.api.constants import EventTypes, Membership
 from synapse.util.logutils import log_function
 from synapse.util.async import run_on_reactor
 from synapse.crypto.event_signing import (
@@ -225,7 +224,7 @@ class FederationHandler(BaseHandler):
 
         if not backfilled:
             extra_users = []
-            if event.type == RoomMemberEvent.TYPE:
+            if event.type == EventTypes.Member:
                 target_user_id = event.state_key
                 target_user = self.hs.parse_userid(target_user_id)
                 extra_users.append(target_user)
@@ -234,7 +233,7 @@ class FederationHandler(BaseHandler):
                 event, extra_users=extra_users
             )
 
-        if event.type == RoomMemberEvent.TYPE:
+        if event.type == EventTypes.Member:
             if event.membership == Membership.JOIN:
                 user = self.hs.parse_userid(event.state_key)
                 yield self.distributor.fire(
@@ -333,7 +332,8 @@ class FederationHandler(BaseHandler):
         event = pdu
 
         # We should assert some things.
-        assert(event.type == RoomMemberEvent.TYPE)
+        # FIXME: Do this in a nicer way
+        assert(event.type == EventTypes.Member)
         assert(event.user_id == joinee)
         assert(event.state_key == joinee)
         assert(event.room_id == room_id)
@@ -450,7 +450,7 @@ class FederationHandler(BaseHandler):
         process it until the other server has signed it and sent it back.
         """
         builder = self.event_builder_factory.new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "content": {"membership": Membership.JOIN},
             "room_id": room_id,
             "sender": user_id,
@@ -492,7 +492,7 @@ class FederationHandler(BaseHandler):
         )
 
         extra_users = []
-        if event.type == RoomMemberEvent.TYPE:
+        if event.type == EventTypes.Member:
             target_user_id = event.state_key
             target_user = self.hs.parse_userid(target_user_id)
             extra_users.append(target_user)
@@ -501,7 +501,7 @@ class FederationHandler(BaseHandler):
             event, extra_users=extra_users
         )
 
-        if event.type == RoomMemberEvent.TYPE:
+        if event.type == EventTypes.Member:
             if event.content["membership"] == Membership.JOIN:
                 user = self.hs.parse_userid(event.state_key)
                 yield self.distributor.fire(
@@ -514,7 +514,7 @@ class FederationHandler(BaseHandler):
 
         for k, s in context.current_state.items():
             try:
-                if k[0] == RoomMemberEvent.TYPE:
+                if k[0] == EventTypes.Member:
                     if s.content["membership"] == Membership.JOIN:
                         destinations.add(
                             self.hs.parse_userid(s.state_key).domain
@@ -731,10 +731,10 @@ class FederationHandler(BaseHandler):
             event.event_id, event.signatures,
         )
 
-        if event.type == RoomMemberEvent.TYPE and not event.auth_events:
+        if event.type == EventTypes.Member and not event.auth_events:
             if len(event.prev_events) == 1:
                 c = yield self.store.get_event(event.prev_events[0][0])
-                if c.type == RoomCreateEvent.TYPE:
+                if c.type == EventTypes.Create:
                     context.auth_events[(c.type, c.state_key)] = c
 
         logger.debug(
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 1eed38c6d1..baf372fdad 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -35,7 +35,6 @@ class MessageHandler(BaseHandler):
         super(MessageHandler, self).__init__(hs)
         self.hs = hs
         self.clock = hs.get_clock()
-        self.event_factory = hs.get_event_factory()
         self.validator = EventValidator()
 
     @defer.inlineCallbacks
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index f7cc869225..8567d7409d 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -17,12 +17,8 @@
 from twisted.internet import defer
 
 from synapse.types import UserID, RoomAlias, RoomID
-from synapse.api.constants import Membership, JoinRules
+from synapse.api.constants import EventTypes, Membership, JoinRules
 from synapse.api.errors import StoreError, SynapseError
-from synapse.api.events.room import (
-    RoomMemberEvent, RoomCreateEvent, RoomPowerLevelsEvent,
-    RoomTopicEvent, RoomNameEvent, RoomJoinRulesEvent,
-)
 from synapse.util import stringutils
 from synapse.util.async import run_on_reactor
 from ._base import BaseHandler
@@ -131,7 +127,7 @@ class RoomCreationHandler(BaseHandler):
         if "name" in config:
             name = config["name"]
             yield msg_handler.create_and_send_event({
-                "type": RoomNameEvent.TYPE,
+                "type": EventTypes.Name,
                 "room_id": room_id,
                 "sender": user_id,
                 "content": {"name": name},
@@ -140,7 +136,7 @@ class RoomCreationHandler(BaseHandler):
         if "topic" in config:
             topic = config["topic"]
             yield msg_handler.create_and_send_event({
-                "type": RoomTopicEvent.TYPE,
+                "type": EventTypes.Topic,
                 "room_id": room_id,
                 "sender": user_id,
                 "content": {"topic": topic},
@@ -148,7 +144,7 @@ class RoomCreationHandler(BaseHandler):
 
         for invitee in invite_list:
             yield msg_handler.create_and_send_event({
-                "type": RoomMemberEvent.TYPE,
+                "type": EventTypes.Member,
                 "state_key": invitee,
                 "room_id": room_id,
                 "user_id": user_id,
@@ -186,12 +182,12 @@ class RoomCreationHandler(BaseHandler):
             return e
 
         creation_event = create(
-            etype=RoomCreateEvent.TYPE,
+            etype=EventTypes.Create,
             content={"creator": creator.to_string()},
         )
 
         join_event = create(
-            etype=RoomMemberEvent.TYPE,
+            etype=EventTypes.Member,
             state_key=creator_id,
             content={
                 "membership": Membership.JOIN,
@@ -199,15 +195,15 @@ class RoomCreationHandler(BaseHandler):
         )
 
         power_levels_event = create(
-            etype=RoomPowerLevelsEvent.TYPE,
+            etype=EventTypes.PowerLevels,
             content={
                 "users": {
                     creator.to_string(): 100,
                 },
                 "users_default": 0,
                 "events": {
-                    RoomNameEvent.TYPE: 100,
-                    RoomPowerLevelsEvent.TYPE: 100,
+                    EventTypes.Name: 100,
+                    EventTypes.PowerLevels: 100,
                 },
                 "events_default": 0,
                 "state_default": 50,
@@ -219,7 +215,7 @@ class RoomCreationHandler(BaseHandler):
 
         join_rule = JoinRules.PUBLIC if is_public else JoinRules.INVITE
         join_rules_event = create(
-            etype=RoomJoinRulesEvent.TYPE,
+            etype=EventTypes.JoinRules,
             content={"join_rule": join_rule},
         )
 
@@ -344,7 +340,7 @@ class RoomMemberHandler(BaseHandler):
         target_user_id = event.state_key
 
         prev_state = context.current_state.get(
-            (RoomMemberEvent.TYPE, target_user_id),
+            (EventTypes.Member, target_user_id),
             None
         )
 
@@ -396,7 +392,7 @@ class RoomMemberHandler(BaseHandler):
 
         content.update({"membership": Membership.JOIN})
         builder = self.event_builder_factory.new({
-            "type": RoomMemberEvent.TYPE,
+            "type": EventTypes.Member,
             "state_key": joinee.to_string(),
             "room_id": room_id,
             "sender": joinee.to_string(),