diff --git a/matrix/api.py b/matrix/api.py index cb40c3c..4a8a930 100644 --- a/matrix/api.py +++ b/matrix/api.py @@ -435,6 +435,15 @@ class MatrixJoinMessage(MatrixMessage): data ) + def decode_body(self, server): + object_hook = partial( + MatrixEvents.MatrixJoinEvent.from_dict, + server, + self.room_id + ) + + return self._decode(server, object_hook) + class MatrixPartMessage(MatrixMessage): def __init__(self, client, room_id): diff --git a/matrix/events.py b/matrix/events.py index 02f444a..5d75f1d 100644 --- a/matrix/events.py +++ b/matrix/events.py @@ -206,3 +206,26 @@ class MatrixRedactEvent(MatrixEvent): False, parsed_dict ) + + +class MatrixJoinEvent(MatrixEvent): + def __init__(self, server, room_id, event_id): + self.room_id = room_id + self.event_id = event_id + MatrixEvent.__init__(self, server) + + @classmethod + def from_dict(cls, server, room_id, parsed_dict): + try: + return cls( + server, + room_id, + sanitize_id(parsed_dict["event_id"]), + ) + except KeyError: + return MatrixErrorEvent.from_dict( + server, + "Error joining room", + False, + parsed_dict + ) diff --git a/matrix/messages.py b/matrix/messages.py index f0c9c13..fc3951b 100644 --- a/matrix/messages.py +++ b/matrix/messages.py @@ -782,6 +782,18 @@ def handle_http_response(server, message): error=message.response.body) server_buffer_prnt(server, error_message) + elif status_code == 404: + if message.type == MessageType.JOIN: + event = message.event + event.execute() + + else: + error_message = ("{prefix}Unhandled 404 error, please inform the " + "developers about this: {error}").format( + prefix=W.prefix("error"), + error=message.response.body) + server_buffer_prnt(server, error_message) + else: server_buffer_prnt( server,