Rename MessageHandler.handle_event. Add a few comments.

This commit is contained in:
Erik Johnston 2014-12-15 17:01:12 +00:00
parent 670dcdfc14
commit cf6e5f1dbf
7 changed files with 32 additions and 14 deletions

View file

@ -122,10 +122,15 @@ class BaseHandler(object):
if event.content["membership"] == Membership.INVITE:
invitee = self.hs.parse_userid(event.state_key)
if not self.hs.is_mine(invitee):
# TODO: Can we add signature from remote server in a nicer
# way? If we have been invited by a remote server, we need
# to get them to sign the event.
returned_invite = yield federation_handler.send_invite(
invitee.domain,
event,
)
# TODO: Make sure the signatures actually are correct.
event.signatures.update(
returned_invite.signatures
)

View file

@ -149,7 +149,7 @@ class DirectoryHandler(BaseHandler):
aliases = yield self.store.get_aliases_for_room(room_id)
msg_handler = self.hs.get_handlers().message_handler
yield msg_handler.handle_event({
yield msg_handler.create_and_send_event({
"type": RoomAliasesEvent.TYPE,
"state_key": self.hs.hostname,
"room_id": room_id,

View file

@ -138,7 +138,19 @@ class MessageHandler(BaseHandler):
defer.returnValue(chunk)
@defer.inlineCallbacks
def handle_event(self, event_dict):
def create_and_send_event(self, event_dict):
""" Given a dict from a client, create and handle a new event.
Creates an FrozenEvent object, filling out auth_events, prev_events,
etc.
Adds display names to Join membership events.
Persists and notifies local clients and federation.
Args:
event_dict (dict): An entire event
"""
builder = self.event_builder_factory.new(event_dict)
self.validator.validate_new(builder)

View file

@ -209,7 +209,7 @@ class ProfileHandler(BaseHandler):
)
msg_handler = self.hs.get_handlers().message_handler
yield msg_handler.handle_event({
yield msg_handler.create_and_send_event({
"type": j.type,
"room_id": j.room_id,
"state_key": j.state_key,

View file

@ -126,11 +126,11 @@ class RoomCreationHandler(BaseHandler):
msg_handler = self.hs.get_handlers().message_handler
for event in creation_events:
yield msg_handler.handle_event(event)
yield msg_handler.create_and_send_event(event)
if "name" in config:
name = config["name"]
yield msg_handler.handle_event({
yield msg_handler.create_and_send_event({
"type": RoomNameEvent.TYPE,
"room_id": room_id,
"sender": user_id,
@ -139,7 +139,7 @@ class RoomCreationHandler(BaseHandler):
if "topic" in config:
topic = config["topic"]
yield msg_handler.handle_event({
yield msg_handler.create_and_send_event({
"type": RoomTopicEvent.TYPE,
"room_id": room_id,
"sender": user_id,
@ -147,7 +147,7 @@ class RoomCreationHandler(BaseHandler):
})
for invitee in invite_list:
yield msg_handler.handle_event({
yield msg_handler.create_and_send_event({
"type": RoomMemberEvent.TYPE,
"state_key": invitee,
"room_id": room_id,

View file

@ -157,7 +157,7 @@ class RoomStateEventRestServlet(RestServlet):
event_dict["state_key"] = state_key
msg_handler = self.handlers.message_handler
yield msg_handler.handle_event(event_dict)
yield msg_handler.create_and_send_event(event_dict)
defer.returnValue((200, {}))
@ -176,7 +176,7 @@ class RoomSendEventRestServlet(RestServlet):
content = _parse_json(request)
msg_handler = self.handlers.message_handler
event = yield msg_handler.handle_event(
event = yield msg_handler.create_and_send_event(
{
"type": event_type,
"content": content,
@ -237,7 +237,7 @@ class JoinRoomAliasServlet(RestServlet):
defer.returnValue((200, ret_dict))
else: # room id
msg_handler = self.handlers.message_handler
yield msg_handler.handle_event(
yield msg_handler.create_and_send_event(
{
"type": RoomMemberEvent.TYPE,
"content": {"membership": Membership.JOIN},
@ -401,7 +401,7 @@ class RoomMembershipRestServlet(RestServlet):
membership_action = "leave"
msg_handler = self.handlers.message_handler
yield msg_handler.handle_event(
yield msg_handler.create_and_send_event(
{
"type": RoomMemberEvent.TYPE,
"content": {"membership": unicode(membership_action)},
@ -439,7 +439,7 @@ class RoomRedactEventRestServlet(RestServlet):
content = _parse_json(request)
msg_handler = self.handlers.message_handler
event = yield msg_handler.handle_event(
event = yield msg_handler.create_and_send_event(
{
"type": RoomRedactionEvent.TYPE,
"content": content,

View file

@ -369,10 +369,11 @@ class RoomCreationTest(unittest.TestCase):
config=config,
)
self.assertTrue(self.message_handler.handle_event.called)
self.assertTrue(self.message_handler.create_and_send_event.called)
event_dicts = [
e[0][0] for e in self.message_handler.handle_event.call_args_list
e[0][0]
for e in self.message_handler.create_and_send_event.call_args_list
]
self.assertTrue(len(event_dicts) > 3)