Skip to content

Commit 318f327

Browse files
chrisbobbegnprice
authored andcommitted
content: Handle image emoji
1 parent 7eb4451 commit 318f327

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

lib/model/content.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ class UnicodeEmojiNode extends EmojiNode {
177177
}
178178

179179
class ImageEmojiNode extends EmojiNode {
180-
const ImageEmojiNode({super.debugHtmlNode, required this.alt});
180+
const ImageEmojiNode({super.debugHtmlNode, required this.src, required this.alt });
181181

182-
final String alt; // TODO parse actual emoji image URL
182+
final String src;
183+
final String alt;
183184
}
184185

185186
////////////////////////////////////////////////////////////////
@@ -246,7 +247,9 @@ InlineContentNode parseInlineContent(dom.Node node) {
246247
&& classes.length == 1) {
247248
final alt = element.attributes['alt'];
248249
if (alt == null) return unimplemented();
249-
return ImageEmojiNode(alt: alt, debugHtmlNode: debugHtmlNode);
250+
final src = element.attributes['src'];
251+
if (src == null) return unimplemented();
252+
return ImageEmojiNode(src: src, alt: alt, debugHtmlNode: debugHtmlNode);
250253
}
251254

252255
// TODO more types of node

lib/widgets/content.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,27 @@ class MessageImageEmoji extends StatelessWidget {
439439

440440
@override
441441
Widget build(BuildContext context) {
442-
// TODO show actual emoji image
443-
final alt = node.alt;
444-
return Container(
445-
padding: const EdgeInsets.all(2),
446-
decoration: BoxDecoration(
447-
color: Colors.white, border: Border.all(color: Colors.purple)),
448-
child: Text(alt));
442+
final store = PerAccountStoreWidget.of(context);
443+
final adjustedSrc = rewriteImageUrl(node.src, store.account);
444+
445+
const size = 20.0;
446+
447+
return Stack(
448+
alignment: Alignment.center,
449+
clipBehavior: Clip.none,
450+
children: [
451+
const SizedBox(width: size, height: kBaseFontSize),
452+
Positioned(
453+
// Web's css makes this seem like it should be -0.5, but that looks
454+
// too low.
455+
top: -1.5,
456+
child: Image.network(
457+
adjustedSrc.toString(),
458+
filterQuality: FilterQuality.medium,
459+
width: size,
460+
height: size,
461+
)),
462+
]);
449463
}
450464
}
451465

0 commit comments

Comments
 (0)