Skip to content

Commit

Permalink
Support MSC2530 fields in media event types
Browse files Browse the repository at this point in the history
Add `filename`, `format` and `formatted_body` to media event content
types.

Signed-off-by: Joe Groocock <[email protected]>
  • Loading branch information
frebib committed Mar 22, 2024
1 parent 47e2157 commit f0efa77
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions mautrix/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
EventType,
FileInfo,
Format,
FormatableMessageEventContent,
ForwardedRoomKeyEventContent,
GenericEvent,
ImageInfo,
Expand Down
1 change: 1 addition & 0 deletions mautrix/types/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
EncryptedFile,
FileInfo,
Format,
FormatableMessageEventContent,
ImageInfo,
InReplyTo,
JSONWebKey,
Expand Down
16 changes: 11 additions & 5 deletions mautrix/types/event/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit f0efa77

Please sign in to comment.