Add redaction message class.

This commit is contained in:
poljar (Damir Jelić) 2018-02-12 13:03:32 +01:00
parent d0c695dc09
commit aa625f0962
2 changed files with 30 additions and 6 deletions

View file

@ -137,7 +137,7 @@ class MatrixClient:
return HttpRequest(RequestType.PUT, self.host, path, content)
def room_redact(self, room_id, event_id, reason):
def room_redact(self, room_id, event_id, reason=None):
# type: (str, str, str) -> HttpRequest
query_parameters = {"access_token": self.access_token}
content = {}
@ -410,6 +410,27 @@ class MatrixTopicMessage(MatrixGenericMessage):
)
class MatrixRedactMessage(MatrixGenericMessage):
def __init__(self, client, room_id, event_id, reason=None):
self.room_id = room_id
self.event_id = event_id
data = {
"room_id": self.room_id,
"event_id": self.event_id
}
if reason:
data["reason"] = reason
MatrixGenericMessage.__init__(
self,
MessageType.REDACT,
client.room_redact,
data
)
class MatrixUser:
def __init__(self, name, display_name):
self.name = name # type: str

View file

@ -24,7 +24,12 @@ import matrix.globals
from matrix.globals import W, OPTIONS, SERVERS
from matrix.utf import utf8_decode
from matrix.api import MatrixMessage, MessageType, MatrixTopicMessage
from matrix.api import (
MatrixMessage,
MessageType,
MatrixTopicMessage,
MatrixRedactMessage
)
from matrix.utils import key_from_value, tags_from_line_data
from matrix.plugin_options import DebugType
from matrix.server import MatrixServer
@ -341,10 +346,8 @@ def matrix_redact_command_cb(data, buffer, args):
W.prnt("", message)
return W.WEECHAT_RC_OK
message = MatrixMessage(
server,
OPTIONS,
MessageType.REDACT,
message = MatrixRedactMessage(
server.client,
room_id=room_id,
event_id=event_id,
reason=reason