diff --git a/matrix/api.py b/matrix/api.py index b01e2f5..cb40c3c 100644 --- a/matrix/api.py +++ b/matrix/api.py @@ -375,6 +375,7 @@ class MatrixRedactMessage(MatrixMessage): def __init__(self, client, room_id, event_id, reason=None): self.room_id = room_id self.event_id = event_id + self.reason = reason data = { "room_id": self.room_id, @@ -391,6 +392,16 @@ class MatrixRedactMessage(MatrixMessage): data ) + def decode_body(self, server): + object_hook = partial( + MatrixEvents.MatrixRedactEvent.from_dict, + server, + self.room_id, + self.reason, + ) + + return self._decode(server, object_hook) + class MatrixBacklogMessage(MatrixMessage): def __init__(self, client, room_id, token, limit): diff --git a/matrix/events.py b/matrix/events.py index 5d54914..02f444a 100644 --- a/matrix/events.py +++ b/matrix/events.py @@ -181,3 +181,28 @@ class MatrixTopicEvent(MatrixEvent): False, parsed_dict ) + + +class MatrixRedactEvent(MatrixEvent): + def __init__(self, server, room_id, event_id, reason): + self.room_id = room_id + self.topic = reason + self.event_id = event_id + MatrixEvent.__init__(self, server) + + @classmethod + def from_dict(cls, server, room_id, reason, parsed_dict): + try: + return cls( + server, + room_id, + sanitize_id(parsed_dict["event_id"]), + reason + ) + except KeyError: + return MatrixErrorEvent.from_dict( + server, + "Error redacting message", + False, + parsed_dict + ) diff --git a/matrix/messages.py b/matrix/messages.py index cdfb469..f0c9c13 100644 --- a/matrix/messages.py +++ b/matrix/messages.py @@ -720,9 +720,9 @@ def matrix_handle_message( room.prev_batch = response['end'] - # Nothing to do here, we'll handle topic changes and redactions in the sync elif message_type == MessageType.REDACT: - pass + event = message.event + event.execute() else: server_buffer_prnt( @@ -771,6 +771,10 @@ def handle_http_response(server, message): event = message.event event.execute() + elif message.type == MessageType.REDACT: + event = message.event + event.execute() + else: error_message = ("{prefix}Unhandled 403 error, please inform the " "developers about this: {error}").format(