forked from MirrorHub/synapse
Rename MessageHandler.handle_event. Add a few comments.
This commit is contained in:
parent
670dcdfc14
commit
cf6e5f1dbf
7 changed files with 32 additions and 14 deletions
|
@ -122,10 +122,15 @@ class BaseHandler(object):
|
||||||
if event.content["membership"] == Membership.INVITE:
|
if event.content["membership"] == Membership.INVITE:
|
||||||
invitee = self.hs.parse_userid(event.state_key)
|
invitee = self.hs.parse_userid(event.state_key)
|
||||||
if not self.hs.is_mine(invitee):
|
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(
|
returned_invite = yield federation_handler.send_invite(
|
||||||
invitee.domain,
|
invitee.domain,
|
||||||
event,
|
event,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: Make sure the signatures actually are correct.
|
||||||
event.signatures.update(
|
event.signatures.update(
|
||||||
returned_invite.signatures
|
returned_invite.signatures
|
||||||
)
|
)
|
||||||
|
|
|
@ -149,7 +149,7 @@ class DirectoryHandler(BaseHandler):
|
||||||
aliases = yield self.store.get_aliases_for_room(room_id)
|
aliases = yield self.store.get_aliases_for_room(room_id)
|
||||||
|
|
||||||
msg_handler = self.hs.get_handlers().message_handler
|
msg_handler = self.hs.get_handlers().message_handler
|
||||||
yield msg_handler.handle_event({
|
yield msg_handler.create_and_send_event({
|
||||||
"type": RoomAliasesEvent.TYPE,
|
"type": RoomAliasesEvent.TYPE,
|
||||||
"state_key": self.hs.hostname,
|
"state_key": self.hs.hostname,
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
|
|
|
@ -138,7 +138,19 @@ class MessageHandler(BaseHandler):
|
||||||
defer.returnValue(chunk)
|
defer.returnValue(chunk)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@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)
|
builder = self.event_builder_factory.new(event_dict)
|
||||||
|
|
||||||
self.validator.validate_new(builder)
|
self.validator.validate_new(builder)
|
||||||
|
|
|
@ -209,7 +209,7 @@ class ProfileHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
msg_handler = self.hs.get_handlers().message_handler
|
msg_handler = self.hs.get_handlers().message_handler
|
||||||
yield msg_handler.handle_event({
|
yield msg_handler.create_and_send_event({
|
||||||
"type": j.type,
|
"type": j.type,
|
||||||
"room_id": j.room_id,
|
"room_id": j.room_id,
|
||||||
"state_key": j.state_key,
|
"state_key": j.state_key,
|
||||||
|
|
|
@ -126,11 +126,11 @@ class RoomCreationHandler(BaseHandler):
|
||||||
msg_handler = self.hs.get_handlers().message_handler
|
msg_handler = self.hs.get_handlers().message_handler
|
||||||
|
|
||||||
for event in creation_events:
|
for event in creation_events:
|
||||||
yield msg_handler.handle_event(event)
|
yield msg_handler.create_and_send_event(event)
|
||||||
|
|
||||||
if "name" in config:
|
if "name" in config:
|
||||||
name = config["name"]
|
name = config["name"]
|
||||||
yield msg_handler.handle_event({
|
yield msg_handler.create_and_send_event({
|
||||||
"type": RoomNameEvent.TYPE,
|
"type": RoomNameEvent.TYPE,
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
"sender": user_id,
|
"sender": user_id,
|
||||||
|
@ -139,7 +139,7 @@ class RoomCreationHandler(BaseHandler):
|
||||||
|
|
||||||
if "topic" in config:
|
if "topic" in config:
|
||||||
topic = config["topic"]
|
topic = config["topic"]
|
||||||
yield msg_handler.handle_event({
|
yield msg_handler.create_and_send_event({
|
||||||
"type": RoomTopicEvent.TYPE,
|
"type": RoomTopicEvent.TYPE,
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
"sender": user_id,
|
"sender": user_id,
|
||||||
|
@ -147,7 +147,7 @@ class RoomCreationHandler(BaseHandler):
|
||||||
})
|
})
|
||||||
|
|
||||||
for invitee in invite_list:
|
for invitee in invite_list:
|
||||||
yield msg_handler.handle_event({
|
yield msg_handler.create_and_send_event({
|
||||||
"type": RoomMemberEvent.TYPE,
|
"type": RoomMemberEvent.TYPE,
|
||||||
"state_key": invitee,
|
"state_key": invitee,
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
|
|
|
@ -157,7 +157,7 @@ class RoomStateEventRestServlet(RestServlet):
|
||||||
event_dict["state_key"] = state_key
|
event_dict["state_key"] = state_key
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
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, {}))
|
defer.returnValue((200, {}))
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ class RoomSendEventRestServlet(RestServlet):
|
||||||
content = _parse_json(request)
|
content = _parse_json(request)
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
event = yield msg_handler.handle_event(
|
event = yield msg_handler.create_and_send_event(
|
||||||
{
|
{
|
||||||
"type": event_type,
|
"type": event_type,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
@ -237,7 +237,7 @@ class JoinRoomAliasServlet(RestServlet):
|
||||||
defer.returnValue((200, ret_dict))
|
defer.returnValue((200, ret_dict))
|
||||||
else: # room id
|
else: # room id
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
yield msg_handler.handle_event(
|
yield msg_handler.create_and_send_event(
|
||||||
{
|
{
|
||||||
"type": RoomMemberEvent.TYPE,
|
"type": RoomMemberEvent.TYPE,
|
||||||
"content": {"membership": Membership.JOIN},
|
"content": {"membership": Membership.JOIN},
|
||||||
|
@ -401,7 +401,7 @@ class RoomMembershipRestServlet(RestServlet):
|
||||||
membership_action = "leave"
|
membership_action = "leave"
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
yield msg_handler.handle_event(
|
yield msg_handler.create_and_send_event(
|
||||||
{
|
{
|
||||||
"type": RoomMemberEvent.TYPE,
|
"type": RoomMemberEvent.TYPE,
|
||||||
"content": {"membership": unicode(membership_action)},
|
"content": {"membership": unicode(membership_action)},
|
||||||
|
@ -439,7 +439,7 @@ class RoomRedactEventRestServlet(RestServlet):
|
||||||
content = _parse_json(request)
|
content = _parse_json(request)
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
event = yield msg_handler.handle_event(
|
event = yield msg_handler.create_and_send_event(
|
||||||
{
|
{
|
||||||
"type": RoomRedactionEvent.TYPE,
|
"type": RoomRedactionEvent.TYPE,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|
|
@ -369,10 +369,11 @@ class RoomCreationTest(unittest.TestCase):
|
||||||
config=config,
|
config=config,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertTrue(self.message_handler.handle_event.called)
|
self.assertTrue(self.message_handler.create_and_send_event.called)
|
||||||
|
|
||||||
event_dicts = [
|
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)
|
self.assertTrue(len(event_dicts) > 3)
|
||||||
|
|
Loading…
Reference in a new issue