Feedback: Removed FeedbackRestServlet. Modified keys on FeedbackEvent. Expanded the feedback constants to fully explain what type of feedback they are.

This commit is contained in:
Kegan Dougal 2014-08-26 17:49:46 +01:00
parent 5a93bfe1f0
commit 5a3df1d029
4 changed files with 13 additions and 81 deletions

View File

@ -31,8 +31,8 @@ class Feedback(object):
"""Represents the types of feedback a user can send in response to a """Represents the types of feedback a user can send in response to a
message.""" message."""
DELIVERED = u"d" DELIVERED = u"delivered"
READ = u"r" READ = u"read"
LIST = (DELIVERED, READ) LIST = (DELIVERED, READ)

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from synapse.api.constants import Membership from synapse.api.constants import Feedback, Membership
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
from . import SynapseEvent from . import SynapseEvent
@ -93,17 +93,19 @@ class MessageEvent(SynapseEvent):
class FeedbackEvent(SynapseEvent): class FeedbackEvent(SynapseEvent):
TYPE = "m.room.message.feedback" TYPE = "m.room.message.feedback"
valid_keys = SynapseEvent.valid_keys + [ valid_keys = SynapseEvent.valid_keys
"msg_id", # the message ID being acknowledged
"msg_sender_id", # person who is sending the feedback is 'user_id'
"feedback_type", # the type of feedback (delivery, read, etc)
]
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(FeedbackEvent, self).__init__(**kwargs) super(FeedbackEvent, self).__init__(**kwargs)
if not kwargs["content"]["type"] in Feedback.LIST:
raise SynapseError(400, "Bad feedback value.")
def get_content_template(self): def get_content_template(self):
return {} return {
"type": u"string",
"target_event_id": u"string",
"msg_sender_id": u"string"
}
class InviteJoinEvent(SynapseEvent): class InviteJoinEvent(SynapseEvent):

View File

@ -228,75 +228,6 @@ class JoinRoomAliasServlet(RestServlet):
defer.returnValue((200, ret_dict)) defer.returnValue((200, ret_dict))
class FeedbackRestServlet(RestServlet):
PATTERN = client_path_pattern(
"/rooms/(?P<room_id>[^/]*)/messages/" +
"(?P<msg_sender_id>[^/]*)/(?P<msg_id>[^/]*)/feedback/" +
"(?P<sender_id>[^/]*)/(?P<feedback_type>[^/]*)$"
)
def get_event_type(self):
return FeedbackEvent.TYPE
@defer.inlineCallbacks
def on_GET(self, request, room_id, msg_sender_id, msg_id, fb_sender_id,
feedback_type):
yield (self.auth.get_user_by_req(request))
# TODO (erikj): Implement this?
raise NotImplementedError("Getting feedback is not supported")
# 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,
feedback_type):
user = yield (self.auth.get_user_by_req(request))
if user.to_string() != fb_sender_id:
raise SynapseError(403, "Must send feedback as yourself.",
errcode=Codes.FORBIDDEN)
if feedback_type not in Feedback.LIST:
raise SynapseError(400, "Bad feedback type.",
errcode=Codes.BAD_JSON)
content = _parse_json(request)
event = self.event_factory.create_event(
etype=self.get_event_type(),
room_id=urllib.unquote(room_id),
msg_sender_id=sender_id,
msg_id=msg_id,
user_id=user.to_string(), # user sending the feedback
feedback_type=feedback_type,
content=content
)
msg_handler = self.handlers.message_handler
yield msg_handler.send_feedback(event)
defer.returnValue((200, ""))
class RoomMemberListRestServlet(RestServlet): class RoomMemberListRestServlet(RestServlet):
PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/members$") PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/members$")
@ -447,7 +378,6 @@ def register_txn_path(servlet, regex_string, http_server, with_get=False):
def register_servlets(hs, http_server): def register_servlets(hs, http_server):
RoomStateEventRestServlet(hs).register(http_server) RoomStateEventRestServlet(hs).register(http_server)
FeedbackRestServlet(hs).register(http_server)
RoomCreateRestServlet(hs).register(http_server) RoomCreateRestServlet(hs).register(http_server)
RoomMemberListRestServlet(hs).register(http_server) RoomMemberListRestServlet(hs).register(http_server)
RoomMessageListRestServlet(hs).register(http_server) RoomMessageListRestServlet(hs).register(http_server)

View File

@ -23,9 +23,9 @@ class FeedbackStore(SQLBaseStore):
def _store_feedback(self, event): def _store_feedback(self, event):
return self._simple_insert("feedback", { return self._simple_insert("feedback", {
"event_id": event.event_id, "event_id": event.event_id,
"feedback_type": event.feedback_type, "feedback_type": event.content["type"],
"room_id": event.room_id, "room_id": event.room_id,
"target_event_id": event.target_event, "target_event_id": event.content["target_event_id"],
"sender": event.user_id, "sender": event.user_id,
}) })