diff --git a/CHANGELOG.md b/CHANGELOG.md index aad156fd..0648c9e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.20.5 (unreleased) + +* *(types)* Added support for MSC2530 media event content + ## v0.20.4 (2024-01-09) * Dropped Python 3.9 support. diff --git a/mautrix/types/__init__.py b/mautrix/types/__init__.py index 42b9068c..9a62f23b 100644 --- a/mautrix/types/__init__.py +++ b/mautrix/types/__init__.py @@ -70,6 +70,7 @@ EventType, FileInfo, Format, + FormatableMessageEventContent, ForwardedRoomKeyEventContent, GenericEvent, ImageInfo, diff --git a/mautrix/types/event/__init__.py b/mautrix/types/event/__init__.py index b391e912..f5f5e4e9 100644 --- a/mautrix/types/event/__init__.py +++ b/mautrix/types/event/__init__.py @@ -49,6 +49,7 @@ EncryptedFile, FileInfo, Format, + FormatableMessageEventContent, ImageInfo, InReplyTo, JSONWebKey, diff --git a/mautrix/types/event/message.py b/mautrix/types/event/message.py index 8d5f1bba..de409534 100644 --- a/mautrix/types/event/message.py +++ b/mautrix/types/event/message.py @@ -185,6 +185,14 @@ class BaseMessageEventContent(BaseMessageEventContentFuncs): _relates_to: Optional[RelatesTo] = attr.ib(default=None, metadata={"json": "m.relates_to"}) +@dataclass +class FormatableMessageEventContent(BaseMessageEventContent): + """Base event content for events that support formatted_body""" + + formatted_body: str = None + format: Format = None + + # endregion # region Media info @@ -272,12 +280,13 @@ class LocationInfo(SerializableAttrs): @dataclass -class MediaMessageEventContent(BaseMessageEventContent, SerializableAttrs): +class MediaMessageEventContent(FormatableMessageEventContent, SerializableAttrs): """The content of a media message event (m.image, m.audio, m.video, m.file)""" url: Optional[ContentURI] = None info: Optional[MediaInfo] = None file: Optional[EncryptedFile] = None + filename: str = None @staticmethod @deserializer(MediaInfo) @@ -308,12 +317,9 @@ class LocationMessageEventContent(BaseMessageEventContent, SerializableAttrs): @dataclass -class TextMessageEventContent(BaseMessageEventContent, SerializableAttrs): +class TextMessageEventContent(FormatableMessageEventContent, SerializableAttrs): """The content of a text message event (m.text, m.notice, m.emote)""" - format: Format = None - formatted_body: str = None - def set_reply( self, reply_to: Union["MessageEvent", EventID],