fix: Render tg-forward html tags

This commit is contained in:
Krille 2024-01-31 09:06:28 +01:00
parent 21af30e4c5
commit 172cd651fc
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652

View file

@ -156,6 +156,7 @@ class HtmlMessage extends StatelessWidget {
SpoilerExtension(textColor: textColor), SpoilerExtension(textColor: textColor),
const ImageExtension(), const ImageExtension(),
FontColorExtension(), FontColorExtension(),
FallbackTextExtension(fontSize: fontSize),
], ],
onLinkTap: (url, _, element) => UrlLauncher( onLinkTap: (url, _, element) => UrlLauncher(
context, context,
@ -172,6 +173,8 @@ class HtmlMessage extends StatelessWidget {
); );
} }
static const Set<String> fallbackTextTags = {'tg-forward'};
/// Keep in sync with: https://spec.matrix.org/v1.6/client-server-api/#mroommessage-msgtypes /// Keep in sync with: https://spec.matrix.org/v1.6/client-server-api/#mroommessage-msgtypes
static const Set<String> allowedHtmlTags = { static const Set<String> allowedHtmlTags = {
'font', 'font',
@ -217,7 +220,7 @@ class HtmlMessage extends StatelessWidget {
'rp', 'rp',
'rt', 'rt',
// Workaround for https://github.com/krille-chan/fluffychat/issues/507 // Workaround for https://github.com/krille-chan/fluffychat/issues/507
'tg-forward', ...fallbackTextTags,
}; };
} }
@ -410,6 +413,22 @@ class CodeExtension extends HtmlExtension {
); );
} }
class FallbackTextExtension extends HtmlExtension {
final double fontSize;
FallbackTextExtension({required this.fontSize});
@override
Set<String> get supportedTags => HtmlMessage.fallbackTextTags;
@override
InlineSpan build(ExtensionContext context) => TextSpan(
text: context.element?.text ?? '',
style: TextStyle(
fontSize: fontSize,
),
);
}
class RoomPillExtension extends HtmlExtension { class RoomPillExtension extends HtmlExtension {
final Room room; final Room room;
final BuildContext context; final BuildContext context;