From 45658a7612de311b7bb2dba456c09eebfa6d10d9 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Sun, 5 Apr 2026 22:39:20 -0400 Subject: [PATCH] Understand more kinds of Giphy reference as GIF This adds Giphy page URLs and `media.giphy.com` URLs (with and without protocols) as *accepted* encodings for GIF messages, alongside the `g:` syntax. When someone posts such a URL by itself as a message, it will be rendered inline just like `g:` messages are now. This does not change the encoding that GIF messages are *sent* in; that is still the `g:` syntax. --- lib/screens/chat_screen.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 372e3e7..ec1116c 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -601,7 +601,23 @@ class _ChatScreenState extends State { String? _parseGifId(String text) { final trimmed = text.trim(); final match = RegExp(r'^g:([A-Za-z0-9_-]+)$').firstMatch(trimmed); - return match?.group(1); + if (match != null) { + return match.group(1); + } + final directUrlMatch = RegExp( + r'^(?:https?://)?media\.giphy\.com/media/([A-Za-z0-9_-]+)/giphy\.gif$', + ).firstMatch(trimmed); + if (directUrlMatch != null) { + return directUrlMatch.group(1); + } + // Giphy understands page URLs with just the ID, or any string and a + // dash before the ID, and redirects to a page with a dash-separated + // title, a dash, and the ID. IDs in this form *probably* can't + // contain dashes. + final pageMatch = RegExp( + r'^(?:https?://)?giphy\.com/gifs/(?:[^/?]*-)?([A-Za-z0-9_]+)/?$', + ).firstMatch(trimmed); + return pageMatch?.group(1); } void _showGifPicker(BuildContext context) {