summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-08-14 17:34:37 +0100
committerErik Johnston <erik@matrix.org>2014-08-14 17:34:37 +0100
commit661c7117659118ed977f56a092525dbdae9dc67c (patch)
tree8284cb857d98c920bb66f70d504cf716d4a613c5 /synapse
parentFix typo (diff)
downloadsynapse-661c7117659118ed977f56a092525dbdae9dc67c.tar.xz
Start fixing places that use the data store.
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/room.py17
-rw-r--r--synapse/rest/room.py39
-rw-r--r--synapse/storage/__init__.py8
-rw-r--r--synapse/storage/_base.py2
-rw-r--r--synapse/storage/feedback.py4
-rw-r--r--synapse/storage/roommember.py2
6 files changed, 33 insertions, 39 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index eae40765b3..a9ff2d93f1 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -141,12 +141,7 @@ class MessageHandler(BaseHandler):
             yield self.state_handler.handle_new_event(event)
 
             # store in db
-            store_id = yield self.store.store_room_data(
-                room_id=event.room_id,
-                etype=event.type,
-                state_key=event.state_key,
-                content=json.dumps(event.content)
-            )
+            store_id = yield self.store.persist_event(event)
 
             event.destinations = yield self.store.get_joined_hosts_for_room(
                 event.room_id
@@ -201,19 +196,15 @@ class MessageHandler(BaseHandler):
                 raise RoomError(
                     403, "Member does not meet private room rules.")
 
-        data = yield self.store.get_room_data(room_id, event_type, state_key)
+        data = yield self.store.get_current_state(room_id, event_type, state_key)
         defer.returnValue(data)
 
     @defer.inlineCallbacks
-    def get_feedback(self, room_id=None, msg_sender_id=None, msg_id=None,
-                     user_id=None, fb_sender_id=None, fb_type=None):
+    def get_feedback(self, event_id):
         yield self.auth.check_joined_room(room_id, user_id)
 
         # Pull out the feedback from the db
-        fb = yield self.store.get_feedback(
-            room_id=room_id, msg_id=msg_id, msg_sender_id=msg_sender_id,
-            fb_sender_id=fb_sender_id, fb_type=fb_type
-        )
+        fb = yield self.store.get_feedback(event_id)
 
         if fb:
             defer.returnValue(fb)
diff --git a/synapse/rest/room.py b/synapse/rest/room.py
index 1fc0c996b8..3f153df8e3 100644
--- a/synapse/rest/room.py
+++ b/synapse/rest/room.py
@@ -285,25 +285,28 @@ class FeedbackRestServlet(RestServlet):
                feedback_type):
         user = yield (self.auth.get_user_by_req(request))
 
-        if feedback_type not in Feedback.LIST:
-            raise SynapseError(400, "Bad feedback type.",
-                               errcode=Codes.BAD_JSON)
-
-        msg_handler = self.handlers.message_handler
-        feedback = yield msg_handler.get_feedback(
-            room_id=urllib.unquote(room_id),
-            msg_sender_id=msg_sender_id,
-            msg_id=msg_id,
-            user_id=user.to_string(),
-            fb_sender_id=fb_sender_id,
-            fb_type=feedback_type
-        )
-
-        if not feedback:
-            raise SynapseError(404, "Feedback not found.",
-                               errcode=Codes.NOT_FOUND)
+        # TODO (erikj): Implement this?
+        raise NotImplementedError("Getting feedback is not supported")
 
-        defer.returnValue((200, json.loads(feedback.content)))
+#        if feedback_type not in Feedback.LIST:
+#            raise SynapseError(400, "Bad feedback type.",
+#                               errcode=Codes.BAD_JSON)
+#
+#        msg_handler = self.handlers.message_handler
+#        feedback = yield msg_handler.get_feedback(
+#            room_id=urllib.unquote(room_id),
+#            msg_sender_id=msg_sender_id,
+#            msg_id=msg_id,
+#            user_id=user.to_string(),
+#            fb_sender_id=fb_sender_id,
+#            fb_type=feedback_type
+#        )
+#
+#        if not feedback:
+#            raise SynapseError(404, "Feedback not found.",
+#                               errcode=Codes.NOT_FOUND)
+#
+#        defer.returnValue((200, json.loads(feedback.content)))
 
     @defer.inlineCallbacks
     def on_PUT(self, request, room_id, sender_id, msg_id, fb_sender_id,
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index afdd75f46d..182b6ebadd 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -21,13 +21,11 @@ from synapse.api.events.room import (
 
 from .directory import DirectoryStore
 from .feedback import FeedbackStore
-from .message import MessageStore
 from .presence import PresenceStore
 from .profile import ProfileStore
 from .registration import RegistrationStore
 from .room import RoomStore
 from .roommember import RoomMemberStore
-from .roomdata import RoomDataStore
 from .stream import StreamStore
 from .pdu import StatePduStore, PduStore
 from .transactions import TransactionStore
@@ -36,7 +34,7 @@ import json
 import os
 
 
-class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore,
+class DataStore(RoomMemberStore, RoomStore,
                 RegistrationStore, StreamStore, ProfileStore, FeedbackStore,
                 PresenceStore, PduStore, StatePduStore, TransactionStore,
                 DirectoryStore):
@@ -78,7 +76,7 @@ class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore,
     def _store_event(self, event):
         vals = {
             "event_id": event.event_id,
-            "event_type", event.type,
+            "event_type": event.type,
             "sender": event.user_id,
             "room_id": event.room_id,
             "content": json.dumps(event.content),
@@ -105,7 +103,7 @@ class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore,
             # TODO (erikj): We also need to update the current state table?
 
     @defer.inlineCallbacks
-    def get_current_state(room_id, event_type=None, state_key="")
+    def get_current_state(room_id, event_type=None, state_key=""):
         sql = (
             "SELECT e.* FROM events as e"
             "INNER JOIN current_state as c ON e.event_id = c.event_id "
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 7fef8601e7..533f509709 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -293,7 +293,7 @@ class SQLBaseStore(object):
     def _parse_event_from_row(self, row_dict):
         d = copy.deepcopy({k: v for k, v in row.items() if v})
         d.update(json.loads(json.loads(row["unrecognized_keys"])))
-        d["content"] = json.loads(d["content"})
+        d["content"] = json.loads(d["content"])
         del d["unrecognized_keys"]
 
         return self.event_factory.create_event(
diff --git a/synapse/storage/feedback.py b/synapse/storage/feedback.py
index dd5f3fbc10..e60f98d1e1 100644
--- a/synapse/storage/feedback.py
+++ b/synapse/storage/feedback.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from twisted.internet import defer
+
 from ._base import SQLBaseStore, Table
 from synapse.api.events.room import FeedbackEvent
 
@@ -31,7 +33,7 @@ class FeedbackStore(SQLBaseStore):
             "sender": event.user_id,
         })
 
-    @defer.inlineCallback
+    @defer.inlineCallbacks
     def get_feedback_for_event(self, event_id):
         sql = (
             "SELECT events.* FROM events INNER JOIN feedback "
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index c99cefbcfc..14c0152e8a 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -112,7 +112,7 @@ class RoomMemberStore(SQLBaseStore):
         args = [user_id]
         args.extend(membership_list)
 
-        where_clause "user_id = ? AND (%s)" % (
+        where_clause = "user_id = ? AND (%s)" % (
             " OR ".join(["membership = ?" for _ in membership_list]),
         )