Skip to content

Commit 13b4d52

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 93ffc37 commit 13b4d52

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
@@ -669,10 +669,12 @@ class MessageContent extends HookConsumerWidget {
669669
}
670670

671671
try {
672+
// Prefer the attachment's imeta filename so a prose link label
673+
// ("Quarterly report") does not replace the real name and extension.
672674
await ref.read(openDownloadedFileProvider)(
673675
url,
674676
auth.headersFor(url),
675-
text,
677+
imeta?.filename ?? text,
676678
);
677679
} catch (_) {
678680
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
@@ -506,6 +506,43 @@ void main() {
506506
expect(openedHeaders?['Authorization'], startsWith('Nostr '));
507507
});
508508

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

0 commit comments

Comments
 (0)