Skip to content

Commit b49e87c

Browse files
committed
fix(mobile): open attachments under the imeta filename
Tapping a relay file attachment opened the download under the Markdown link text. When that label is prose, the saved file lost the real name and extension, so the system viewer could not recognize it. Prefer the NIP-92 imeta filename and fall back to the link text. Fixes block#8065 Signed-off-by: Bartok9 <[email protected]>
1 parent f0eb557 commit b49e87c

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎mobile/lib/features/channels/message_content.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,12 @@ class MessageContent extends HookConsumerWidget {
536536
}
537537

538538
try {
539+
// Prefer the attachment's imeta filename so a prose link label
540+
// ("Quarterly report") does not replace the real name and extension.
539541
await ref.read(openDownloadedFileProvider)(
540542
url,
541543
auth.headersFor(url),
542-
text,
544+
imeta?.filename ?? text,
543545
);
544546
} catch (_) {
545547
if (!context.mounted) return;

‎mobile/test/features/channels/message_content_test.dart‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,43 @@ void main() {
481481
expect(openedHeaders?['Authorization'], startsWith('Nostr '));
482482
});
483483

484+
testWidgets('opens attachments under the imeta filename, not the link text', (
485+
tester,
486+
) async {
487+
const url = 'https://relay.example/media/sha256.pdf';
488+
String? openedFilename;
489+
final auth = MediaGetAuthService(
490+
baseUrl: 'https://relay.example',
491+
nsec: nostr.Keys.generate().nsec,
492+
);
493+
494+
await tester.pumpWidget(
495+
_testable(
496+
const MessageContent(
497+
content: '[Quarterly report]($url)',
498+
tags: [
499+
[
500+
'imeta',
501+
'url $url',
502+
'filename q3-report.pdf',
503+
],
504+
],
505+
),
506+
overrides: [
507+
mediaGetAuthServiceProvider.overrideWithValue(auth),
508+
openDownloadedFileProvider.overrideWithValue((url, headers, filename) async {
509+
openedFilename = filename;
510+
}),
511+
],
512+
),
513+
);
514+
515+
await tester.tap(find.text('Quarterly report'));
516+
await tester.pump();
517+
518+
expect(openedFilename, 'q3-report.pdf');
519+
});
520+
484521
test('buildImageViewerRoute uses modal-style page route builder', () {
485522
final route = buildImageViewerRoute(
486523
imageUrl: 'https://example.com/media/image.png',

0 commit comments

Comments
 (0)