Add react method to MaubotMessageEvent

This commit is contained in:
Tulir Asokan 2019-06-21 14:19:24 +03:00
parent 66592ef81f
commit d56ec94d34

View File

@ -21,7 +21,8 @@ import attr
from mautrix import Client as MatrixClient from mautrix import Client as MatrixClient
from mautrix.util.formatter import parse_html from mautrix.util.formatter import parse_html
from mautrix.types import (EventType, MessageEvent, Event, EventID, RoomID, MessageEventContent, from mautrix.types import (EventType, MessageEvent, Event, EventID, RoomID, MessageEventContent,
MessageType, TextMessageEventContent, Format, RelatesTo, StateEvent) MessageType, TextMessageEventContent, Format, RelatesTo, RelationType,
ReactionEventContent)
class EscapeHTML(Extension): class EscapeHTML(Extension):
@ -70,6 +71,11 @@ class MaubotMessageEvent(MessageEvent):
def mark_read(self) -> Awaitable[None]: def mark_read(self) -> Awaitable[None]:
return self.client.send_receipt(self.room_id, self.event_id, "m.read") return self.client.send_receipt(self.room_id, self.event_id, "m.read")
def react(self, key: str) -> Awaitable[None]:
content = ReactionEventContent(relates_to=RelatesTo(rel_type=RelationType.ANNOTATION,
event_id=self.event_id, key=key))
return self.client.send_message_event(self.room_id, EventType.REACTION, content)
class MaubotMatrixClient(MatrixClient): class MaubotMatrixClient(MatrixClient):
def send_markdown(self, room_id: RoomID, markdown: str, msgtype: MessageType = MessageType.TEXT, def send_markdown(self, room_id: RoomID, markdown: str, msgtype: MessageType = MessageType.TEXT,