Add a setting to show link images in all chats by default

'Show link images in all chats by default' (default off) applies to
every channel and contact without an explicit per-chat choice: the
per-chat setting is now unset/on/off and resolves to perChat ?? default.
The 'Load images from links' master switch still overrides it.
This commit is contained in:
zjs81 committed 2026-10-24 22:01:30 -07:00
1 parent 79e3668c18
commit a4670a9275
30 files changed
+330 -16

No files matched your search

+20 -5
View File
@@ -491,7 +491,7 @@ class MeshCoreConnector extends ChangeNotifier {
List<Channel> _cachedChannels = [];
final Map<int, bool> _channelSmazEnabled = {};
final Map<int, bool> _channelCyr2LatEnabled = {};
final Map<int, bool> _channelUrlImagesEnabled = {};
final Map<int, bool?> _channelUrlImagesEnabled = {};
final Map<int, String?> _channelCyr2LatProfileId = {};
final Map<int, Region> _channelRegions = {};
Region _defaultRegion = '';
@@ -501,7 +501,7 @@ class MeshCoreConnector extends ChangeNotifier {
Uint8List? _defaultFloodScopeKey;
final Map<String, bool> _contactSmazEnabled = {};
final Map<String, bool> _contactCyr2LatEnabled = {};
final Map<String, bool> _contactUrlImagesEnabled = {};
final Map<String, bool?> _contactUrlImagesEnabled = {};
final Map<String, String?> _contactCyr2LatProfileId = {};
final Set<String> _knownContactKeys = {};
final Map<String, int> _contactUnreadCount = {};
@@ -1059,13 +1059,25 @@ class MeshCoreConnector extends ChangeNotifier {
return _contactSmazEnabled[contactKeyHex] ?? false;
}
bool _lastShowLinkImagesByDefault = false;
void _onAppSettingsChanged() {
final showByDefault = _showLinkImagesByDefault;
if (showByDefault == _lastShowLinkImagesByDefault) return;
_lastShowLinkImagesByDefault = showByDefault;
notifyListeners();
}
bool get _showLinkImagesByDefault =>
_appSettingsService?.settings.showLinkImagesByDefault ?? false;
bool isChannelUrlImagesEnabled(int channelIndex) {
return _channelUrlImagesEnabled[channelIndex] ?? false;
return _channelUrlImagesEnabled[channelIndex] ?? _showLinkImagesByDefault;
}
bool isContactUrlImagesEnabled(String contactKeyHex) {
_ensureContactUrlImagesSettingLoaded(contactKeyHex);
return _contactUrlImagesEnabled[contactKeyHex] ?? false;
return _contactUrlImagesEnabled[contactKeyHex] ?? _showLinkImagesByDefault;
}
/// True when the channel has its own (real) region assigned.
@@ -1621,6 +1633,8 @@ class MeshCoreConnector extends ChangeNotifier {
_retryService = retryService;
_pathHistoryService = pathHistoryService;
_appSettingsService = appSettingsService;
_lastShowLinkImagesByDefault = _showLinkImagesByDefault;
appSettingsService?.addListener(_onAppSettingsChanged);
_translationService = translationService;
_imageCodecService = imageCodecService;
_imageTransport = imageTransport;
@@ -7320,7 +7334,7 @@ class MeshCoreConnector extends ChangeNotifier {
void _ensureContactUrlImagesSettingLoaded(String contactKeyHex) {
if (_contactUrlImagesEnabled.containsKey(contactKeyHex)) return;
_contactSettingsStore.loadUrlImagesEnabled(contactKeyHex).then((enabled) {
if (_contactUrlImagesEnabled[contactKeyHex] == enabled) return;
if (_contactUrlImagesEnabled.containsKey(contactKeyHex)) return;
_contactUrlImagesEnabled[contactKeyHex] = enabled;
notifyListeners();
});
@@ -8874,6 +8888,7 @@ class MeshCoreConnector extends ChangeNotifier {
@override
void dispose() {
_disposed = true;
_appSettingsService?.removeListener(_onAppSettingsChanged);
_scanSubscription?.cancel();
_isScanningSubscription?.cancel();
_connectionSubscription?.cancel();
+2
View File
@@ -458,6 +458,8 @@
"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_showLinkImagesByDefault": "Show link images in all chats by default",
"appSettings_showLinkImagesByDefaultSubtitle": "Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.",
"appSettings_publicIpfsGateway": "Public gateway",
"appSettings_ipfsGatewayDeactivated": "Deactivated",
"appSettings_ipfsGatewayIpfsIo": "ipfs.io",
+12
View File
@@ -1984,6 +1984,18 @@ abstract class AppLocalizations {
/// **'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_showLinkImagesByDefault.
///
/// In en, this message translates to:
/// **'Show link images in all chats by default'**
String get appSettings_showLinkImagesByDefault;
/// No description provided for @appSettings_showLinkImagesByDefaultSubtitle.
///
/// In en, this message translates to:
/// **'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.'**
String get appSettings_showLinkImagesByDefaultSubtitle;
/// No description provided for @appSettings_publicIpfsGateway.
///
/// In en, this message translates to:
+8
View File
@@ -1093,6 +1093,14 @@ class AppLocalizationsBg extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1088,6 +1088,14 @@ class AppLocalizationsDe extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1072,6 +1072,14 @@ class AppLocalizationsEn extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1085,6 +1085,14 @@ class AppLocalizationsEs extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1091,6 +1091,14 @@ class AppLocalizationsFr extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1080,6 +1080,14 @@ class AppLocalizationsHu extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1091,6 +1091,14 @@ class AppLocalizationsIt extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1028,6 +1028,14 @@ class AppLocalizationsJa extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1032,6 +1032,14 @@ class AppLocalizationsKo extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1081,6 +1081,14 @@ class AppLocalizationsNl extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1097,6 +1097,14 @@ class AppLocalizationsPl extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1089,6 +1089,14 @@ class AppLocalizationsPt extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1094,6 +1094,14 @@ class AppLocalizationsRu extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1080,6 +1080,14 @@ class AppLocalizationsSk extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1082,6 +1082,14 @@ class AppLocalizationsSl extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1071,6 +1071,14 @@ class AppLocalizationsSv extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1084,6 +1084,14 @@ class AppLocalizationsUk extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+8
View File
@@ -1012,6 +1012,14 @@ class AppLocalizationsZh extends AppLocalizations {
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_showLinkImagesByDefault =>
'Show link images in all chats by default';
@override
String get appSettings_showLinkImagesByDefaultSubtitle =>
'Load link images in every chat unless you turned them off there. This shares your IP address with image hosts in every chat.';
@override
String get appSettings_publicIpfsGateway => 'Public gateway';
+10
View File
@@ -150,6 +150,9 @@ class AppSettings {
/// Master switch for fetching images behind links in messages.
final bool loadLinkImages;
/// Chats with no saved link-image choice load link images when true.
final bool showLinkImagesByDefault;
final String publicIpfsGateway;
final String uploadIpfsGateway;
final String uploadIpfsEndpoint;
@@ -275,6 +278,7 @@ class AppSettings {
this.networkMapUploadEnabled = false,
this.networkMapPromptShown = false,
this.loadLinkImages = true,
this.showLinkImagesByDefault = false,
this.publicIpfsGateway = defaultPublicIpfsGateway,
this.uploadIpfsGateway = '',
this.uploadIpfsEndpoint = '',
@@ -371,6 +375,7 @@ class AppSettings {
'network_map_upload_enabled': networkMapUploadEnabled,
'network_map_prompt_shown': networkMapPromptShown,
'load_link_images': loadLinkImages,
'show_link_images_by_default': showLinkImagesByDefault,
'public_ipfs_gateway': publicIpfsGateway,
'upload_ipfs_gateway': uploadIpfsGateway,
'upload_ipfs_endpoint': uploadIpfsEndpoint,
@@ -511,6 +516,8 @@ class AppSettings {
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,
showLinkImagesByDefault:
json['show_link_images_by_default'] as bool? ?? false,
publicIpfsGateway:
json['public_ipfs_gateway'] as String? ?? defaultPublicIpfsGateway,
uploadIpfsGateway: json['upload_ipfs_gateway'] as String? ?? '',
@@ -639,6 +646,7 @@ class AppSettings {
bool? networkMapUploadEnabled,
bool? networkMapPromptShown,
bool? loadLinkImages,
bool? showLinkImagesByDefault,
String? publicIpfsGateway,
String? uploadIpfsGateway,
String? uploadIpfsEndpoint,
@@ -734,6 +742,8 @@ class AppSettings {
networkMapPromptShown:
networkMapPromptShown ?? this.networkMapPromptShown,
loadLinkImages: loadLinkImages ?? this.loadLinkImages,
showLinkImagesByDefault:
showLinkImagesByDefault ?? this.showLinkImagesByDefault,
publicIpfsGateway: publicIpfsGateway ?? this.publicIpfsGateway,
uploadIpfsGateway: uploadIpfsGateway ?? this.uploadIpfsGateway,
uploadIpfsEndpoint: uploadIpfsEndpoint ?? this.uploadIpfsEndpoint,
+16
View File
@@ -697,6 +697,22 @@ class AppSettingsScreen extends StatelessWidget {
onChanged: settingsService.setLoadLinkImages,
),
const Divider(height: 1, indent: 16),
SwitchListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
secondary: const Icon(Icons.collections_outlined, size: 24),
title: Text(context.l10n.appSettings_showLinkImagesByDefault),
subtitle: Text(
context.l10n.appSettings_showLinkImagesByDefaultSubtitle,
),
value: settingsService.settings.showLinkImagesByDefault,
onChanged: settingsService.settings.loadLinkImages
? settingsService.setShowLinkImagesByDefault
: null,
),
const Divider(height: 1, indent: 16),
ListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
+11 -5
View File
@@ -1649,7 +1649,10 @@ class _ChannelsScreenState extends State<ChannelsScreen>
);
bool smazEnabled = connector.isChannelSmazEnabled(channel.index);
bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index);
bool urlImagesEnabled = connector.isChannelUrlImagesEnabled(channel.index);
final initialUrlImagesEnabled = connector.isChannelUrlImagesEnabled(
channel.index,
);
bool urlImagesEnabled = initialUrlImagesEnabled;
final loadLinkImages = appSettingsService.settings.loadLinkImages;
String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId(
channel.index,
@@ -1842,10 +1845,13 @@ class _ChannelsScreenState extends State<ChannelsScreen>
channel.index,
cyr2latEnabled,
);
await connector.setChannelUrlImagesEnabled(
channel.index,
urlImagesEnabled,
);
if (urlImagesEnabled !=
initialUrlImagesEnabled) {
await connector.setChannelUrlImagesEnabled(
channel.index,
urlImagesEnabled,
);
}
await connector.setChannelCyr2LatProfileId(
channel.index,
selectedCyr2LatProfileId,
+4
View File
@@ -332,6 +332,10 @@ class AppSettingsService extends ChangeNotifier {
await updateSettings(_settings.copyWith(loadLinkImages: value));
}
Future<void> setShowLinkImagesByDefault(bool value) async {
await updateSettings(_settings.copyWith(showLinkImagesByDefault: value));
}
Future<void> setIpfsImageSettings({
required String publicGateway,
required String uploadGateway,
+3 -3
View File
@@ -60,14 +60,14 @@ class ChannelSettingsStore {
await PrefsManager.instance.setBool(_cyr2LatKey(channelId), enabled);
}
Future<bool> loadUrlImagesEnabled(String channelId) async {
Future<bool?> loadUrlImagesEnabled(String channelId) async {
if (publicKeyHex.isEmpty) {
appLogger.warn(
'Public key hex is not set. Cannot load channel URL image settings.',
);
return false;
return null;
}
return PrefsManager.instance.getBool(_urlImagesKey(channelId)) ?? false;
return PrefsManager.instance.getBool(_urlImagesKey(channelId));
}
Future<void> saveUrlImagesEnabled(String channelId, bool enabled) async {
+3 -3
View File
@@ -76,16 +76,16 @@ class ContactSettingsStore {
await prefs.setBool(key, enabled);
}
Future<bool> loadUrlImagesEnabled(String contactKeyHex) async {
Future<bool?> loadUrlImagesEnabled(String contactKeyHex) async {
if (publicKeyHex.isEmpty) {
appLogger.warn(
'Public key hex is not set. Cannot load contact URL image settings.',
);
return false;
return null;
}
final prefs = PrefsManager.instance;
final key = '$keyForUrlImages$contactKeyHex';
return prefs.getBool(key) ?? false;
return prefs.getBool(key);
}
Future<void> saveUrlImagesEnabled(String contactKeyHex, bool enabled) async {