Skip to content

Commit 6d637a8

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 4dea51f commit 6d637a8

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
@@ -708,10 +708,12 @@ class MessageContent extends HookConsumerWidget {
708708
}
709709

710710
try {
711+
// Prefer the attachment's imeta filename so a prose link label
712+
// ("Quarterly report") does not replace the real name and extension.
711713
await ref.read(openDownloadedFileProvider)(
712714
url,
713715
auth.headersFor(url),
714-
text,
716+
imeta?.filename ?? text,
715717
);
716718
} catch (_) {
717719
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
@@ -508,6 +508,43 @@ void main() {
508508
expect(openedHeaders?['Authorization'], startsWith('Nostr '));
509509
});
510510

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

0 commit comments

Comments
 (0)