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

@@ -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,