support for m.emote msgtype

This commit is contained in:
Henry Hiles 2026-05-19 11:23:38 -04:00
commit f9b1960cf8
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
2 changed files with 28 additions and 5 deletions

View file

@ -25,6 +25,13 @@ abstract class MessageContent extends Content with _$MessageContent {
String? formattedBody, String? formattedBody,
}) = NoticeMessageContent; }) = NoticeMessageContent;
@FreezedUnionValue("m.emote")
factory MessageContent.emote({
required String body,
String? format,
String? formattedBody,
}) = EmoteMessageContent;
@FreezedUnionValue("m.image") @FreezedUnionValue("m.image")
factory MessageContent.image({ factory MessageContent.image({
required String body, required String body,

View file

@ -62,6 +62,11 @@ class RenderEvent extends ConsumerWidget {
children: getEventOptions!(event).toList(), children: getEventOptions!(event).toList(),
); );
final textStyle = TextStyle(
fontSize: event.localContent?.bigEmoji == true ? 32 : null,
fontStyle: event.content is EmoteMessageContent ? FontStyle.italic : null,
);
if (event.redactedBy != null) return SizedBox.shrink(); if (event.redactedBy != null) return SizedBox.shrink();
final child = switch (event.content) { final child = switch (event.content) {
@ -132,6 +137,11 @@ class RenderEvent extends ConsumerWidget {
:final formattedBody, :final formattedBody,
:final format, :final format,
) || ) ||
EmoteMessageContent(
:final body,
:final formattedBody,
:final format,
) ||
ImageMessageContent( ImageMessageContent(
:final body, :final body,
:final formattedBody, :final formattedBody,
@ -141,10 +151,7 @@ class RenderEvent extends ConsumerWidget {
children: [ children: [
format == "org.matrix.custom.html" && !textOnly format == "org.matrix.custom.html" && !textOnly
? Html( ? Html(
textStyle: textStyle: textStyle,
event.localContent?.bigEmoji == true
? TextStyle(fontSize: 32)
: null,
formattedBody!.replaceAllMapped( formattedBody!.replaceAllMapped(
RegExp( RegExp(
"(<a\\b[^>]*>.*?<\\/a>)|(\\bhttps?:\\/\\/[^\\s<]+)", "(<a\\b[^>]*>.*?<\\/a>)|(\\bhttps?:\\/\\/[^\\s<]+)",
@ -164,6 +171,7 @@ class RenderEvent extends ConsumerWidget {
), ),
) )
: Linkify( : Linkify(
style: textStyle,
text: body, text: body,
maxLines: maxLines, maxLines: maxLines,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
@ -263,7 +271,15 @@ class RenderEvent extends ConsumerWidget {
LinkPreview(link.url), LinkPreview(link.url),
], ],
), ),
_ => Text("Unknown message type", style: errorStyle), MessageContent(:final body) => Row(
spacing: 8,
mainAxisSize: MainAxisSize.min,
children: [
Text("Unknown message type:", style: errorStyle),
Text(body),
],
),
_ => throw Exception("This is impossible"),
}, },
], ],
), ),