diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index ac3b4792..e4ef43fb 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts index fb605bc8..ca7fe065 100644 --- a/android/settings.gradle.kts +++ b/android/settings.gradle.kts @@ -19,8 +19,8 @@ pluginManagement { plugins { id("dev.flutter.flutter-plugin-loader") version "1.0.0" - id("com.android.application") version "8.9.1" apply false - id("org.jetbrains.kotlin.android") version "2.1.0" apply false + id("com.android.application") version "8.11.1" apply false + id("org.jetbrains.kotlin.android") version "2.2.20" apply false } include(":app") diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index a2b07bf5..37198761 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -375,12 +375,14 @@ class MeshCoreConnector extends ChangeNotifier { List _cachedChannels = []; final Map _channelSmazEnabled = {}; final Map _channelCyr2LatEnabled = {}; + final Map _channelUrlImagesEnabled = {}; final Map _channelCyr2LatProfileId = {}; final Map _channelRegions = {}; bool _lastSentWasCliCommand = false; // Track if last sent message was a CLI command final Map _contactSmazEnabled = {}; final Map _contactCyr2LatEnabled = {}; + final Map _contactUrlImagesEnabled = {}; final Map _contactCyr2LatProfileId = {}; final Set _knownContactKeys = {}; final Map _contactUnreadCount = {}; @@ -789,6 +791,15 @@ class MeshCoreConnector extends ChangeNotifier { return _contactSmazEnabled[contactKeyHex] ?? false; } + bool isChannelUrlImagesEnabled(int channelIndex) { + return _channelUrlImagesEnabled[channelIndex] ?? false; + } + + bool isContactUrlImagesEnabled(String contactKeyHex) { + _ensureContactUrlImagesSettingLoaded(contactKeyHex); + return _contactUrlImagesEnabled[contactKeyHex] ?? false; + } + bool hasChannelRegion(int channelIndex) { return (_channelRegions[channelIndex] ?? '').isNotEmpty; } @@ -931,6 +942,24 @@ class MeshCoreConnector extends ChangeNotifier { notifyListeners(); } + Future setChannelUrlImagesEnabled( + int channelIndex, + bool enabled, + ) async { + _channelUrlImagesEnabled[channelIndex] = enabled; + await _channelSettingsStore.saveUrlImagesEnabled(channelIndex, enabled); + notifyListeners(); + } + + Future setContactUrlImagesEnabled( + String contactKeyHex, + bool enabled, + ) async { + _contactUrlImagesEnabled[contactKeyHex] = enabled; + await _contactSettingsStore.saveUrlImagesEnabled(contactKeyHex, enabled); + notifyListeners(); + } + Future setChannelCyr2LatEnabled(int channelIndex, bool enabled) async { _channelCyr2LatEnabled[channelIndex] = enabled; if (enabled) { @@ -1101,6 +1130,7 @@ class MeshCoreConnector extends ChangeNotifier { } Future loadContactCache() async { + _contactUrlImagesEnabled.clear(); final cached = await _contactStore.loadContacts(); _knownContactKeys ..clear() @@ -1111,6 +1141,7 @@ class MeshCoreConnector extends ChangeNotifier { for (final contact in cached) { _ensureContactSmazSettingLoaded(contact.publicKeyHex); _ensureContactCyr2LatSettingLoaded(contact.publicKeyHex); + _ensureContactUrlImagesSettingLoaded(contact.publicKeyHex); } } @@ -1131,12 +1162,15 @@ class MeshCoreConnector extends ChangeNotifier { Future loadChannelSettings({int? maxChannels}) async { _channelSmazEnabled.clear(); _channelCyr2LatEnabled.clear(); + _channelUrlImagesEnabled.clear(); _channelRegions.clear(); final channelCount = maxChannels ?? _maxChannels; for (int i = 0; i < channelCount; i++) { _channelSmazEnabled[i] = await _channelSettingsStore.loadSmazEnabled(i); _channelCyr2LatEnabled[i] = await _channelSettingsStore .loadCyr2LatEnabled(i); + _channelUrlImagesEnabled[i] = await _channelSettingsStore + .loadUrlImagesEnabled(i); _channelRegions[i] = await _channelRegionStore.loadRegion(i); } } @@ -5329,6 +5363,8 @@ class MeshCoreConnector extends ChangeNotifier { await _notificationService.showMessageNotification( contactName: c?.name ?? 'Unknown', message: resolvedText, + urlImagesEnabled: + c != null && isContactUrlImagesEnabled(c.publicKeyHex), contactId: msg.senderKeyHex, badgeCount: getTotalUnreadCount(), ); @@ -5343,6 +5379,8 @@ class MeshCoreConnector extends ChangeNotifier { await _notificationService.showMessageNotification( contactName: c?.name ?? 'Unknown Room', message: resolvedText, + urlImagesEnabled: + c != null && isContactUrlImagesEnabled(c.publicKeyHex), contactId: msg.senderKeyHex, badgeCount: getTotalUnreadCount(), ); @@ -5493,6 +5531,15 @@ class MeshCoreConnector extends ChangeNotifier { }); } + void _ensureContactUrlImagesSettingLoaded(String contactKeyHex) { + if (_contactUrlImagesEnabled.containsKey(contactKeyHex)) return; + _contactSettingsStore.loadUrlImagesEnabled(contactKeyHex).then((enabled) { + if (_contactUrlImagesEnabled[contactKeyHex] == enabled) return; + _contactUrlImagesEnabled[contactKeyHex] = enabled; + notifyListeners(); + }); + } + void _ensureContactCyr2LatProfileLoaded(String contactKeyHex) { if (_contactCyr2LatProfileId.containsKey(contactKeyHex)) return; _contactSettingsStore.loadCyr2LatProfileId(contactKeyHex).then((profileId) { @@ -5647,6 +5694,7 @@ class MeshCoreConnector extends ChangeNotifier { channelName: label, senderName: message.senderName, message: resolvedText, + urlImagesEnabled: isChannelUrlImagesEnabled(channelIndex), channelIndex: message.channelIndex, badgeCount: getTotalUnreadCount(), ); diff --git a/lib/helpers/message_url_image_helper.dart b/lib/helpers/message_url_image_helper.dart new file mode 100644 index 00000000..d917af6d --- /dev/null +++ b/lib/helpers/message_url_image_helper.dart @@ -0,0 +1,338 @@ +import 'dart:async'; +import 'dart:collection'; + +import 'package:flutter/material.dart'; +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:http/http.dart' as http; + +/// Finds and renders image URLs embedded in ordinary text messages. +/// +/// This is deliberately separate from MeshCore's transmitted channel-image +/// protocol, which is handled by [ReceivedImageStore]. +class MessageUrlImageHelper { + static final Map> _verifiedImageCache = + >{}; + static const int _maxMessageImageCacheEntries = 200; + static final LinkedHashMap> _messageImageCache = + LinkedHashMap>(); + + static final RegExp _pyxPattern = RegExp( + r'''https?://pyx\.li/\?i=([^\s<>'"`]+)''', + caseSensitive: false, + ); + + static final RegExp _ipfsUrlPattern = RegExp( + r'''https?://[^\s<>'"`]+/(?:ipfs|ipns)/[^\s<>'"`]+''', + caseSensitive: false, + ); + + static final RegExp _ipfsCidPattern = RegExp( + r'''ipfs:(?://)?([^\s<>'"`]+)''', + caseSensitive: false, + ); + + static final RegExp _ibbSharePattern = RegExp( + r'''https?://(?:www\.)?ibb\.co/[^\s<>'"`/?#]+(?:[/?#][^\s<>'"`]*)?''', + caseSensitive: false, + ); + + static final RegExp _imagePattern = RegExp( + r'''https?://[^\s<>'"`]+?\.(?:png|jpe?g|webp)(?:\?[^\s<>'"`]+)?(?:#[^\s<>'"`]+)?''', + caseSensitive: false, + ); + + /// Checks locally whether [text] contains a URL format this helper supports. + /// This deliberately does not resolve sharing pages or fetch image data. + static bool hasPotentialImageUrl(String text) { + return _pyxPattern.hasMatch(text) || + _ipfsUrlPattern.hasMatch(text) || + _ipfsCidPattern.hasMatch(text) || + _ibbSharePattern.hasMatch(text) || + _imagePattern.hasMatch(text); + } + + static Future parse(String text) async { + final trimmed = text.trim(); + if (trimmed.isEmpty) return null; + + final pyxMatch = _pyxPattern.firstMatch(trimmed); + if (pyxMatch != null) { + return _extractFromUrl( + _trimBoundary(pyxMatch.group(0)!), + RegExp(r''']+src=["']([^"']+)["']''', caseSensitive: false), + ); + } + + final ipfsUrlMatch = _ipfsUrlPattern.firstMatch(trimmed); + if (ipfsUrlMatch != null) { + return _trimBoundary(ipfsUrlMatch.group(0)!); + } + + final ipfsCidMatch = _ipfsCidPattern.firstMatch(trimmed); + if (ipfsCidMatch != null) { + final cid = _trimBoundary(ipfsCidMatch.group(1)!); + return 'https://ipfs.io/ipfs/$cid'; + } + + final ibbMatch = _ibbSharePattern.firstMatch(trimmed); + if (ibbMatch != null) { + return _extractFromUrl( + _trimBoundary(ibbMatch.group(0)!), + RegExp( + r''']+property=["']og:image["'][^>]+content=["']([^"']+)["']''', + caseSensitive: false, + ), + ); + } + + final imageMatch = _imagePattern.firstMatch(trimmed); + if (imageMatch != null) { + return _trimBoundary(imageMatch.group(0)!); + } + + return null; + } + + static Future parseVerified(String text) async { + final imageUrl = await parse(text); + if (imageUrl == null) return null; + + final verified = await _verifyImageUrl(imageUrl); + return verified ? imageUrl : null; + } + + /// Caches successful URL-image parsing by stable message identity. + /// + /// Null results are evicted so temporary connectivity or host failures can + /// be retried when a message is shown again. + static Future parseVerifiedForMessage( + String messageId, + String text, + ) { + final cached = _messageImageCache.remove(messageId); + if (cached != null) { + _messageImageCache[messageId] = cached; + return cached; + } + + final parsing = parseVerified(text); + _messageImageCache[messageId] = parsing; + parsing.then((imageUrl) { + if (imageUrl == null && + identical(_messageImageCache[messageId], parsing)) { + _messageImageCache.remove(messageId); + } else if (imageUrl != null) { + while (_messageImageCache.length > _maxMessageImageCacheEntries) { + _messageImageCache.remove(_messageImageCache.keys.first); + } + } + }); + return parsing; + } + + static Future _extractFromUrl(String pageUrl, RegExp pattern) async { + try { + final response = await http + .get(Uri.parse(pageUrl)) + .timeout(const Duration(seconds: 8)); + if (response.statusCode < 200 || response.statusCode >= 300) { + return null; + } + final value = pattern.firstMatch(response.body)?.group(1); + if (value == null || value.isEmpty) return null; + + final imageUrl = Uri.parse( + pageUrl, + ).resolve(value.replaceAll('&', '&')); + return imageUrl.scheme == 'http' || imageUrl.scheme == 'https' + ? imageUrl.toString() + : null; + } catch (_) { + return null; + } + } + + static String _trimBoundary(String value) { + return value.trim().replaceAll(RegExp(r"[.,;:!?]+$"), ''); + } + + static Future _verifyImageUrl(String imageUrl) { + final cached = _verifiedImageCache[imageUrl]; + if (cached != null) return cached; + + final verification = _tryLoadImage(imageUrl); + _verifiedImageCache[imageUrl] = verification; + verification.then((verified) { + if (!verified && identical(_verifiedImageCache[imageUrl], verification)) { + _verifiedImageCache.remove(imageUrl); + } + }); + return verification; + } + + static Future _tryLoadImage(String imageUrl) async { + final completer = Completer(); + final stream = CachedNetworkImageProvider( + imageUrl, + ).resolve(const ImageConfiguration()); + + late final ImageStreamListener listener; + listener = ImageStreamListener( + (_, _) { + if (!completer.isCompleted) completer.complete(true); + stream.removeListener(listener); + }, + onError: (_, _) { + if (!completer.isCompleted) completer.complete(false); + stream.removeListener(listener); + }, + ); + + stream.addListener(listener); + + return completer.future.timeout( + const Duration(seconds: 8), + onTimeout: () { + stream.removeListener(listener); + return false; + }, + ); + } +} + +class MessageUrlImageFutureBuilder extends StatefulWidget { + const MessageUrlImageFutureBuilder({ + super.key, + required this.messageId, + required this.text, + required this.builder, + }); + + final String messageId; + final String text; + final AsyncWidgetBuilder builder; + + @override + State createState() => + _MessageUrlImageFutureBuilderState(); +} + +class _MessageUrlImageFutureBuilderState + extends State { + late Future _imageFuture; + + @override + void initState() { + super.initState(); + _imageFuture = MessageUrlImageHelper.parseVerifiedForMessage( + widget.messageId, + widget.text, + ); + } + + @override + void didUpdateWidget(covariant MessageUrlImageFutureBuilder oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.messageId != widget.messageId) { + _imageFuture = MessageUrlImageHelper.parseVerifiedForMessage( + widget.messageId, + widget.text, + ); + } + } + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: _imageFuture, + builder: widget.builder, + ); + } +} + +class MessageUrlImagePreview extends StatelessWidget { + const MessageUrlImagePreview({super.key, required this.imageUrl}); + + final String imageUrl; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () { + showDialog( + context: context, + builder: (context) => Dialog( + insetPadding: const EdgeInsets.all(12), + backgroundColor: Colors.black, + child: SizedBox( + width: double.infinity, + height: double.infinity, + child: Stack( + children: [ + Positioned.fill( + child: InteractiveViewer( + boundaryMargin: const EdgeInsets.all(80), + minScale: 1.0, + maxScale: 3.0, + child: Center( + child: CachedNetworkImage( + imageUrl: imageUrl, + fit: BoxFit.contain, + placeholder: (context, url) => const Center( + child: CircularProgressIndicator(strokeWidth: 2), + ), + errorWidget: (context, url, error) => const Center( + child: Icon( + Icons.broken_image, + color: Colors.white, + ), + ), + ), + ), + ), + ), + Positioned( + top: 12, + right: 12, + child: IconButton( + onPressed: () => Navigator.of(context).pop(), + icon: const Icon(Icons.close, color: Colors.white), + style: IconButton.styleFrom( + backgroundColor: Colors.black54, + ), + ), + ), + ], + ), + ), + ), + ); + }, + child: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: SizedBox( + width: 240, + height: 240, + child: CachedNetworkImage( + imageUrl: imageUrl, + fit: BoxFit.contain, + placeholder: (context, url) => ColoredBox( + color: Theme.of(context).colorScheme.surfaceContainerHighest, + child: const Center( + child: CircularProgressIndicator(strokeWidth: 2), + ), + ), + errorWidget: (context, url, error) => Container( + padding: const EdgeInsets.all(12), + color: Theme.of(context).colorScheme.surfaceContainerHighest, + child: Text( + 'Unable to load image', + style: Theme.of(context).textTheme.bodySmall, + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 101f6c42..cc34c09e 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -2626,6 +2626,8 @@ "messageStatus_pending": "Wird gesendet", "messageStatus_failed": "Senden fehlgeschlagen", "messageStatus_repeated": "Mehrfach gehört", + "urlImage_enable": "URL-Bilder anzeigen", + "urlImage_possible": "Mögliches URL-Bild; in den Einstellungen aktivieren.", "contacts_moreOptions": "Weitere Optionen", "contacts_searchOpen": "Suche öffnen", "contacts_searchClose": "Suche schließen", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 447736b2..bc5098f8 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -34,6 +34,8 @@ "messageStatus_pending": "Sending", "messageStatus_failed": "Failed to send", "messageStatus_repeated": "Heard repeated", + "urlImage_enable": "Enable URL images", + "urlImage_possible": "Possible URL image; enable it in Settings.", "common_reboot": "Reboot", "common_loading": "Loading...", "common_notAvailable": "—", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 0020c553..20dbfc3a 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -334,6 +334,18 @@ abstract class AppLocalizations { /// **'Heard repeated'** String get messageStatus_repeated; + /// No description provided for @urlImage_enable. + /// + /// In en, this message translates to: + /// **'Enable URL images'** + String get urlImage_enable; + + /// No description provided for @urlImage_possible. + /// + /// In en, this message translates to: + /// **'Possible URL image; enable it in Settings.'** + String get urlImage_possible; + /// No description provided for @common_reboot. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index 2167179a..8c32d7e6 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -110,6 +110,12 @@ class AppLocalizationsBg extends AppLocalizations { @override String get messageStatus_repeated => 'Повторно чуто'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Рестартирай'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 6efc6f8a..8e24579e 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -110,6 +110,13 @@ class AppLocalizationsDe extends AppLocalizations { @override String get messageStatus_repeated => 'Mehrfach gehört'; + @override + String get urlImage_enable => 'URL-Bilder anzeigen'; + + @override + String get urlImage_possible => + 'Mögliches URL-Bild; in den Einstellungen aktivieren.'; + @override String get common_reboot => 'Neustart'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 028060f8..91534db3 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -110,6 +110,12 @@ class AppLocalizationsEn extends AppLocalizations { @override String get messageStatus_repeated => 'Heard repeated'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Reboot'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 52ca6fa3..ceeaf7ac 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -110,6 +110,12 @@ class AppLocalizationsEs extends AppLocalizations { @override String get messageStatus_repeated => 'Escuchado repetidamente'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Reiniciar'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 7802013a..9732f8c7 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -110,6 +110,12 @@ class AppLocalizationsFr extends AppLocalizations { @override String get messageStatus_repeated => 'Reçu plusieurs fois'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Redémarrer'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index de0948b0..f5af9446 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -110,6 +110,12 @@ class AppLocalizationsHu extends AppLocalizations { @override String get messageStatus_repeated => '– ismételte Heard'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Indítsa újra'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 86fad8fc..51811401 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -110,6 +110,12 @@ class AppLocalizationsIt extends AppLocalizations { @override String get messageStatus_repeated => 'Ricevuto ripetutamente'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Riavvia'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index b4cdf527..e5e5ddc2 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -110,6 +110,12 @@ class AppLocalizationsJa extends AppLocalizations { @override String get messageStatus_repeated => '何度も聞いた'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => '再起動'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 81e09968..a3b30012 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -110,6 +110,12 @@ class AppLocalizationsKo extends AppLocalizations { @override String get messageStatus_repeated => '반복 수신됨'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => '재부팅'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index ba3a72f1..905eee47 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -110,6 +110,12 @@ class AppLocalizationsNl extends AppLocalizations { @override String get messageStatus_repeated => 'Hearsay, herhaald'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Herstarten'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 28f4fa8a..3317d9fb 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -110,6 +110,12 @@ class AppLocalizationsPl extends AppLocalizations { @override String get messageStatus_repeated => 'Usłyszałem to wielokrotnie'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Uruchom ponownie'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 7e43e870..969266a2 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -110,6 +110,12 @@ class AppLocalizationsPt extends AppLocalizations { @override String get messageStatus_repeated => 'Ouvi repetidamente'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Reiniciar'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index c799292f..eb9b5fc6 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -110,6 +110,12 @@ class AppLocalizationsRu extends AppLocalizations { @override String get messageStatus_repeated => 'Услышал несколько раз'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Перезагрузить'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 6caa811b..2d747521 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -110,6 +110,12 @@ class AppLocalizationsSk extends AppLocalizations { @override String get messageStatus_repeated => 'Slyšal som to opakovane'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Restartovať'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index d1dcc927..9a976f1e 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -111,6 +111,12 @@ class AppLocalizationsSl extends AppLocalizations { @override String get messageStatus_repeated => 'Slišal sem večkrat'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Ponoviti'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 54afa3af..de522619 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -110,6 +110,12 @@ class AppLocalizationsSv extends AppLocalizations { @override String get messageStatus_repeated => 'Hördes upprepade gånger'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Start om'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 14a168ee..63735000 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -110,6 +110,12 @@ class AppLocalizationsUk extends AppLocalizations { @override String get messageStatus_repeated => 'Почув неодноразово'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => 'Перезавантажити'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index b2abbaa1..07725428 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -110,6 +110,12 @@ class AppLocalizationsZh extends AppLocalizations { @override String get messageStatus_repeated => '多次听到'; + @override + String get urlImage_enable => 'Enable URL images'; + + @override + String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override String get common_reboot => '重启'; diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index abceff4c..fc8a4460 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -18,6 +18,7 @@ import '../helpers/chat_scroll_controller.dart'; import '../connector/meshcore_protocol.dart'; import '../helpers/cyr2lat.dart'; import '../helpers/gif_helper.dart'; +import '../helpers/message_url_image_helper.dart'; import '../helpers/path_helper.dart'; import '../helpers/reaction_helper.dart'; import '../helpers/snack_bar_builder.dart'; @@ -412,6 +413,9 @@ class _ChannelChatScreenState extends State { ); } + final urlImagesEnabled = connector.isChannelUrlImagesEnabled( + widget.channel.index, + ); // Images are not ChannelMessages: they arrive as GRP_DATA // chunks and are owned by ReceivedImageStore, so the two // sources are merged here in timestamp order and the list @@ -500,7 +504,11 @@ class _ChannelChatScreenState extends State { ); final message = row.message; final bubble = message != null - ? _buildMessageBubble(message, textScale) + ? _buildMessageBubble( + message, + textScale, + urlImagesEnabled, + ) : _buildImageBubble( row.image!, textScale, @@ -543,7 +551,11 @@ class _ChannelChatScreenState extends State { connector.setChannelUnreadCount(widget.channel.index, count); } - Widget _buildMessageBubble(ChannelMessage message, double textScale) { + Widget _buildMessageBubble( + ChannelMessage message, + double textScale, + bool urlImagesEnabled, + ) { final settingsService = context.watch(); final enableTracing = settingsService.settings.enableMessageTracing; final isOutgoing = message.isOutgoing; @@ -583,6 +595,33 @@ class _ChannelChatScreenState extends State { final metaColor = textColor.withValues(alpha: 0.65); const bodyFontSize = 14.0; + Widget buildTextContent() { + return Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Flexible( + child: TranslatedMessageContent( + displayText: translatedDisplayText, + originalText: originalDisplayText, + style: TextStyle( + color: textColor, + fontSize: bodyFontSize * textScale, + ), + originalStyle: TextStyle( + fontSize: bodyFontSize * textScale, + fontStyle: FontStyle.italic, + color: textColor.withValues(alpha: 0.72), + ), + onSecondaryTap: PlatformInfo.isDesktop + ? () => _showMessageActions(message) + : null, + ), + ), + ], + ); + } + // Asymmetric radius matching chat_screen bubbles. final borderRadius = isOutgoing ? const BorderRadius.only( @@ -688,29 +727,76 @@ class _ChannelChatScreenState extends State { ), ], ) + else if (urlImagesEnabled) + MessageUrlImageFutureBuilder( + messageId: message.messageId, + text: message.text, + builder: (context, snapshot) { + final imageAttachment = snapshot.data; + + if (imageAttachment != null) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + vertical: 4, + ), + child: Align( + alignment: isOutgoing + ? Alignment.centerRight + : Alignment.centerLeft, + child: MessageUrlImagePreview( + imageUrl: imageAttachment, + ), + ), + ), + Padding( + padding: const EdgeInsets.only(top: 8), + child: TranslatedMessageContent( + displayText: translatedDisplayText, + originalText: originalDisplayText, + style: TextStyle( + color: textColor, + fontSize: bodyFontSize * textScale, + ), + originalStyle: TextStyle( + fontSize: bodyFontSize * textScale, + fontStyle: FontStyle.italic, + color: textColor.withValues( + alpha: 0.72, + ), + ), + onSecondaryTap: PlatformInfo.isDesktop + ? () => _showMessageActions(message) + : null, + ), + ), + ], + ); + } + + return buildTextContent(); + }, + ) else - Row( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Flexible( - child: TranslatedMessageContent( - displayText: translatedDisplayText, - originalText: originalDisplayText, - style: TextStyle( - color: textColor, - fontSize: bodyFontSize * textScale, + if (MessageUrlImageHelper.hasPotentialImageUrl( + message.text, + )) + Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + context.l10n.urlImage_possible, + style: TextStyle( + color: metaColor, + fontSize: 11 * textScale, + ), ), - originalStyle: TextStyle( - fontSize: bodyFontSize * textScale, - fontStyle: FontStyle.italic, - color: textColor.withValues(alpha: 0.72), - ), - onSecondaryTap: PlatformInfo.isDesktop - ? () => _showMessageActions(message) - : null, ), - ), + buildTextContent(), ], ), if (enableTracing && displayPath.isNotEmpty) ...[ diff --git a/lib/screens/channels_screen.dart b/lib/screens/channels_screen.dart index 1867f5de..74c07c0c 100644 --- a/lib/screens/channels_screen.dart +++ b/lib/screens/channels_screen.dart @@ -1533,6 +1533,7 @@ class _ChannelsScreenState extends State final pskController = TextEditingController(text: channel.pskHex); bool smazEnabled = connector.isChannelSmazEnabled(channel.index); bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index); + bool urlImagesEnabled = connector.isChannelUrlImagesEnabled(channel.index); String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId( channel.index, ); @@ -1635,6 +1636,13 @@ class _ChannelsScreenState extends State ), ), ], + SwitchListTile( + contentPadding: EdgeInsets.zero, + title: Text(sheetContext.l10n.urlImage_enable), + value: urlImagesEnabled, + onChanged: (value) => + setSheetState(() => urlImagesEnabled = value), + ), const SizedBox(height: 24), ], ), @@ -1684,6 +1692,10 @@ class _ChannelsScreenState extends State channel.index, cyr2latEnabled, ); + await connector.setChannelUrlImagesEnabled( + channel.index, + urlImagesEnabled, + ); await connector.setChannelCyr2LatProfileId( channel.index, selectedCyr2LatProfileId, diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 2568d492..6c1f306f 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -13,6 +13,7 @@ import '../utils/platform_info.dart'; import '../connector/meshcore_connector.dart'; import '../connector/meshcore_protocol.dart'; import '../helpers/cyr2lat.dart'; +import '../helpers/message_url_image_helper.dart'; import '../helpers/path_helper.dart'; import '../helpers/reaction_helper.dart'; import '../widgets/message_status_icon.dart'; @@ -895,6 +896,9 @@ class _ChatScreenState extends State { bool cyr2latEnabled = connector.isContactCyr2LatEnabled( contact.publicKeyHex, ); + bool urlImagesEnabled = connector.isContactUrlImagesEnabled( + contact.publicKeyHex, + ); String? selectedCyr2LatProfileId = connector.getContactCyr2LatProfileId( contact.publicKeyHex, ); @@ -994,6 +998,19 @@ class _ChatScreenState extends State { ), ], const Divider(height: 8), + SwitchListTile( + contentPadding: EdgeInsets.zero, + title: Text(context.l10n.urlImage_enable), + value: urlImagesEnabled, + onChanged: (value) { + connector.setContactUrlImagesEnabled( + contact.publicKeyHex, + value, + ); + setDialogState(() => urlImagesEnabled = value); + }, + ), + const Divider(height: 8), SwitchListTile( contentPadding: EdgeInsets.zero, title: Text(context.l10n.contact_teleBase), @@ -1335,6 +1352,9 @@ class _MessageBubble extends StatelessWidget { final gifId = GifHelper.parseGif(message.text); final poi = parseMarkerText(message.text); final isFailed = message.status == MessageStatus.failed; + final urlImagesEnabled = context.select( + (connector) => connector.isContactUrlImagesEnabled(sourceId), + ); // Bubble colors — outgoing uses MeshPalette.me / meBorder / meInk. final bubbleColor = isFailed @@ -1382,6 +1402,30 @@ class _MessageBubble extends StatelessWidget { ? message.originalText : (translatedDisplayText != messageText ? messageText : null); + Widget buildTextContent() { + return Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Flexible( + child: TranslatedMessageContent( + displayText: translatedDisplayText, + originalText: originalDisplayText, + style: TextStyle( + color: textColor, + fontSize: bodyFontSize * textScale, + ), + originalStyle: TextStyle( + color: textColor.withValues(alpha: 0.72), + fontSize: bodyFontSize * textScale, + ), + onSecondaryTap: PlatformInfo.isDesktop ? onLongPress : null, + ), + ), + ], + ); + } + return Padding( padding: const EdgeInsets.symmetric(vertical: 3), child: Column( @@ -1469,28 +1513,76 @@ class _MessageBubble extends StatelessWidget { ), ], ) + else if (urlImagesEnabled) + MessageUrlImageFutureBuilder( + messageId: message.messageId, + text: message.text, + builder: (context, snapshot) { + final imageAttachment = snapshot.data; + + if (imageAttachment != null) { + return Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + vertical: 4, + ), + child: Align( + alignment: isOutgoing + ? Alignment.centerRight + : Alignment.centerLeft, + child: MessageUrlImagePreview( + imageUrl: imageAttachment, + ), + ), + ), + Padding( + padding: const EdgeInsets.only(top: 8), + child: TranslatedMessageContent( + displayText: translatedDisplayText, + originalText: originalDisplayText, + style: TextStyle( + color: textColor, + fontSize: bodyFontSize * textScale, + ), + originalStyle: TextStyle( + color: textColor.withValues( + alpha: 0.72, + ), + fontSize: bodyFontSize * textScale, + ), + onSecondaryTap: PlatformInfo.isDesktop + ? onLongPress + : null, + ), + ), + ], + ); + } + + return buildTextContent(); + }, + ) else - Row( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Flexible( - child: TranslatedMessageContent( - displayText: translatedDisplayText, - originalText: originalDisplayText, - style: TextStyle( - color: textColor, - fontSize: bodyFontSize * textScale, + if (MessageUrlImageHelper.hasPotentialImageUrl( + message.text, + )) + Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + context.l10n.urlImage_possible, + style: TextStyle( + color: metaColor, + fontSize: 11 * textScale, + ), ), - originalStyle: TextStyle( - color: textColor.withValues(alpha: 0.72), - fontSize: bodyFontSize * textScale, - ), - onSecondaryTap: PlatformInfo.isDesktop - ? onLongPress - : null, ), - ), + buildTextContent(), ], ), if (enableTracing && diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 05ebf6b0..e2cad357 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -3,7 +3,9 @@ import 'dart:ui'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter/foundation.dart'; +import 'package:flutter_cache_manager/flutter_cache_manager.dart'; +import '../helpers/message_url_image_helper.dart'; import '../helpers/reaction_helper.dart'; import '../l10n/app_localizations.dart'; import '../utils/platform_info.dart'; @@ -196,14 +198,40 @@ class NotificationService { return text; } + Future _resolveNotificationImagePath( + String text, { + required bool urlImagesEnabled, + }) async { + if (!urlImagesEnabled) return null; + + final imageUrl = await MessageUrlImageHelper.parseVerified(text); + if (imageUrl == null) return null; + + try { + // Cache the image so notification platforms can read it from disk. + final imageFile = await DefaultCacheManager().getSingleFile(imageUrl); + if (!imageFile.existsSync()) return null; + return imageFile.path; + } catch (e) { + debugPrint('Failed to resolve notification image: $e'); + return null; + } + } + Future _showMessageNotificationImpl({ required String contactName, required String message, + required bool urlImagesEnabled, String? contactId, int? badgeCount, }) async { if (!await _ensureCanNotify()) return; + final imagePath = await _resolveNotificationImagePath( + message, + urlImagesEnabled: urlImagesEnabled, + ); + final androidDetails = AndroidNotificationDetails( 'messages', 'Messages', @@ -212,6 +240,12 @@ class NotificationService { priority: Priority.high, icon: '@mipmap/ic_launcher', number: badgeCount, + styleInformation: imagePath != null + ? BigPictureStyleInformation( + FilePathAndroidBitmap(imagePath), + summaryText: formatNotificationText(message), + ) + : null, ); final iosDetails = DarwinNotificationDetails( @@ -219,6 +253,11 @@ class NotificationService { presentBadge: true, presentSound: true, badgeNumber: badgeCount, + attachments: imagePath != null + ? [ + DarwinNotificationAttachment(imagePath), + ] + : null, ); final macDetails = DarwinNotificationDetails( @@ -226,6 +265,11 @@ class NotificationService { presentBadge: true, presentSound: true, badgeNumber: badgeCount, + attachments: imagePath != null + ? [ + DarwinNotificationAttachment(imagePath), + ] + : null, ); final notificationDetails = NotificationDetails( @@ -299,11 +343,17 @@ class NotificationService { Future _showChannelMessageNotificationImpl({ required String channelName, required String message, + required bool urlImagesEnabled, int? channelIndex, int? badgeCount, }) async { if (!await _ensureCanNotify()) return; + final imagePath = await _resolveNotificationImagePath( + message, + urlImagesEnabled: urlImagesEnabled, + ); + final androidDetails = AndroidNotificationDetails( 'channel_messages', 'Channel Messages', @@ -312,6 +362,12 @@ class NotificationService { priority: Priority.high, icon: '@mipmap/ic_launcher', number: badgeCount, + styleInformation: imagePath != null + ? BigPictureStyleInformation( + FilePathAndroidBitmap(imagePath), + summaryText: formatNotificationText(message), + ) + : null, ); final iosDetails = DarwinNotificationDetails( @@ -319,6 +375,11 @@ class NotificationService { presentBadge: true, presentSound: true, badgeNumber: badgeCount, + attachments: imagePath != null + ? [ + DarwinNotificationAttachment(imagePath), + ] + : null, ); final macDetails = DarwinNotificationDetails( @@ -326,6 +387,11 @@ class NotificationService { presentBadge: true, presentSound: true, badgeNumber: badgeCount, + attachments: imagePath != null + ? [ + DarwinNotificationAttachment(imagePath), + ] + : null, ); final notificationDetails = NotificationDetails( @@ -448,6 +514,7 @@ class NotificationService { Future showMessageNotification({ required String contactName, required String message, + required bool urlImagesEnabled, String? contactId, int? badgeCount, }) async { @@ -458,6 +525,7 @@ class NotificationService { type: _NotificationType.message, title: contactName, body: message, + urlImagesEnabled: urlImagesEnabled, id: contactId, badgeCount: badgeCount, ), @@ -485,6 +553,7 @@ class NotificationService { required String channelName, required String senderName, required String message, + required bool urlImagesEnabled, int? channelIndex, int? badgeCount, }) async { @@ -495,6 +564,7 @@ class NotificationService { type: _NotificationType.channelMessage, title: channelName, body: '$senderName: $message', + urlImagesEnabled: urlImagesEnabled, id: channelIndex?.toString(), badgeCount: badgeCount, ), @@ -556,6 +626,7 @@ class NotificationService { await _showMessageNotificationImpl( contactName: notification.title, message: notification.body, + urlImagesEnabled: notification.urlImagesEnabled, contactId: notification.id, badgeCount: notification.badgeCount, ); @@ -571,6 +642,7 @@ class NotificationService { await _showChannelMessageNotificationImpl( channelName: notification.title, message: notification.body, + urlImagesEnabled: notification.urlImagesEnabled, channelIndex: int.tryParse(notification.id ?? ''), badgeCount: notification.badgeCount, ); @@ -647,6 +719,7 @@ class _PendingNotification { final _NotificationType type; final String title; final String body; + final bool urlImagesEnabled; final String? id; final int? badgeCount; @@ -654,6 +727,7 @@ class _PendingNotification { required this.type, required this.title, required this.body, + this.urlImagesEnabled = false, this.id, this.badgeCount, }); diff --git a/lib/storage/channel_settings_store.dart b/lib/storage/channel_settings_store.dart index e0b390f8..2415d01c 100644 --- a/lib/storage/channel_settings_store.dart +++ b/lib/storage/channel_settings_store.dart @@ -4,6 +4,7 @@ import 'prefs_manager.dart'; class ChannelSettingsStore { static const String _keyPrefix = 'channel_smaz_'; static const String _cyr2latKeyPrefix = 'channel_cyr2lat_'; + static const String _urlImagesKeyPrefix = 'channel_url_images_'; String publicKeyHex = ''; set setPublicKeyHex(String value) => @@ -11,6 +12,7 @@ class ChannelSettingsStore { String get keyFor => '$_keyPrefix$publicKeyHex'; String get keyForCyr2Lat => '$_cyr2latKeyPrefix$publicKeyHex'; + String get keyForUrlImages => '$_urlImagesKeyPrefix$publicKeyHex'; Future loadSmazEnabled(int channelIndex) async { if (publicKeyHex.isEmpty) { @@ -73,6 +75,31 @@ class ChannelSettingsStore { await prefs.setBool(key, enabled); } + Future loadUrlImagesEnabled(int channelIndex) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot load channel URL image settings.', + ); + return false; + } + final prefs = PrefsManager.instance; + final key = '$keyForUrlImages$channelIndex'; + return prefs.getBool(key) ?? false; + } + + Future saveUrlImagesEnabled(int channelIndex, bool enabled) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot save channel URL image settings.', + ); + return; + } + await PrefsManager.instance.setBool( + '$keyForUrlImages$channelIndex', + enabled, + ); + } + Future loadCyr2LatProfileId(int channelIndex) async { if (publicKeyHex.isEmpty) { appLogger.warn( diff --git a/lib/storage/contact_settings_store.dart b/lib/storage/contact_settings_store.dart index 682f1af6..a0760477 100644 --- a/lib/storage/contact_settings_store.dart +++ b/lib/storage/contact_settings_store.dart @@ -4,6 +4,7 @@ import 'prefs_manager.dart'; class ContactSettingsStore { static const String _keyPrefix = 'contact_smaz_'; static const String _cyr2latKeyPrefix = 'contact_cyr2lat_'; + static const String _urlImagesKeyPrefix = 'contact_url_images_'; String publicKeyHex = ''; set setPublicKeyHex(String value) => @@ -11,6 +12,7 @@ class ContactSettingsStore { String get keyFor => '$_keyPrefix$publicKeyHex'; String get keyForCyr2Lat => '$_cyr2latKeyPrefix$publicKeyHex'; + String get keyForUrlImages => '$_urlImagesKeyPrefix$publicKeyHex'; Future loadSmazEnabled(String contactKeyHex) async { if (publicKeyHex.isEmpty) { @@ -73,6 +75,31 @@ class ContactSettingsStore { await prefs.setBool(key, enabled); } + Future loadUrlImagesEnabled(String contactKeyHex) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot load contact URL image settings.', + ); + return false; + } + final prefs = PrefsManager.instance; + final key = '$keyForUrlImages$contactKeyHex'; + return prefs.getBool(key) ?? false; + } + + Future saveUrlImagesEnabled(String contactKeyHex, bool enabled) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot save contact URL image settings.', + ); + return; + } + await PrefsManager.instance.setBool( + '$keyForUrlImages$contactKeyHex', + enabled, + ); + } + Future loadCyr2LatProfileId(String contactKeyHex) async { if (publicKeyHex.isEmpty) { appLogger.warn( diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 3fbca4bc..9c7e2a7a 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -10,6 +10,7 @@ list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST flserial + jni ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/test/helpers/message_url_image_helper_test.dart b/test/helpers/message_url_image_helper_test.dart new file mode 100644 index 00000000..ecb2712b --- /dev/null +++ b/test/helpers/message_url_image_helper_test.dart @@ -0,0 +1,93 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/helpers/message_url_image_helper.dart'; + +void main() { + group('MessageUrlImageHelper', () { + test('parses short pyx ids', () async { + final attachment = await MessageUrlImageHelper.parse( + 'my picture: https://pyx.li/?i=RzmdkTsE text', + ); + + expect(attachment, isNotNull); + expect(attachment, 'https://pyx.li/i/RzmdkTsE.jpg'); + }); + + test('parses direct pyx image urls', () async { + final attachment = await MessageUrlImageHelper.parse( + 'https://pyx.li/?i=Cd1KFiwu', + ); + + expect(attachment, isNotNull); + expect(attachment, 'https://pyx.li/i/Cd1KFiwu.jpg'); + }); + + test('parses provider-hosted ipfs links', () async { + final attachment = await MessageUrlImageHelper.parse( + 'my picture: https://uneven-plum-tarantula.myfilebase.com/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', + ); + + expect(attachment, isNotNull); + expect( + attachment, + 'https://uneven-plum-tarantula.myfilebase.com/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly', + ); + }); + + test('parses direct ipfs cid urls', () async { + final attachment = await MessageUrlImageHelper.parse( + 'my picture: ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', + ); + + expect(attachment, isNotNull); + expect( + attachment, + 'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly', + ); + }); + + test('parses direct ipfs cid urls without double slashes', () async { + final attachment = await MessageUrlImageHelper.parse( + 'my picture: ipfs:bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', + ); + + expect( + attachment, + 'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly', + ); + }); + + test('parses http image urls', () async { + final attachment = await MessageUrlImageHelper.parse( + 'see this image https://example.com/picture.png?size=large additional text', + ); + + expect(attachment, isNotNull); + expect(attachment, 'https://example.com/picture.png?size=large'); + }); + + test('returns null for plain text', () async { + expect(await MessageUrlImageHelper.parse('hello world'), isNull); + }); + + test('detects supported image URLs without resolving them', () { + expect( + MessageUrlImageHelper.hasPotentialImageUrl( + 'https://pyx.li/?i=RzmdkTsE', + ), + isTrue, + ); + expect( + MessageUrlImageHelper.hasPotentialImageUrl('hello world'), + isFalse, + ); + }); + + test('returns null for non-image ipfs gateway URL', () async { + final attachment = await MessageUrlImageHelper.parseVerified( + 'https://lime-famous-rat-748.mypinata.cloud/ipfs/bafybeih3jqv36rsxqx7yw3k3ixhganrevrk7xmcxgkr2zuzjegxdytb3nq', + ); + + expect(attachment, isNull); + }); + }); +} diff --git a/untranslated.json b/untranslated.json index 0967ef42..83b675e2 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1 +1,101 @@ -{} +{ + "bg": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "de": [ + "reaction_report" + ], + + "es": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "fr": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "hu": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "it": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "ja": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "ko": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "nl": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "pl": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "pt": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "ru": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "sk": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "sl": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "sv": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "uk": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ], + + "zh": [ + "urlImage_enable", + "urlImage_possible", + "reaction_report" + ] +} diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index d6ef3354..ae56b7cf 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -13,6 +13,7 @@ list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST flserial flutter_local_notifications_windows + jni ) set(PLUGIN_BUNDLED_LIBRARIES)