[PATCH] page/buffer: Support link previews in compact mode
Export this patch
---
The display code is just copied over from the non compact view for now.
Pushed, thanks!
lib/page/buffer.dart | 30 +++++++++++++++++++++++++++---
lib/page/settings.dart | 2 +-
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/lib/page/buffer.dart b/lib/page/buffer.dart
index 80641ed..58a548f 100644
--- a/lib/page/buffer.dart
+++ b/lib/page/buffer.dart
@@ -415,6 +415,7 @@ class _CompactMessageItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ var prefs = context.read<Prefs>();
var ircMsg = msg.msg;
var entry = msg.entry;
var sender = ircMsg.source!.name;
@@ -427,17 +428,20 @@ class _CompactMessageItem extends StatelessWidget {
var textStyle = TextStyle(color: Theme.of(context).textTheme.bodyText1!.color);
+ String? text;
List<TextSpan> textSpans;
if (ctcp != null && ctcp.cmd == 'ACTION') {
textStyle = textStyle.apply(fontStyle: FontStyle.italic);
if (ctcp.cmd == 'ACTION') {
- textSpans = applyAnsiFormatting(ctcp.param ?? '', textStyle);
+ text = ctcp.param;
+ textSpans = applyAnsiFormatting(text ?? '', textStyle);
} else {
textSpans = [TextSpan(text: 'has sent a CTCP "${ctcp.cmd}" command', style: textStyle)];
}
} else {
- textSpans = applyAnsiFormatting(ircMsg.params[1], textStyle);
+ text = ircMsg.params[1];
+ textSpans = applyAnsiFormatting(text, textStyle);
}
textSpans = textSpans.map((span) {
@@ -490,9 +494,29 @@ class _CompactMessageItem extends StatelessWidget {
),
));
+ Widget? linkPreview;
+ if (prefs.linkPreview && text != null) {
+ var body = stripAnsiFormatting(text);
+ linkPreview = LinkPreview(
+ text: body,
+ builder: (context, child) {
+ return Align(alignment: Alignment.center, child: Container(
+ margin: EdgeInsets.symmetric(vertical: 5),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(10),
+ child: child,
+ ),
+ ));
+ },
+ );
+ }
+
return Container(
margin: EdgeInsets.only(top: prevMsgSameSender ? 0 : 2.5, bottom: last ? 10 : 0, left: 4, right: 5),
- child: Stack(children: stack),
+ child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
+ Stack(children: stack),
+ if (linkPreview != null) linkPreview,
+ ]),
);
}
}
diff --git a/lib/page/settings.dart b/lib/page/settings.dart
index cda1e8c..b0c9002 100644
--- a/lib/page/settings.dart
+++ b/lib/page/settings.dart
@@ -164,7 +164,7 @@ class _SettingsPageState extends State<SettingsPage> {
});
},
),
- if (!_compact) SwitchListTile(
+ SwitchListTile(
title: Text('Display link previews'),
subtitle: Text('Retrieve link previews directly from websites for messages you receive. Privacy-conscious users may want to leave this off.'),
secondary: Icon(Icons.preview),
base-commit: c4df7fe91caae2ba0f4d3af0df8fb62757556790
--
2.17.1