refactor: Always use HtmlMessage
This commit is contained in:
parent
1772fc71df
commit
4739ea42fa
1 changed files with 21 additions and 58 deletions
|
|
@ -2,7 +2,6 @@ import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
|
|
@ -180,46 +179,6 @@ class MessageContent extends StatelessWidget {
|
||||||
textColor: textColor,
|
textColor: textColor,
|
||||||
linkColor: linkColor,
|
linkColor: linkColor,
|
||||||
);
|
);
|
||||||
|
|
||||||
case MessageTypes.Text:
|
|
||||||
case MessageTypes.Notice:
|
|
||||||
case MessageTypes.Emote:
|
|
||||||
if (AppConfig.renderHtml &&
|
|
||||||
!event.redacted &&
|
|
||||||
event.isRichMessage) {
|
|
||||||
var html = event.formattedText;
|
|
||||||
if (event.messageType == MessageTypes.Emote) {
|
|
||||||
html = '* $html';
|
|
||||||
}
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16,
|
|
||||||
vertical: 8,
|
|
||||||
),
|
|
||||||
child: HtmlMessage(
|
|
||||||
html: html,
|
|
||||||
textColor: textColor,
|
|
||||||
room: event.room,
|
|
||||||
fontSize:
|
|
||||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
|
||||||
linkStyle: TextStyle(
|
|
||||||
color: linkColor,
|
|
||||||
fontSize:
|
|
||||||
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
decorationColor: linkColor,
|
|
||||||
),
|
|
||||||
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
|
||||||
eventId: event.eventId,
|
|
||||||
checkboxCheckedEvents: event.aggregatedEvents(
|
|
||||||
timeline,
|
|
||||||
EventCheckboxRoomExtension.relationshipType,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// else we fall through to the normal message rendering
|
|
||||||
continue textmessage;
|
|
||||||
case MessageTypes.BadEncrypted:
|
case MessageTypes.BadEncrypted:
|
||||||
case EventTypes.Encrypted:
|
case EventTypes.Encrypted:
|
||||||
return _ButtonContent(
|
return _ButtonContent(
|
||||||
|
|
@ -264,6 +223,9 @@ class MessageContent extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue textmessage;
|
continue textmessage;
|
||||||
|
case MessageTypes.Text:
|
||||||
|
case MessageTypes.Notice:
|
||||||
|
case MessageTypes.Emote:
|
||||||
case MessageTypes.None:
|
case MessageTypes.None:
|
||||||
textmessage:
|
textmessage:
|
||||||
default:
|
default:
|
||||||
|
|
@ -291,34 +253,35 @@ class MessageContent extends StatelessWidget {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final bigEmotes = event.onlyEmotes &&
|
var html = AppConfig.renderHtml && event.isRichMessage
|
||||||
event.numberEmotes > 0 &&
|
? event.formattedText
|
||||||
event.numberEmotes <= 3;
|
: event.body;
|
||||||
|
if (event.messageType == MessageTypes.Emote) {
|
||||||
|
html = '* $html';
|
||||||
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 16,
|
horizontal: 16,
|
||||||
vertical: 8,
|
vertical: 8,
|
||||||
),
|
),
|
||||||
child: Linkify(
|
child: HtmlMessage(
|
||||||
text: event.calcLocalizedBodyFallback(
|
html: html,
|
||||||
MatrixLocals(L10n.of(context)),
|
textColor: textColor,
|
||||||
hideReply: true,
|
room: event.room,
|
||||||
),
|
fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||||
textScaleFactor: MediaQuery.textScalerOf(context).scale(1),
|
|
||||||
style: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
fontSize: bigEmotes ? fontSize * 5 : fontSize,
|
|
||||||
decoration:
|
|
||||||
event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
options: const LinkifyOptions(humanize: false),
|
|
||||||
linkStyle: TextStyle(
|
linkStyle: TextStyle(
|
||||||
color: linkColor,
|
color: linkColor,
|
||||||
fontSize: fontSize,
|
fontSize:
|
||||||
|
AppConfig.fontSizeFactor * AppConfig.messageFontSize,
|
||||||
decoration: TextDecoration.underline,
|
decoration: TextDecoration.underline,
|
||||||
decorationColor: linkColor,
|
decorationColor: linkColor,
|
||||||
),
|
),
|
||||||
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
||||||
|
eventId: event.eventId,
|
||||||
|
checkboxCheckedEvents: event.aggregatedEvents(
|
||||||
|
timeline,
|
||||||
|
EventCheckboxRoomExtension.relationshipType,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue