Skip to content

Commit

Permalink
Merge branch '140'
Browse files Browse the repository at this point in the history
  • Loading branch information
non-Jedi committed Oct 15, 2017
2 parents 49284e4 + 1b6c044 commit 3039e32
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions matrix_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ def send_message_event(self, room_id, event_type, content, txn_id=None,
params["ts"] = timestamp
return self._send("PUT", path, content, query_params=params)

def redact_event(self, room_id, event_id, reason, txn_id=None, timestamp=None):
"""Perferm PUT /rooms/$room_id/redact/$event_id/$txn_id/
Args:
room_id(str): The room ID to redact the message event in.
event_id(str): The event id to redact.
reason(str): The reason the message was redacted.
txn_id(int): Optional. The transaction ID to use.
timestamp(int): Optional. Set origin_server_ts (For application services only)
"""
if not txn_id:
txn_id = str(self.txn_id) + str(int(time() * 1000))

self.txn_id = self.txn_id + 1
path = '/rooms/%s/redact/%s/%s' % (
room_id, event_id, txn_id
)
params = {}
if timestamp:
params["ts"] = timestamp
return self._send("PUT", path, {"reason": reason}, query_params=params)

# content_type can be a image,audio or video
# extra information should be supplied, see
# https://matrix.org/docs/spec/r0.0.1/client_server.html
Expand Down
14 changes: 14 additions & 0 deletions matrix_client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ def send_audio(self, url, name, **audioinfo):
return self.client.api.send_content(self.room_id, url, name, "m.audio",
extra_information=audioinfo)

def redact_message(self, event_id, reason=None):
""" Redacts the message with specified event_id in the room.
See https://matrix.org/docs/spec/r0.0.1/client_server.html#id112
Args:
event_id (str): The id of the event to be redacted.
reason (str): Optional. The reason provided for the redaction.
"""
content = {}
if reason:
content['reason'] = reason
return self.client.api.send_redact_event(self.room_id, event_id,
content)

def add_listener(self, callback, event_type=None):
""" Add a callback handler for events going to this room.
Expand Down

0 comments on commit 3039e32

Please sign in to comment.