From 34c65765ba1c6bf7c143e7bd076f27809d6a3c70 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Sat, 31 Oct 2026 20:39:56 +0100 Subject: [PATCH] fix: call a sharee without a name unknown person in every share sheet --- src/components/files/ShareSheet.tsx | 3 ++- .../sharing/ShareCollectionSheet.tsx | 3 ++- .../sharing/__tests__/unknown-person.test.ts | 25 +++++++++++++++++++ src/components/sharing/unknown-person.ts | 10 ++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/components/sharing/__tests__/unknown-person.test.ts create mode 100644 src/components/sharing/unknown-person.ts diff --git a/src/components/files/ShareSheet.tsx b/src/components/files/ShareSheet.tsx index 3fee704d..7121f29e 100644 --- a/src/components/files/ShareSheet.tsx +++ b/src/components/files/ShareSheet.tsx @@ -21,6 +21,7 @@ import { spacing, radius, typography, type ThemePalette } from '../../theme/toke import { useColors } from '../../theme/colors'; import { useLocaleStore } from '../../stores/locale-store'; import { MODAL_ORIENTATIONS } from '../../lib/modal-orientations'; +import { unknownPersonLabel } from '../sharing/unknown-person'; import { useSheetInsets } from '../../lib/use-layout'; import { useSheetBottomInset } from '../../lib/sheet-bottom-inset'; @@ -172,7 +173,7 @@ export default function ShareSheet({ node, onClose, onChanged }: ShareSheetProps // Stalwart 1.0 with directory queries off hides every principal the user // has no relationship with, so a sharee may have no name. const unresolved = !p && !loadingPrincipals; - return p?.description || p?.name || (unresolved ? t('sharing.unknown_user', 'Unknown user') : principalId); + return p?.description || p?.name || (unresolved ? unknownPersonLabel(t) : principalId); }; const renderPrincipalLabel = (principalId: string) => { diff --git a/src/components/sharing/ShareCollectionSheet.tsx b/src/components/sharing/ShareCollectionSheet.tsx index 5d2b3d69..e288c153 100644 --- a/src/components/sharing/ShareCollectionSheet.tsx +++ b/src/components/sharing/ShareCollectionSheet.tsx @@ -21,6 +21,7 @@ import { spacing, radius, typography, type ThemePalette } from '../../theme/toke import { useColors } from '../../theme/colors'; import { useLocaleStore } from '../../stores/locale-store'; import { MODAL_ORIENTATIONS } from '../../lib/modal-orientations'; +import { unknownPersonLabel } from './unknown-person'; import { useSheetInsets } from '../../lib/use-layout'; import { useSheetBottomInset } from '../../lib/sheet-bottom-inset'; @@ -200,7 +201,7 @@ export function ShareCollectionSheet({ return ( - {p?.description || p?.name || (unresolved ? t('sharing.unknown_user', 'Unknown user') : principalId)} + {p?.description || p?.name || (unresolved ? unknownPersonLabel(t) : principalId)} {/* Never the id in its place: Stalwart 1.0's are a letter or two ("e") and read as a broken address. */} diff --git a/src/components/sharing/__tests__/unknown-person.test.ts b/src/components/sharing/__tests__/unknown-person.test.ts new file mode 100644 index 00000000..31f37554 --- /dev/null +++ b/src/components/sharing/__tests__/unknown-person.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from 'vitest'; +import fs from 'node:fs'; +import path from 'node:path'; +import { unknownPersonLabel } from '../unknown-person'; +import { principalRowDisplay } from '../../../lib/delegation/display'; + +// Settings > Sharing said "Unknown person", the folder share sheet "Unknown user". + +const t = (_key: string, fallback?: string) => fallback ?? ''; +const read = (rel: string) => fs.readFileSync(path.resolve(__dirname, '..', '..', '..', rel), 'utf8'); + +describe('a sharee without a name', () => { + it('reads like Settings > Sharing', () => { + expect(unknownPersonLabel(t)).toBe('Unknown person'); + expect(unknownPersonLabel((key) => key)).toBe(principalRowDisplay(null, (key) => key).name); + }); + + it('is what the folder, calendar, address book and file share sheets show', () => { + for (const file of ['components/sharing/ShareCollectionSheet.tsx', 'components/files/ShareSheet.tsx']) { + const src = read(file); + expect(src, file).not.toMatch(/sharing\.unknown_user|Unknown user/); + expect(src, file).toMatch(/unresolved \? unknownPersonLabel\(t\) : principalId/); + } + }); +}); diff --git a/src/components/sharing/unknown-person.ts b/src/components/sharing/unknown-person.ts new file mode 100644 index 00000000..e36634ce --- /dev/null +++ b/src/components/sharing/unknown-person.ts @@ -0,0 +1,10 @@ +type Translate = (key: string, fallback?: string) => string; + +/** + * A sharee the server shows no name for (Stalwart 1.0 with directory queries + * off). One wording everywhere: Settings > Sharing (lib/delegation/display) + * said "Unknown person", the folder and file share sheets "Unknown user". + */ +export function unknownPersonLabel(t: Translate): string { + return t('delegates.unknown_person', 'Unknown person'); +}