Skip to content

Commit 435c2da

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 bd1ff00 commit 435c2da

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
@@ -537,10 +537,12 @@ class MessageContent extends HookConsumerWidget {
537537
}
538538

539539
try {
540+
// Prefer the attachment's imeta filename so a prose link label
541+
// ("Quarterly report") does not replace the real name and extension.
540542
await ref.read(openDownloadedFileProvider)(
541543
url,
542544
auth.headersFor(url),
543-
text,
545+
imeta?.filename ?? text,
544546
);
545547
} catch (_) {
546548
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)