Skip to content

Commit 52e962f

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 e9269cb commit 52e962f

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
@@ -539,10 +539,12 @@ class MessageContent extends HookConsumerWidget {
539539
}
540540

541541
try {
542+
// Prefer the attachment's imeta filename so a prose link label
543+
// ("Quarterly report") does not replace the real name and extension.
542544
await ref.read(openDownloadedFileProvider)(
543545
url,
544546
auth.headersFor(url),
545-
text,
547+
imeta?.filename ?? text,
546548
);
547549
} catch (_) {
548550
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
@@ -499,6 +499,43 @@ void main() {
499499
expect(openedHeaders?['Authorization'], startsWith('Nostr '));
500500
});
501501

502+
testWidgets('opens attachments under the imeta filename, not the link text', (
503+
tester,
504+
) async {
505+
const url = 'https://relay.example/media/sha256.pdf';
506+
String? openedFilename;
507+
final auth = MediaGetAuthService(
508+
baseUrl: 'https://relay.example',
509+
nsec: nostr.Keys.generate().nsec,
510+
);
511+
512+
await tester.pumpWidget(
513+
_testable(
514+
const MessageContent(
515+
content: '[Quarterly report]($url)',
516+
tags: [
517+
[
518+
'imeta',
519+
'url $url',
520+
'filename q3-report.pdf',
521+
],
522+
],
523+
),
524+
overrides: [
525+
mediaGetAuthServiceProvider.overrideWithValue(auth),
526+
openDownloadedFileProvider.overrideWithValue((url, headers, filename) async {
527+
openedFilename = filename;
528+
}),
529+
],
530+
),
531+
);
532+
533+
await tester.tap(find.text('Quarterly report'));
534+
await tester.pump();
535+
536+
expect(openedFilename, 'q3-report.pdf');
537+
});
538+
502539
test('buildImageViewerRoute uses modal-style page route builder', () {
503540
final route = buildImageViewerRoute(
504541
imageUrl: 'https://example.com/media/image.png',

0 commit comments

Comments
 (0)