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.
This commit is contained in:
Adam Novak 2026-04-05 22:39:20 -04:00
parent 10b63e0df2
commit 45658a7612

View file

@ -601,7 +601,23 @@ class _ChatScreenState extends State<ChatScreen> {
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) {