better link support

This commit is contained in:
Henry Hiles 2025-11-23 13:43:25 -05:00
commit 7890add93c
No known key found for this signature in database

View file

@ -112,7 +112,8 @@ class RoomChat extends HookConsumerWidget {
builders: Builders( builders: Builders(
chatAnimatedListBuilder: (_, itemBuilder) => chatAnimatedListBuilder: (_, itemBuilder) =>
ChatAnimatedList( ChatAnimatedList(
itemBuilder: itemBuilder, itemBuilder:
itemBuilder, // TODO: Load earlier
onEndReached: notifier.loadOlder, onEndReached: notifier.loadOlder,
onStartReached: () => notifier.markRead(), onStartReached: () => notifier.markRead(),
), ),
@ -130,7 +131,24 @@ class RoomChat extends HookConsumerWidget {
MessageGroupStatus? groupStatus, MessageGroupStatus? groupStatus,
}) => FlyerChatTextMessage( }) => FlyerChatTextMessage(
customWidget: HtmlWidget( customWidget: HtmlWidget(
message.metadata?["formatted"], message.metadata?["formatted"].replaceAllMapped(
RegExp(regexLink, unicode: true),
(match) {
final full = match.group(0)!;
// If no protocol is present, add https://
final hasProtocol =
full.startsWith("http://") ||
full.startsWith("https://") ||
full.startsWith("ftp://");
final url = hasProtocol
? full
: "https://$full";
return "<a href=\"$url\">$full</a>";
},
),
customWidgetBuilder: (element) { customWidgetBuilder: (element) {
if (element.localName == "mx-reply") { if (element.localName == "mx-reply") {
return SizedBox.shrink(); return SizedBox.shrink();