summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-10 14:02:48 +0000
committerErik Johnston <erik@matrix.org>2014-12-10 14:02:48 +0000
commit02db7eb209af879a0168a371b4cb1c2ad0fcab49 (patch)
tree27535103af5903aa66c4561c02cbc24f5a013fd7 /synapse
parentMerge branch 'develop' of github.com:matrix-org/synapse into events_refactor (diff)
downloadsynapse-02db7eb209af879a0168a371b4cb1c2ad0fcab49.tar.xz
Fix bug when uploading state with empty state_key
Diffstat (limited to 'synapse')
-rw-r--r--synapse/events/__init__.py10
-rw-r--r--synapse/handlers/_base.py66
-rw-r--r--synapse/handlers/message.py15
-rw-r--r--synapse/rest/room.py20
-rw-r--r--synapse/storage/__init__.py4
-rw-r--r--synapse/storage/schema/im.sql2
6 files changed, 29 insertions, 88 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index 5f41933174..bd3ffb59cc 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -118,6 +118,9 @@ class EventBase(object):
 
         return d
 
+    def get(self, key, default):
+        return self._event_dict.get(key, default)
+
     def get_internal_metadata_dict(self):
         return self.internal_metadata.get_dict()
 
@@ -165,6 +168,9 @@ class FrozenEvent(EventBase):
         return _unfreeze(super(FrozenEvent, self).get_dict())
 
     def __str__(self):
+        return self.__repr__()
+
+    def __repr__(self):
         return "<FrozenEvent event_id='%s', type='%s', state_key='%s'>" % (
-            self.event_id, self.type, self.state_key,
-        )
+            self.event_id, self.type, self.get("state_key", None),
+        )
\ No newline at end of file
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index 6b5f6e7cd8..fdd3151877 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -97,6 +97,11 @@ class BaseHandler(object):
 
         event = builder.build()
 
+        logger.debug(
+            "Created event %s with auth_events: %s, current state: %s",
+            event.event_id, context.auth_events, context.current_state,
+        )
+
         defer.returnValue(
             (event, context,)
         )
@@ -147,64 +152,3 @@ class BaseHandler(object):
             None,
             destinations=destinations,
         )
-
-    # @defer.inlineCallbacks
-    # def _on_new_room_event(self, event, snapshot, extra_destinations=[],
-    #                        extra_users=[], suppress_auth=False,
-    #                        do_invite_host=None):
-    #     yield run_on_reactor()
-    #
-    #     snapshot.fill_out_prev_events(event)
-    #
-    #     yield self.state_handler.annotate_event_with_state(event)
-    #
-    #     yield self.auth.add_auth_events(event)
-    #
-    #     logger.debug("Signing event...")
-    #
-    #     add_hashes_and_signatures(
-    #         event, self.server_name, self.signing_key
-    #     )
-    #
-    #     logger.debug("Signed event.")
-    #
-    #     if not suppress_auth:
-    #         logger.debug("Authing...")
-    #         self.auth.check(event, auth_events=event.old_state_events)
-    #         logger.debug("Authed")
-    #     else:
-    #         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)
-    #
-    #     destinations = set(extra_destinations)
-    #     # Send a PDU to all hosts who have joined the room.
-    #
-    #     for k, s in event.state_events.items():
-    #         try:
-    #             if k[0] == RoomMemberEvent.TYPE:
-    #                 if s.content["membership"] == Membership.JOIN:
-    #                     destinations.add(
-    #                         self.hs.parse_userid(s.state_key).domain
-    #                     )
-    #         except:
-    #             logger.warn(
-    #                 "Failed to get destination from event %s", s.event_id
-    #             )
-    #
-    #     event.destinations = list(destinations)
-    #
-    #     yield self.notifier.on_new_room_event(event, extra_users=extra_users)
-    #
-    #     federation_handler = self.hs.get_handlers().federation_handler
-    #     yield federation_handler.handle_new_event(event, snapshot)
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 13fa0be7b4..9043b945e4 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -166,21 +166,6 @@ class MessageHandler(BaseHandler):
         defer.returnValue(event)
 
     @defer.inlineCallbacks
-    def store_room_data(self, event=None):
-        """ Stores data for a room.
-
-        Args:
-            event : The room path event
-            stamp_event (bool) : True to stamp event content with server keys.
-        Raises:
-            SynapseError if something went wrong.
-        """
-
-        snapshot = yield self.store.snapshot_room(event)
-
-        yield self._on_new_room_event(event, snapshot)
-
-    @defer.inlineCallbacks
     def get_room_data(self, user_id=None, room_id=None,
                       event_type=None, state_key=""):
         """ Get data from a room.
diff --git a/synapse/rest/room.py b/synapse/rest/room.py
index 3d78b4ff5c..22e1244e57 100644
--- a/synapse/rest/room.py
+++ b/synapse/rest/room.py
@@ -147,16 +147,18 @@ class RoomStateEventRestServlet(RestServlet):
 
         content = _parse_json(request)
 
+        event_dict = {
+            "type": event_type,
+            "content": content,
+            "room_id": urllib.unquote(room_id),
+            "sender": user.to_string(),
+        }
+
+        if state_key is not None:
+            event_dict["state_key"] = urllib.unquote(state_key)
+
         msg_handler = self.handlers.message_handler
-        yield msg_handler.handle_event(
-            {
-                "type": event_type,
-                "content": content,
-                "room_id": room_id,
-                "sender": user.to_string(),
-                "state_key": urllib.unquote(state_key),
-            }
-        )
+        yield msg_handler.handle_event(event_dict)
 
         defer.returnValue((200, {}))
 
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 7068424441..f8d895082d 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -39,6 +39,7 @@ from .state import StateStore
 from .signatures import SignatureStore
 
 from syutil.base64util import decode_base64
+from syutil.jsonutil import encode_canonical_json
 
 from synapse.crypto.event_signing import compute_event_reference_hash
 
@@ -162,7 +163,8 @@ class DataStore(RoomMemberStore, RoomStore,
             table="event_json",
             values={
                 "event_id": event.event_id,
-                "json": json.dumps(event_dict, separators=(',', ':')),
+                "room_id": event.room_id,
+                "json": encode_canonical_json(event_dict),
             },
             or_replace=True,
         )
diff --git a/synapse/storage/schema/im.sql b/synapse/storage/schema/im.sql
index cb0c494ddf..0300bb29e1 100644
--- a/synapse/storage/schema/im.sql
+++ b/synapse/storage/schema/im.sql
@@ -35,11 +35,13 @@ CREATE INDEX IF NOT EXISTS events_room_id ON events (room_id);
 
 CREATE TABLE IF NOT EXISTS event_json(
     event_id TEXT NOT NULL,
+    room_id TEXT NOT NULL,
     json BLOB NOT NULL,
     CONSTRAINT ev_j_uniq UNIQUE (event_id)
 );
 
 CREATE INDEX IF NOT EXISTS event_json_id ON event_json(event_id);
+CREATE INDEX IF NOT EXISTS event_json_room_id ON event_json(room_id);
 
 
 CREATE TABLE IF NOT EXISTS state_events(