Add HTML render

This commit is contained in:
Sorunome
2020-05-09 11:36:41 +00:00
committed by Christian Pauly
parent eb72198048
commit 3ee1018eb5
12 changed files with 167 additions and 21 deletions

View File

@ -2,6 +2,9 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:flutter/material.dart';
import 'html_message.dart';
import 'matrix.dart';
class ReplyContent extends StatelessWidget {
final Event replyEvent;
final bool lightText;
@ -11,6 +14,40 @@ class ReplyContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget replyBody;
if (
replyEvent != null && Matrix.of(context).renderHtml &&
[EventTypes.Message, EventTypes.Encrypted].contains(replyEvent.type) &&
[MessageTypes.Text, MessageTypes.Notice, MessageTypes.Emote].contains(replyEvent.messageType) &&
!replyEvent.redacted && replyEvent.content['format'] == 'org.matrix.custom.html' && replyEvent.content['formatted_body'] is String
) {
String html = replyEvent.content['formatted_body'];
if (replyEvent.messageType == MessageTypes.Emote) {
html = "* $html";
}
replyBody = HtmlMessage(
html: html,
textColor: lightText
? Colors.white
: Theme.of(context).textTheme.bodyText2.color,
maxLines: 1,
);
} else {
replyBody = Text(
replyEvent?.getLocalizedBody(
L10n.of(context),
withSenderNamePrefix: false,
hideReply: true,
) ??
"",
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
color: lightText
? Colors.white
: Theme.of(context).textTheme.bodyText2.color),
);
}
return Row(
children: <Widget>[
Container(
@ -34,20 +71,7 @@ class ReplyContent extends StatelessWidget {
lightText ? Colors.white : Theme.of(context).primaryColor,
),
),
Text(
replyEvent?.getLocalizedBody(
L10n.of(context),
withSenderNamePrefix: false,
hideReply: true,
) ??
"",
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
color: lightText
? Colors.white
: Theme.of(context).textTheme.bodyText2.color),
),
replyBody,
],
),
),