From 79e3668c18f92026831ba8764b1a8b97e44a68a4 Mon Sep 17 00:00:00 2001 From: zjs81 Date: Sat, 24 Oct 2026 21:58:09 -0700 Subject: [PATCH] Add a global switch to stop loading images from links 'Load images from links' (default on) gates every link image fetch in MessageUrlImageHelper: chat previews, notification images, ipfs:// resolution and pyx/ibb scraping. Per-chat toggles keep their values but are disabled while it is off. IPFS uploads are unaffected. --- lib/helpers/message_url_image_helper.dart | 48 ++++++++++------- lib/l10n/app_en.arb | 3 ++ lib/l10n/app_localizations.dart | 18 +++++++ lib/l10n/app_localizations_bg.dart | 10 ++++ lib/l10n/app_localizations_de.dart | 10 ++++ lib/l10n/app_localizations_en.dart | 10 ++++ lib/l10n/app_localizations_es.dart | 10 ++++ lib/l10n/app_localizations_fr.dart | 10 ++++ lib/l10n/app_localizations_hu.dart | 10 ++++ lib/l10n/app_localizations_it.dart | 10 ++++ lib/l10n/app_localizations_ja.dart | 10 ++++ lib/l10n/app_localizations_ko.dart | 10 ++++ lib/l10n/app_localizations_nl.dart | 10 ++++ lib/l10n/app_localizations_pl.dart | 10 ++++ lib/l10n/app_localizations_pt.dart | 10 ++++ lib/l10n/app_localizations_ru.dart | 10 ++++ lib/l10n/app_localizations_sk.dart | 10 ++++ lib/l10n/app_localizations_sl.dart | 10 ++++ lib/l10n/app_localizations_sv.dart | 10 ++++ lib/l10n/app_localizations_uk.dart | 10 ++++ lib/l10n/app_localizations_zh.dart | 10 ++++ lib/main.dart | 5 ++ lib/models/app_settings.dart | 8 +++ lib/screens/app_settings_screen.dart | 12 +++++ lib/screens/channel_chat_screen.dart | 7 +-- lib/screens/channels_screen.dart | 15 +++++- lib/screens/chat_screen.dart | 30 +++++++---- lib/services/app_settings_service.dart | 4 ++ .../message_url_image_helper_test.dart | 26 +++++++++- test/models/model_changes_test.dart | 7 +++ untranslated.json | 51 +++++++++++++++++++ 31 files changed, 381 insertions(+), 33 deletions(-) diff --git a/lib/helpers/message_url_image_helper.dart b/lib/helpers/message_url_image_helper.dart index 2f3e0756..6e85351a 100644 --- a/lib/helpers/message_url_image_helper.dart +++ b/lib/helpers/message_url_image_helper.dart @@ -24,6 +24,10 @@ class MessageUrlImageHelper { @visibleForTesting static http.Client? httpClient; + /// Mirrors [AppSettings.loadLinkImages]. When false, nothing is fetched + /// for link images and every parse returns null. + static final ValueNotifier loadLinkImages = ValueNotifier(true); + static final RegExp _pyxPattern = RegExp( r'''https?://pyx\.li/\?i=([A-Za-z0-9_-]+)''', caseSensitive: false, @@ -63,6 +67,7 @@ class MessageUrlImageHelper { String text, { String publicGateway = AppSettings.defaultPublicIpfsGateway, }) async { + if (!loadLinkImages.value) return null; final trimmed = text.trim(); if (trimmed.isEmpty) return null; @@ -123,6 +128,7 @@ class MessageUrlImageHelper { String text, { String publicGateway = AppSettings.defaultPublicIpfsGateway, }) { + if (!loadLinkImages.value) return Future.value(); final cacheKey = '$messageId|$publicGateway'; final cached = _messageImageCache.remove(cacheKey); if (cached != null) { @@ -240,29 +246,37 @@ class _MessageUrlImageFutureBuilderState @override void initState() { super.initState(); - _imageFuture = MessageUrlImageHelper.parseVerifiedForMessage( + _imageFuture = _parse(); + MessageUrlImageHelper.loadLinkImages.addListener(_onLoadLinkImagesChanged); + } + + @override + void didUpdateWidget(covariant MessageUrlImageFutureBuilder oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.messageId != widget.messageId || + oldWidget.publicGateway != widget.publicGateway) { + _imageFuture = _parse(); + } + } + + @override + void dispose() { + MessageUrlImageHelper.loadLinkImages.removeListener( + _onLoadLinkImagesChanged, + ); + super.dispose(); + } + + Future _parse() { + return MessageUrlImageHelper.parseVerifiedForMessage( widget.messageId, widget.text, publicGateway: widget.publicGateway, ); } - @override - void didUpdateWidget(covariant MessageUrlImageFutureBuilder oldWidget) { - super.didUpdateWidget(oldWidget); - if (oldWidget.messageId != widget.messageId) { - _imageFuture = MessageUrlImageHelper.parseVerifiedForMessage( - widget.messageId, - widget.text, - publicGateway: widget.publicGateway, - ); - } else if (oldWidget.publicGateway != widget.publicGateway) { - _imageFuture = MessageUrlImageHelper.parseVerifiedForMessage( - widget.messageId, - widget.text, - publicGateway: widget.publicGateway, - ); - } + void _onLoadLinkImagesChanged() { + setState(() => _imageFuture = _parse()); } @override diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 1849de8e..edf1fd10 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -69,6 +69,7 @@ }, "urlImage_enable": "Enable URL images", "urlImage_possible": "Possible URL image; enable it in Settings.", + "urlImage_disabledInAppSettings": "Turned off in app settings", "common_reboot": "Reboot", "common_loading": "Loading...", "common_notAvailable": "—", @@ -455,6 +456,8 @@ "appSettings_maxMessageRetriesSubtitle": "Number of retry attempts before marking a message as failed", "appSettings_ipfsImageLinks": "IPFS provider configuration", "appSettings_ipfsImageLinksSubtitle": "Upload for url Images (or Files) via IPFS provider and default gateway to receive", + "appSettings_loadLinkImages": "Load images from links", + "appSettings_loadLinkImagesSubtitle": "Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.", "appSettings_publicIpfsGateway": "Public gateway", "appSettings_ipfsGatewayDeactivated": "Deactivated", "appSettings_ipfsGatewayIpfsIo": "ipfs.io", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 78a0b15e..a494e526 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -382,6 +382,12 @@ abstract class AppLocalizations { /// **'Possible URL image; enable it in Settings.'** String get urlImage_possible; + /// No description provided for @urlImage_disabledInAppSettings. + /// + /// In en, this message translates to: + /// **'Turned off in app settings'** + String get urlImage_disabledInAppSettings; + /// No description provided for @common_reboot. /// /// In en, this message translates to: @@ -1966,6 +1972,18 @@ abstract class AppLocalizations { /// **'Upload for url Images (or Files) via IPFS provider and default gateway to receive'** String get appSettings_ipfsImageLinksSubtitle; + /// No description provided for @appSettings_loadLinkImages. + /// + /// In en, this message translates to: + /// **'Load images from links'** + String get appSettings_loadLinkImages; + + /// No description provided for @appSettings_loadLinkImagesSubtitle. + /// + /// In en, this message translates to: + /// **'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'** + String get appSettings_loadLinkImagesSubtitle; + /// No description provided for @appSettings_publicIpfsGateway. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index b40cbd33..acfebbcb 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -150,6 +150,9 @@ class AppLocalizationsBg extends AppLocalizations { String get urlImage_possible => 'Възможно изображение от URL; активирайте го в Настройки.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Рестартирай'; @@ -1083,6 +1086,13 @@ class AppLocalizationsBg extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 232197ba..44ab330e 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -150,6 +150,9 @@ class AppLocalizationsDe extends AppLocalizations { String get urlImage_possible => 'Mögliches URL-Bild; in den Einstellungen aktivieren.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Neustart'; @@ -1078,6 +1081,13 @@ class AppLocalizationsDe extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 25256f93..104199aa 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -150,6 +150,9 @@ class AppLocalizationsEn extends AppLocalizations { @override String get urlImage_possible => 'Possible URL image; enable it in Settings.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Reboot'; @@ -1062,6 +1065,13 @@ class AppLocalizationsEn extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index a5ed0764..7e8dfab0 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -150,6 +150,9 @@ class AppLocalizationsEs extends AppLocalizations { String get urlImage_possible => 'Posible imagen de URL; actívala en Configuración.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Reiniciar'; @@ -1075,6 +1078,13 @@ class AppLocalizationsEs extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 4b9bfcde..a809a3c7 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -150,6 +150,9 @@ class AppLocalizationsFr extends AppLocalizations { String get urlImage_possible => 'Image URL possible ; activez-la dans les Paramètres.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Redémarrer'; @@ -1081,6 +1084,13 @@ class AppLocalizationsFr extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 79c968e1..af28f6a5 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -150,6 +150,9 @@ class AppLocalizationsHu extends AppLocalizations { String get urlImage_possible => 'Lehetséges URL-kép; engedélyezze a Beállításokban.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Indítsa újra'; @@ -1070,6 +1073,13 @@ class AppLocalizationsHu extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 4768156b..67e124de 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -150,6 +150,9 @@ class AppLocalizationsIt extends AppLocalizations { String get urlImage_possible => 'Possibile immagine URL; abilitala nelle Impostazioni.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Riavvia'; @@ -1081,6 +1084,13 @@ class AppLocalizationsIt extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 9057572a..d04f31c8 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -147,6 +147,9 @@ class AppLocalizationsJa extends AppLocalizations { @override String get urlImage_possible => 'URL画像の可能性があります。設定で有効にしてください。'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => '再起動'; @@ -1018,6 +1021,13 @@ class AppLocalizationsJa extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 75e8cc06..9e893675 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -147,6 +147,9 @@ class AppLocalizationsKo extends AppLocalizations { @override String get urlImage_possible => 'URL 이미지일 수 있습니다. 설정에서 활성화하세요.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => '재부팅'; @@ -1022,6 +1025,13 @@ class AppLocalizationsKo extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 4b99bcfd..824a142c 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -151,6 +151,9 @@ class AppLocalizationsNl extends AppLocalizations { String get urlImage_possible => 'Mogelijke URL-afbeelding; schakel dit in bij Instellingen.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Herstarten'; @@ -1071,6 +1074,13 @@ class AppLocalizationsNl extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 500eadcb..b88b5ee6 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -152,6 +152,9 @@ class AppLocalizationsPl extends AppLocalizations { String get urlImage_possible => 'Możliwy obraz z URL; włącz go w Ustawieniach.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Uruchom ponownie'; @@ -1087,6 +1090,13 @@ class AppLocalizationsPl extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index af1d3ca4..4392cc30 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -150,6 +150,9 @@ class AppLocalizationsPt extends AppLocalizations { String get urlImage_possible => 'Possível imagem de URL; ative-a em Configurações.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Reiniciar'; @@ -1079,6 +1082,13 @@ class AppLocalizationsPt extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 13d4ac7f..e35d7dce 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -150,6 +150,9 @@ class AppLocalizationsRu extends AppLocalizations { String get urlImage_possible => 'Возможно изображение по URL; включите это в настройках.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Перезагрузить'; @@ -1084,6 +1087,13 @@ class AppLocalizationsRu extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 7e429e7d..34592fcd 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -151,6 +151,9 @@ class AppLocalizationsSk extends AppLocalizations { String get urlImage_possible => 'Možný obrázok z URL; povoľte ho v Nastaveniach.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Restartovať'; @@ -1070,6 +1073,13 @@ class AppLocalizationsSk extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index d04579ac..c04c23ea 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -152,6 +152,9 @@ class AppLocalizationsSl extends AppLocalizations { String get urlImage_possible => 'Mogoča slika iz URL; omogočite jo v Nastavitvah.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Ponoviti'; @@ -1072,6 +1075,13 @@ class AppLocalizationsSl extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index b0e614da..e47b7b4e 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -150,6 +150,9 @@ class AppLocalizationsSv extends AppLocalizations { String get urlImage_possible => 'Möjlig URL-bild; aktivera den i Inställningar.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Starta om'; @@ -1061,6 +1064,13 @@ class AppLocalizationsSv extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 83d6424a..6407a997 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -150,6 +150,9 @@ class AppLocalizationsUk extends AppLocalizations { String get urlImage_possible => 'Можливе зображення за URL; увімкніть це в Налаштуваннях.'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => 'Перезавантажити'; @@ -1074,6 +1077,13 @@ class AppLocalizationsUk extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 714864c6..40a0c6c6 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -146,6 +146,9 @@ class AppLocalizationsZh extends AppLocalizations { @override String get urlImage_possible => '可能是URL图片,请在设置中启用。'; + @override + String get urlImage_disabledInAppSettings => 'Turned off in app settings'; + @override String get common_reboot => '重启'; @@ -1002,6 +1005,13 @@ class AppLocalizationsZh extends AppLocalizations { String get appSettings_ipfsImageLinksSubtitle => 'Upload for url Images (or Files) via IPFS provider and default gateway to receive'; + @override + String get appSettings_loadLinkImages => 'Load images from links'; + + @override + String get appSettings_loadLinkImagesSubtitle => + 'Show pictures from links in messages. Loading an image shares your IP address with the site that hosts it.'; + @override String get appSettings_publicIpfsGateway => 'Public gateway'; diff --git a/lib/main.dart b/lib/main.dart index eecb4132..db10b0fb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,7 @@ import 'screens/chrome_required_screen.dart'; import 'utils/platform_info.dart'; import 'connector/meshcore_connector.dart'; +import 'helpers/message_url_image_helper.dart'; import 'models/image_codec_support.dart'; import 'screens/scanner_screen.dart'; import 'services/image_chunk_transport.dart'; @@ -139,10 +140,14 @@ void main() async { notificationService.setPublicIpfsGateway( appSettingsService.settings.publicIpfsGateway, ); + MessageUrlImageHelper.loadLinkImages.value = + appSettingsService.settings.loadLinkImages; appSettingsService.addListener(() { notificationService.setPublicIpfsGateway( appSettingsService.settings.publicIpfsGateway, ); + MessageUrlImageHelper.loadLinkImages.value = + appSettingsService.settings.loadLinkImages; }); await notificationService.initialize(); await backgroundService.initialize(); diff --git a/lib/models/app_settings.dart b/lib/models/app_settings.dart index 64ccbfad..337e8fbd 100644 --- a/lib/models/app_settings.dart +++ b/lib/models/app_settings.dart @@ -147,6 +147,9 @@ class AppSettings { final int tcpServerPort; final bool jumpToOldestUnread; final bool imageMessagesEnabled; + + /// Master switch for fetching images behind links in messages. + final bool loadLinkImages; final String publicIpfsGateway; final String uploadIpfsGateway; final String uploadIpfsEndpoint; @@ -271,6 +274,7 @@ class AppSettings { this.jumpToOldestUnread = false, this.networkMapUploadEnabled = false, this.networkMapPromptShown = false, + this.loadLinkImages = true, this.publicIpfsGateway = defaultPublicIpfsGateway, this.uploadIpfsGateway = '', this.uploadIpfsEndpoint = '', @@ -366,6 +370,7 @@ class AppSettings { 'jump_to_oldest_unread': jumpToOldestUnread, 'network_map_upload_enabled': networkMapUploadEnabled, 'network_map_prompt_shown': networkMapPromptShown, + 'load_link_images': loadLinkImages, 'public_ipfs_gateway': publicIpfsGateway, 'upload_ipfs_gateway': uploadIpfsGateway, 'upload_ipfs_endpoint': uploadIpfsEndpoint, @@ -505,6 +510,7 @@ class AppSettings { networkMapUploadEnabled: json['network_map_upload_enabled'] as bool? ?? false, networkMapPromptShown: json['network_map_prompt_shown'] as bool? ?? false, + loadLinkImages: json['load_link_images'] as bool? ?? true, publicIpfsGateway: json['public_ipfs_gateway'] as String? ?? defaultPublicIpfsGateway, uploadIpfsGateway: json['upload_ipfs_gateway'] as String? ?? '', @@ -632,6 +638,7 @@ class AppSettings { bool? jumpToOldestUnread, bool? networkMapUploadEnabled, bool? networkMapPromptShown, + bool? loadLinkImages, String? publicIpfsGateway, String? uploadIpfsGateway, String? uploadIpfsEndpoint, @@ -726,6 +733,7 @@ class AppSettings { networkMapUploadEnabled ?? this.networkMapUploadEnabled, networkMapPromptShown: networkMapPromptShown ?? this.networkMapPromptShown, + loadLinkImages: loadLinkImages ?? this.loadLinkImages, publicIpfsGateway: publicIpfsGateway ?? this.publicIpfsGateway, uploadIpfsGateway: uploadIpfsGateway ?? this.uploadIpfsGateway, uploadIpfsEndpoint: uploadIpfsEndpoint ?? this.uploadIpfsEndpoint, diff --git a/lib/screens/app_settings_screen.dart b/lib/screens/app_settings_screen.dart index 5feadfcc..407c8f3f 100644 --- a/lib/screens/app_settings_screen.dart +++ b/lib/screens/app_settings_screen.dart @@ -685,6 +685,18 @@ class AppSettingsScreen extends StatelessWidget { ) { return Column( children: [ + SwitchListTile( + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 4, + ), + secondary: const Icon(Icons.image_search_outlined, size: 24), + title: Text(context.l10n.appSettings_loadLinkImages), + subtitle: Text(context.l10n.appSettings_loadLinkImagesSubtitle), + value: settingsService.settings.loadLinkImages, + onChanged: settingsService.setLoadLinkImages, + ), + const Divider(height: 1, indent: 16), ListTile( contentPadding: const EdgeInsets.symmetric( horizontal: 16, diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index f0cbcc19..06805668 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -815,9 +815,10 @@ class _ChannelChatScreenState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (MessageUrlImageHelper.hasPotentialImageUrl( - message.text, - )) + if (settingsService.settings.loadLinkImages && + MessageUrlImageHelper.hasPotentialImageUrl( + message.text, + )) Padding( padding: const EdgeInsets.only(bottom: 4), child: Text( diff --git a/lib/screens/channels_screen.dart b/lib/screens/channels_screen.dart index 53d561ac..f743efc6 100644 --- a/lib/screens/channels_screen.dart +++ b/lib/screens/channels_screen.dart @@ -1650,6 +1650,7 @@ class _ChannelsScreenState extends State bool smazEnabled = connector.isChannelSmazEnabled(channel.index); bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index); bool urlImagesEnabled = connector.isChannelUrlImagesEnabled(channel.index); + final loadLinkImages = appSettingsService.settings.loadLinkImages; String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId( channel.index, ); @@ -1769,9 +1770,19 @@ class _ChannelsScreenState extends State SwitchListTile( contentPadding: EdgeInsets.zero, title: Text(sheetContext.l10n.urlImage_enable), + subtitle: loadLinkImages + ? null + : Text( + sheetContext + .l10n + .urlImage_disabledInAppSettings, + ), value: urlImagesEnabled, - onChanged: (value) => - setSheetState(() => urlImagesEnabled = value), + onChanged: loadLinkImages + ? (value) => setSheetState( + () => urlImagesEnabled = value, + ) + : null, ), const SizedBox(height: 24), ], diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 81ea6577..43d30804 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -782,6 +782,10 @@ class _ChatScreenState extends State { bool urlImagesEnabled = connector.isContactUrlImagesEnabled( contact.publicKeyHex, ); + final loadLinkImages = context + .read() + .settings + .loadLinkImages; String? selectedCyr2LatProfileId = connector.getContactCyr2LatProfileId( contact.publicKeyHex, ); @@ -896,14 +900,19 @@ class _ChatScreenState extends State { SwitchListTile( contentPadding: EdgeInsets.zero, title: Text(context.l10n.urlImage_enable), + subtitle: loadLinkImages + ? null + : Text(context.l10n.urlImage_disabledInAppSettings), value: urlImagesEnabled, - onChanged: (value) { - connector.setContactUrlImagesEnabled( - contact.publicKeyHex, - value, - ); - setDialogState(() => urlImagesEnabled = value); - }, + onChanged: loadLinkImages + ? (value) { + connector.setContactUrlImagesEnabled( + contact.publicKeyHex, + value, + ); + setDialogState(() => urlImagesEnabled = value); + } + : null, ), const Divider(height: 8), SwitchListTile( @@ -1432,9 +1441,10 @@ class _MessageBubble extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (MessageUrlImageHelper.hasPotentialImageUrl( - message.text, - )) + if (settingsService.settings.loadLinkImages && + MessageUrlImageHelper.hasPotentialImageUrl( + message.text, + )) Padding( padding: const EdgeInsets.only(bottom: 4), child: Text( diff --git a/lib/services/app_settings_service.dart b/lib/services/app_settings_service.dart index 7bd5ba65..7bd1fbf2 100644 --- a/lib/services/app_settings_service.dart +++ b/lib/services/app_settings_service.dart @@ -328,6 +328,10 @@ class AppSettingsService extends ChangeNotifier { await updateSettings(_settings.copyWith(networkMapPromptShown: value)); } + Future setLoadLinkImages(bool value) async { + await updateSettings(_settings.copyWith(loadLinkImages: value)); + } + Future setIpfsImageSettings({ required String publicGateway, required String uploadGateway, diff --git a/test/helpers/message_url_image_helper_test.dart b/test/helpers/message_url_image_helper_test.dart index 900b0a01..a8a21a2e 100644 --- a/test/helpers/message_url_image_helper_test.dart +++ b/test/helpers/message_url_image_helper_test.dart @@ -5,7 +5,10 @@ import 'package:meshcore_open/helpers/message_url_image_helper.dart'; void main() { group('MessageUrlImageHelper', () { - tearDown(() => MessageUrlImageHelper.httpClient = null); + tearDown(() { + MessageUrlImageHelper.httpClient = null; + MessageUrlImageHelper.loadLinkImages.value = true; + }); void mockPyxPage(String id) { MessageUrlImageHelper.httpClient = MockClient((request) async { @@ -120,5 +123,26 @@ void main() { expect(attachment, isNull); }); + + test('fetches nothing when loading link images is off', () async { + MessageUrlImageHelper.loadLinkImages.value = false; + MessageUrlImageHelper.httpClient = MockClient((request) async { + fail('Unexpected request to ${request.url}'); + }); + + for (final text in [ + 'https://pyx.li/?i=RzmdkTsE', + 'https://ibb.co/abc123', + 'ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi', + 'https://example.com/photo.png', + ]) { + expect(await MessageUrlImageHelper.parse(text), isNull); + expect(await MessageUrlImageHelper.parseVerified(text), isNull); + expect( + await MessageUrlImageHelper.parseVerifiedForMessage('m1', text), + isNull, + ); + } + }); }); } diff --git a/test/models/model_changes_test.dart b/test/models/model_changes_test.dart index 94a7eb2a..9c46be93 100644 --- a/test/models/model_changes_test.dart +++ b/test/models/model_changes_test.dart @@ -443,6 +443,13 @@ void main() { expect(settings.evictDiscoveredContactsEnabled, isFalse); }); + test('load link images defaults on and round-trips through JSON', () { + expect(AppSettings().loadLinkImages, isTrue); + expect(AppSettings.fromJson({}).loadLinkImages, isTrue); + final saved = AppSettings(loadLinkImages: false).toJson(); + expect(AppSettings.fromJson(saved).loadLinkImages, isFalse); + }); + test('public IPFS gateway defaults to ipfs.io when never set', () { expect( AppSettings.fromJson({}).publicIpfsGateway, diff --git a/untranslated.json b/untranslated.json index 73747889..07b30a44 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1,8 +1,11 @@ { "bg": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -51,9 +54,12 @@ ], "de": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -102,9 +108,12 @@ ], "es": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -153,9 +162,12 @@ ], "fr": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -204,9 +216,12 @@ ], "hu": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -255,9 +270,12 @@ ], "it": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -306,9 +324,12 @@ ], "ja": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -357,9 +378,12 @@ ], "ko": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -408,9 +432,12 @@ ], "nl": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -459,9 +486,12 @@ ], "pl": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -510,9 +540,12 @@ ], "pt": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -561,9 +594,12 @@ ], "ru": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -612,9 +648,12 @@ ], "sk": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -663,9 +702,12 @@ ], "sl": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -714,9 +756,12 @@ ], "sv": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -765,9 +810,12 @@ ], "uk": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo", @@ -816,9 +864,12 @@ ], "zh": [ + "urlImage_disabledInAppSettings", "settings_pathHashModeNotApplied", "appSettings_ipfsImageLinks", "appSettings_ipfsImageLinksSubtitle", + "appSettings_loadLinkImages", + "appSettings_loadLinkImagesSubtitle", "appSettings_publicIpfsGateway", "appSettings_ipfsGatewayDeactivated", "appSettings_ipfsGatewayIpfsIo",