Add redaction event class.

This commit is contained in:
poljar (Damir Jelić) 2018-02-14 13:00:18 +01:00
parent 3232f61f7e
commit 2a0cccc191
3 changed files with 42 additions and 2 deletions

View file

@ -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):

View file

@ -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
)

View file

@ -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(