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.
This commit is contained in:
zjs81 committed 2026-10-24 22:01:29 -07:00
1 parent 7f5f71d070
commit 79e3668c18
31 files changed
+381 -33

No files matched your search

+31 -17
View File
@@ -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<bool> loadLinkImages = ValueNotifier<bool>(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<String?>.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<String?> _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
+3
View File
@@ -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",
+18
View File
@@ -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:
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+10
View File
@@ -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';
+5
View File
@@ -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();
+8
View File
@@ -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,
+12
View File
@@ -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,
+4 -3
View File
@@ -815,9 +815,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
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(
+13 -2
View File
@@ -1650,6 +1650,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
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<ChannelsScreen>
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),
],
+20 -10
View File
@@ -782,6 +782,10 @@ class _ChatScreenState extends State<ChatScreen> {
bool urlImagesEnabled = connector.isContactUrlImagesEnabled(
contact.publicKeyHex,
);
final loadLinkImages = context
.read<AppSettingsService>()
.settings
.loadLinkImages;
String? selectedCyr2LatProfileId = connector.getContactCyr2LatProfileId(
contact.publicKeyHex,
);
@@ -896,14 +900,19 @@ class _ChatScreenState extends State<ChatScreen> {
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(
+4
View File
@@ -328,6 +328,10 @@ class AppSettingsService extends ChangeNotifier {
await updateSettings(_settings.copyWith(networkMapPromptShown: value));
}
Future<void> setLoadLinkImages(bool value) async {
await updateSettings(_settings.copyWith(loadLinkImages: value));
}
Future<void> setIpfsImageSettings({
required String publicGateway,
required String uploadGateway,
@@ -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,
);
}
});
});
}
+7
View File
@@ -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,
+51
View File
@@ -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",