Refactor of the redaction API.

This commit is contained in:
poljar (Damir Jelić) 2018-02-06 12:07:17 +01:00
parent 64df928a4e
commit 2813c42c3c
2 changed files with 22 additions and 19 deletions

View file

@ -127,6 +127,25 @@ class MatrixClient:
return HttpRequest(RequestType.PUT, self.host, path, content)
def room_redact(self, room_id, event_id, reason):
# type: (str, str, str) -> HttpRequest
query_parameters = {"access_token": self.access_token}
content = {}
if reason:
content["reason"] = reason
path = ("{api}/rooms/{room}/redact/{event_id}/{tx_id}?"
"{query_parameters}").format(
api=MATRIX_API_PATH,
room=quote(room_id),
event_id=quote(event_id),
tx_id=quote(str(self._get_txn_id())),
query_parameters=urlencode(query_parameters))
return HttpRequest(RequestType.PUT, self.host, path, content)
class MatrixMessage:
def __init__(
@ -169,7 +188,7 @@ class MatrixMessage:
self.request = server.client.sync(server.next_batch, sync_filter)
elif message_type == MessageType.SEND:
self.request = server.client.room_message(room_id, data)
self.request = server.client.room_send_message(room_id, data)
elif message_type == MessageType.STATE:
if extra_id == "m.room.topic":
@ -178,20 +197,7 @@ class MatrixMessage:
assert "Not implemented state event"
elif message_type == MessageType.REDACT:
path = ("{api}/rooms/{room}/redact/{event_id}/{tx_id}?"
"access_token={access_token}").format(
api=MATRIX_API_PATH,
room=room_id,
event_id=extra_id,
tx_id=get_transaction_id(server),
access_token=server.access_token)
self.request = HttpRequest(
RequestType.PUT,
host,
path,
data
)
self.request = server.client.room_redact(room_id, extra_id, data)
elif message_type == MessageType.ROOM_MSG:
path = ("{api}/rooms/{room}/messages?from={prev_batch}&"

View file

@ -335,9 +335,6 @@ def matrix_redact_command_cb(data, buffer, args):
line_string, _, reason = matches.groups()
line = int(line_string)
if reason:
body = {"reason": reason}
event_id = event_id_from_line(buffer, line)
if not event_id:
@ -352,7 +349,7 @@ def matrix_redact_command_cb(data, buffer, args):
server,
OPTIONS,
MessageType.REDACT,
data=body,
data=reason,
room_id=room_id,
extra_id=event_id
)