Start fixing places that use the data store.

This commit is contained in:
Erik Johnston 2014-08-14 17:34:37 +01:00
parent 78b501eba6
commit 661c711765
6 changed files with 33 additions and 39 deletions

View File

@ -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)

View File

@ -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)
# TODO (erikj): Implement this?
raise NotImplementedError("Getting feedback is not supported")
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)))
# 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,

View File

@ -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 "

View File

@ -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(

View File

@ -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 "

View File

@ -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]),
)