mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
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:
parent
10b63e0df2
commit
45658a7612
1 changed files with 17 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue