From d920449cbb1d1e8d276be7d46a6602b2e0ef092d Mon Sep 17 00:00:00 2001 From: ericz Date: Mon, 10 Aug 2026 22:21:10 +0200 Subject: [PATCH] Add Contact and Channelsettings to explicitly enable Picture preview. --- lib/connector/meshcore_connector.dart | 45 +++++++++++ lib/helpers/message_image_helper.dart | 10 +++ lib/l10n/app_de.arb | 2 + lib/l10n/app_en.arb | 2 + lib/l10n/app_localizations.dart | 12 +++ lib/l10n/app_localizations_bg.dart | 6 ++ lib/l10n/app_localizations_de.dart | 7 ++ lib/l10n/app_localizations_en.dart | 6 ++ lib/l10n/app_localizations_es.dart | 6 ++ lib/l10n/app_localizations_fr.dart | 6 ++ lib/l10n/app_localizations_hu.dart | 6 ++ lib/l10n/app_localizations_it.dart | 6 ++ lib/l10n/app_localizations_ja.dart | 6 ++ lib/l10n/app_localizations_ko.dart | 6 ++ lib/l10n/app_localizations_nl.dart | 6 ++ lib/l10n/app_localizations_pl.dart | 6 ++ lib/l10n/app_localizations_pt.dart | 6 ++ lib/l10n/app_localizations_ru.dart | 6 ++ lib/l10n/app_localizations_sk.dart | 6 ++ lib/l10n/app_localizations_sl.dart | 6 ++ lib/l10n/app_localizations_sv.dart | 6 ++ lib/l10n/app_localizations_uk.dart | 6 ++ lib/l10n/app_localizations_zh.dart | 6 ++ lib/screens/channel_chat_screen.dart | 84 +++++++++++++------- lib/screens/channels_screen.dart | 12 +++ lib/screens/chat_screen.dart | 87 +++++++++++++++------ lib/services/notification_service.dart | 27 ++++++- lib/storage/channel_settings_store.dart | 22 ++++++ lib/storage/contact_settings_store.dart | 23 ++++++ test/helpers/message_image_helper_test.dart | 10 ++- untranslated.json | 32 ++++++++ 31 files changed, 421 insertions(+), 56 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 4e3ac7d8..c4fa3a62 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -356,12 +356,14 @@ class MeshCoreConnector extends ChangeNotifier { List _cachedChannels = []; final Map _channelSmazEnabled = {}; final Map _channelCyr2LatEnabled = {}; + final Map _channelImagesEnabled = {}; 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 _contactImagesEnabled = {}; final Map _contactCyr2LatProfileId = {}; final Set _knownContactKeys = {}; final Map _contactUnreadCount = {}; @@ -756,6 +758,15 @@ class MeshCoreConnector extends ChangeNotifier { return _contactSmazEnabled[contactKeyHex] ?? false; } + bool isChannelImagesEnabled(int channelIndex) { + return _channelImagesEnabled[channelIndex] ?? false; + } + + bool isContactImagesEnabled(String contactKeyHex) { + _ensureContactImagesSettingLoaded(contactKeyHex); + return _contactImagesEnabled[contactKeyHex] ?? false; + } + bool hasChannelRegion(int channelIndex) { return (_channelRegions[channelIndex] ?? '').isNotEmpty; } @@ -898,6 +909,21 @@ class MeshCoreConnector extends ChangeNotifier { notifyListeners(); } + Future setChannelImagesEnabled(int channelIndex, bool enabled) async { + _channelImagesEnabled[channelIndex] = enabled; + await _channelSettingsStore.saveImagesEnabled(channelIndex, enabled); + notifyListeners(); + } + + Future setContactImagesEnabled( + String contactKeyHex, + bool enabled, + ) async { + _contactImagesEnabled[contactKeyHex] = enabled; + await _contactSettingsStore.saveImagesEnabled(contactKeyHex, enabled); + notifyListeners(); + } + Future setChannelCyr2LatEnabled(int channelIndex, bool enabled) async { _channelCyr2LatEnabled[channelIndex] = enabled; if (enabled) { @@ -1070,6 +1096,7 @@ class MeshCoreConnector extends ChangeNotifier { for (final contact in cached) { _ensureContactSmazSettingLoaded(contact.publicKeyHex); _ensureContactCyr2LatSettingLoaded(contact.publicKeyHex); + _ensureContactImagesSettingLoaded(contact.publicKeyHex); } } @@ -1090,12 +1117,16 @@ class MeshCoreConnector extends ChangeNotifier { Future loadChannelSettings({int? maxChannels}) async { _channelSmazEnabled.clear(); _channelCyr2LatEnabled.clear(); + _channelImagesEnabled.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); + _channelImagesEnabled[i] = await _channelSettingsStore.loadImagesEnabled( + i, + ); _channelRegions[i] = await _channelRegionStore.loadRegion(i); } } @@ -5151,6 +5182,8 @@ class MeshCoreConnector extends ChangeNotifier { await _notificationService.showMessageNotification( contactName: c?.name ?? 'Unknown', message: resolvedText, + imagesEnabled: + c != null && isContactImagesEnabled(c.publicKeyHex), contactId: msg.senderKeyHex, badgeCount: getTotalUnreadCount(), ); @@ -5165,6 +5198,8 @@ class MeshCoreConnector extends ChangeNotifier { await _notificationService.showMessageNotification( contactName: c?.name ?? 'Unknown Room', message: resolvedText, + imagesEnabled: + c != null && isContactImagesEnabled(c.publicKeyHex), contactId: msg.senderKeyHex, badgeCount: getTotalUnreadCount(), ); @@ -5315,6 +5350,15 @@ class MeshCoreConnector extends ChangeNotifier { }); } + void _ensureContactImagesSettingLoaded(String contactKeyHex) { + if (_contactImagesEnabled.containsKey(contactKeyHex)) return; + _contactSettingsStore.loadImagesEnabled(contactKeyHex).then((enabled) { + if (_contactImagesEnabled[contactKeyHex] == enabled) return; + _contactImagesEnabled[contactKeyHex] = enabled; + notifyListeners(); + }); + } + void _ensureContactCyr2LatProfileLoaded(String contactKeyHex) { if (_contactCyr2LatProfileId.containsKey(contactKeyHex)) return; _contactSettingsStore.loadCyr2LatProfileId(contactKeyHex).then((profileId) { @@ -5469,6 +5513,7 @@ class MeshCoreConnector extends ChangeNotifier { channelName: label, senderName: message.senderName, message: resolvedText, + imagesEnabled: isChannelImagesEnabled(channelIndex), channelIndex: message.channelIndex, badgeCount: getTotalUnreadCount(), ); diff --git a/lib/helpers/message_image_helper.dart b/lib/helpers/message_image_helper.dart index 3763b633..06496485 100644 --- a/lib/helpers/message_image_helper.dart +++ b/lib/helpers/message_image_helper.dart @@ -33,6 +33,16 @@ class MessageImageHelper { 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; diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index f5cc3685..9a698fbb 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -2625,6 +2625,8 @@ "messageStatus_pending": "Wird gesendet", "messageStatus_failed": "Senden fehlgeschlagen", "messageStatus_repeated": "Mehrfach gehört", + "messageImage_enable": "Erlaube Bilder", + "messageImage_possible": "Mögliches Bild, erlaube in Einstellungen.", "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 9c9c8286..1e9f6bae 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", + "messageImage_enable": "Enable Images", + "messageImage_possible": "Possible Image, enable 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 2ad4638e..515bcf6c 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 @messageImage_enable. + /// + /// In en, this message translates to: + /// **'Enable Images'** + String get messageImage_enable; + + /// No description provided for @messageImage_possible. + /// + /// In en, this message translates to: + /// **'Possible Image, enable in Settings.'** + String get messageImage_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 41c11438..54634ec6 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable in Settings.'; + @override String get common_reboot => 'Рестартирай'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 5da89506..58b7f7c7 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 messageImage_enable => 'Erlaube Bilder'; + + @override + String get messageImage_possible => + 'Mögliches Bild, erlaube in Einstellungen.'; + @override String get common_reboot => 'Neustart'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index ccdd9ed0..bc8ecb36 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 da679126..67d2a462 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 29022552..9bc7afe6 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 7fa5c541..e654a960 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 0e01ff91..a4fa765d 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 e16d6419..1790e99d 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable in Settings.'; + @override String get common_reboot => '再起動'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 209867fe..147b1475 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable in Settings.'; + @override String get common_reboot => '재부팅'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index bf33733a..66826cd5 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 f0f57506..115f71ec 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 55c2fa48..31f806a1 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 d32b69a4..8079a4d5 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable in Settings.'; + @override String get common_reboot => 'Перезагрузить'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 5ee8ec33..42312235 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 07d1bd4f..98859b41 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 8bdd20f9..8e2ffcd2 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable 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 2e87ba8d..b4f969b2 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable in Settings.'; + @override String get common_reboot => 'Перезавантажити'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index fa2813c3..7a3f7866 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 messageImage_enable => 'Enable Images'; + + @override + String get messageImage_possible => 'Possible Image, enable in Settings.'; + @override String get common_reboot => '重启'; diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index 8a789347..9ab2afa1 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -393,6 +393,9 @@ class _ChannelChatScreenState extends State { // Reverse messages so newest appear at bottom with reverse: true final reversedMessages = messages.reversed.toList(); + final imagesEnabled = connector.isChannelImagesEnabled( + widget.channel.index, + ); final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0); @@ -473,6 +476,7 @@ class _ChannelChatScreenState extends State { final bubble = _buildMessageBubble( message, textScale, + imagesEnabled, ); if (isUnreadAnchor) { return Column( @@ -512,7 +516,11 @@ class _ChannelChatScreenState extends State { connector.setChannelUnreadCount(widget.channel.index, count); } - Widget _buildMessageBubble(ChannelMessage message, double textScale) { + Widget _buildMessageBubble( + ChannelMessage message, + double textScale, + bool imagesEnabled, + ) { final settingsService = context.watch(); final enableTracing = settingsService.settings.enableMessageTracing; final isOutgoing = message.isOutgoing; @@ -552,6 +560,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( @@ -657,7 +692,7 @@ class _ChannelChatScreenState extends State { ), ], ) - else + else if (imagesEnabled) FutureBuilder( future: MessageImageHelper.parseVerified( message.text, @@ -702,33 +737,28 @@ class _ChannelChatScreenState extends State { ); } - 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, + return buildTextContent(); + }, + ) + else + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (MessageImageHelper.hasPotentialImageUrl( + message.text, + )) + Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + context.l10n.messageImage_possible, + style: TextStyle( + color: metaColor, + fontSize: 11 * textScale, ), ), - ], - ); - }, + ), + buildTextContent(), + ], ), if (enableTracing && displayPath.isNotEmpty) ...[ const SizedBox(height: 3), diff --git a/lib/screens/channels_screen.dart b/lib/screens/channels_screen.dart index 1867f5de..720c4e59 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 imagesEnabled = connector.isChannelImagesEnabled(channel.index); String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId( channel.index, ); @@ -1635,6 +1636,13 @@ class _ChannelsScreenState extends State ), ), ], + SwitchListTile( + contentPadding: EdgeInsets.zero, + title: Text(sheetContext.l10n.messageImage_enable), + value: imagesEnabled, + onChanged: (value) => + setSheetState(() => imagesEnabled = value), + ), const SizedBox(height: 24), ], ), @@ -1684,6 +1692,10 @@ class _ChannelsScreenState extends State channel.index, cyr2latEnabled, ); + await connector.setChannelImagesEnabled( + channel.index, + imagesEnabled, + ); await connector.setChannelCyr2LatProfileId( channel.index, selectedCyr2LatProfileId, diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 60b4d1b9..73138a93 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -868,6 +868,7 @@ class _ChatScreenState extends State { bool cyr2latEnabled = connector.isContactCyr2LatEnabled( contact.publicKeyHex, ); + bool imagesEnabled = connector.isContactImagesEnabled(contact.publicKeyHex); String? selectedCyr2LatProfileId = connector.getContactCyr2LatProfileId( contact.publicKeyHex, ); @@ -967,6 +968,19 @@ class _ChatScreenState extends State { ), ], const Divider(height: 8), + SwitchListTile( + contentPadding: EdgeInsets.zero, + title: Text(context.l10n.messageImage_enable), + value: imagesEnabled, + onChanged: (value) { + connector.setContactImagesEnabled( + contact.publicKeyHex, + value, + ); + setDialogState(() => imagesEnabled = value); + }, + ), + const Divider(height: 8), SwitchListTile( contentPadding: EdgeInsets.zero, title: Text(context.l10n.contact_teleBase), @@ -1307,6 +1321,9 @@ class _MessageBubble extends StatelessWidget { final gifId = GifHelper.parseGif(message.text); final poi = parseMarkerText(message.text); final isFailed = message.status == MessageStatus.failed; + final imagesEnabled = context.select( + (connector) => connector.isContactImagesEnabled(sourceId), + ); // Bubble colors — outgoing uses MeshPalette.me / meBorder / meInk. final bubbleColor = isFailed @@ -1354,6 +1371,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( @@ -1441,7 +1482,7 @@ class _MessageBubble extends StatelessWidget { ), ], ) - else + else if (imagesEnabled) FutureBuilder( future: MessageImageHelper.parseVerified( message.text, @@ -1486,32 +1527,28 @@ class _MessageBubble extends StatelessWidget { ); } - 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 buildTextContent(); + }, + ) + else + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (MessageImageHelper.hasPotentialImageUrl( + message.text, + )) + Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + context.l10n.messageImage_possible, + style: TextStyle( + color: metaColor, + fontSize: 11 * textScale, ), ), - ], - ); - }, + ), + buildTextContent(), + ], ), if (enableTracing && isOutgoing && diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 16d90ad1..ae48bc06 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -198,7 +198,12 @@ class NotificationService { return text; } - Future _resolveNotificationImagePath(String text) async { + Future _resolveNotificationImagePath( + String text, { + required bool imagesEnabled, + }) async { + if (!imagesEnabled) return null; + final imageUrl = await MessageImageHelper.parseVerified(text); if (imageUrl == null) return null; @@ -216,12 +221,16 @@ class NotificationService { Future _showMessageNotificationImpl({ required String contactName, required String message, + required bool imagesEnabled, String? contactId, int? badgeCount, }) async { if (!await _ensureCanNotify()) return; - final imagePath = await _resolveNotificationImagePath(message); + final imagePath = await _resolveNotificationImagePath( + message, + imagesEnabled: imagesEnabled, + ); final androidDetails = AndroidNotificationDetails( 'messages', @@ -334,12 +343,16 @@ class NotificationService { Future _showChannelMessageNotificationImpl({ required String channelName, required String message, + required bool imagesEnabled, int? channelIndex, int? badgeCount, }) async { if (!await _ensureCanNotify()) return; - final imagePath = await _resolveNotificationImagePath(message); + final imagePath = await _resolveNotificationImagePath( + message, + imagesEnabled: imagesEnabled, + ); final androidDetails = AndroidNotificationDetails( 'channel_messages', @@ -501,6 +514,7 @@ class NotificationService { Future showMessageNotification({ required String contactName, required String message, + required bool imagesEnabled, String? contactId, int? badgeCount, }) async { @@ -511,6 +525,7 @@ class NotificationService { type: _NotificationType.message, title: contactName, body: message, + imagesEnabled: imagesEnabled, id: contactId, badgeCount: badgeCount, ), @@ -538,6 +553,7 @@ class NotificationService { required String channelName, required String senderName, required String message, + required bool imagesEnabled, int? channelIndex, int? badgeCount, }) async { @@ -548,6 +564,7 @@ class NotificationService { type: _NotificationType.channelMessage, title: channelName, body: '$senderName: $message', + imagesEnabled: imagesEnabled, id: channelIndex?.toString(), badgeCount: badgeCount, ), @@ -609,6 +626,7 @@ class NotificationService { await _showMessageNotificationImpl( contactName: notification.title, message: notification.body, + imagesEnabled: notification.imagesEnabled, contactId: notification.id, badgeCount: notification.badgeCount, ); @@ -624,6 +642,7 @@ class NotificationService { await _showChannelMessageNotificationImpl( channelName: notification.title, message: notification.body, + imagesEnabled: notification.imagesEnabled, channelIndex: int.tryParse(notification.id ?? ''), badgeCount: notification.badgeCount, ); @@ -700,6 +719,7 @@ class _PendingNotification { final _NotificationType type; final String title; final String body; + final bool imagesEnabled; final String? id; final int? badgeCount; @@ -707,6 +727,7 @@ class _PendingNotification { required this.type, required this.title, required this.body, + this.imagesEnabled = false, this.id, this.badgeCount, }); diff --git a/lib/storage/channel_settings_store.dart b/lib/storage/channel_settings_store.dart index e0b390f8..7af70335 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 _imagesKeyPrefix = 'channel_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 keyForImages => '$_imagesKeyPrefix$publicKeyHex'; Future loadSmazEnabled(int channelIndex) async { if (publicKeyHex.isEmpty) { @@ -73,6 +75,26 @@ class ChannelSettingsStore { await prefs.setBool(key, enabled); } + Future loadImagesEnabled(int channelIndex) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot load channel image settings.', + ); + return false; + } + return PrefsManager.instance.getBool('$keyForImages$channelIndex') ?? false; + } + + Future saveImagesEnabled(int channelIndex, bool enabled) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot save channel image settings.', + ); + return; + } + await PrefsManager.instance.setBool('$keyForImages$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..a64b5345 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 _imagesKeyPrefix = 'contact_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 keyForImages => '$_imagesKeyPrefix$publicKeyHex'; Future loadSmazEnabled(String contactKeyHex) async { if (publicKeyHex.isEmpty) { @@ -73,6 +75,27 @@ class ContactSettingsStore { await prefs.setBool(key, enabled); } + Future loadImagesEnabled(String contactKeyHex) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot load contact image settings.', + ); + return false; + } + return PrefsManager.instance.getBool('$keyForImages$contactKeyHex') ?? + false; + } + + Future saveImagesEnabled(String contactKeyHex, bool enabled) async { + if (publicKeyHex.isEmpty) { + appLogger.warn( + 'Public key hex is not set. Cannot save contact image settings.', + ); + return; + } + await PrefsManager.instance.setBool('$keyForImages$contactKeyHex', enabled); + } + Future loadCyr2LatProfileId(String contactKeyHex) async { if (publicKeyHex.isEmpty) { appLogger.warn( diff --git a/test/helpers/message_image_helper_test.dart b/test/helpers/message_image_helper_test.dart index b10b3ac5..8f092d2f 100644 --- a/test/helpers/message_image_helper_test.dart +++ b/test/helpers/message_image_helper_test.dart @@ -58,7 +58,15 @@ void main() { expect(await MessageImageHelper.parse('hello world'), isNull); }); - test('returns null for non-image ipfs gateway url', () async { + test('detects supported image URLs without resolving them', () { + expect( + MessageImageHelper.hasPotentialImageUrl('https://pyx.li/?i=RzmdkTsE'), + isTrue, + ); + expect(MessageImageHelper.hasPotentialImageUrl('hello world'), isFalse); + }); + + test('returns null for non-image ipfs gateway URL', () async { final attachment = await MessageImageHelper.parseVerified( 'https://lime-famous-rat-748.mypinata.cloud/ipfs/bafybeih3jqv36rsxqx7yw3k3ixhganrevrk7xmcxgkr2zuzjegxdytb3nq', ); diff --git a/untranslated.json b/untranslated.json index 14f7f7cc..cc4b5cee 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1,5 +1,7 @@ { "bg": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -55,6 +57,8 @@ ], "es": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -89,6 +93,8 @@ ], "fr": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -123,6 +129,8 @@ ], "hu": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -157,6 +165,8 @@ ], "it": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -191,6 +201,8 @@ ], "ja": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -225,6 +237,8 @@ ], "ko": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -259,6 +273,8 @@ ], "nl": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -293,6 +309,8 @@ ], "pl": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -327,6 +345,8 @@ ], "pt": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -361,6 +381,8 @@ ], "ru": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -395,6 +417,8 @@ ], "sk": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -429,6 +453,8 @@ ], "sl": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -463,6 +489,8 @@ ], "sv": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -497,6 +525,8 @@ ], "uk": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle", @@ -531,6 +561,8 @@ ], "zh": [ + "messageImage_enable", + "messageImage_possible", "settings_regionSettings", "settings_regionSettingsSubtitle", "settings_regionManagement_screenTitle",