Add invite event class.

This commit is contained in:
poljar (Damir Jelić) 2018-02-14 14:52:21 +01:00
parent 32babecb33
commit 272e82aa76
3 changed files with 45 additions and 1 deletions

View file

@ -471,9 +471,10 @@ class MatrixPartMessage(MatrixMessage):
class MatrixInviteMessage(MatrixMessage): class MatrixInviteMessage(MatrixMessage):
def __init__(self, client, room_id, user_id): def __init__(self, client, room_id, user_id):
self.room_id = room_id self.room_id = room_id
self.user_id = user_id
data = {"room_id": self.room_id, data = {"room_id": self.room_id,
"user_id": user_id} "user_id": self.user_id}
MatrixMessage.__init__( MatrixMessage.__init__(
self, self,
@ -482,6 +483,16 @@ class MatrixInviteMessage(MatrixMessage):
data data
) )
def decode_body(self, server):
object_hook = partial(
MatrixEvents.MatrixInviteEvent.from_dict,
server,
self.room_id,
self.user_id
)
return self._decode(server, object_hook)
class MatrixUser: class MatrixUser:
def __init__(self, name, display_name): def __init__(self, name, display_name):

View file

@ -252,3 +252,28 @@ class MatrixPartEvent(MatrixEvent):
False, False,
parsed_dict parsed_dict
) )
class MatrixInviteEvent(MatrixEvent):
def __init__(self, server, room_id, user_id):
self.room_id = room_id
self.user_id = user_id
MatrixEvent.__init__(self, server)
@classmethod
def from_dict(cls, server, room_id, user_id, parsed_dict):
try:
if parsed_dict == {}:
return cls(
server,
room_id,
user_id)
raise KeyError
except KeyError:
return MatrixErrorEvent.from_dict(
server,
"Error inviting user",
False,
parsed_dict
)

View file

@ -695,6 +695,10 @@ def matrix_handle_message(
event = message.event event = message.event
event.execute() event.execute()
elif message_type is MessageType.INVITE:
event = message.event
event.execute()
elif message_type is MessageType.SEND: elif message_type is MessageType.SEND:
event = message.event event = message.event
event.execute() event.execute()
@ -795,6 +799,10 @@ def handle_http_response(server, message):
event = message.event event = message.event
event.execute() event.execute()
elif message.type == MessageType.INVITE:
event = message.event
event.execute()
else: else:
error_message = ("{prefix}Unhandled 403 error, please inform the " error_message = ("{prefix}Unhandled 403 error, please inform the "
"developers about this: {error}").format( "developers about this: {error}").format(