Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(core/user): replace calls to useDisplayName with getDisplayName to remove stale username bugs (#5471)

Seamusb1e9a0770e8d
diff --git a/apps/web/src/components/app/app-sidebar/sidebar.tsx b/apps/web/src/components/app/app-sidebar/sidebar.tsx
index 71d86e0323..42ba8bfe0b 100644
--- a/apps/web/src/components/app/app-sidebar/sidebar.tsx
+++ b/apps/web/src/components/app/app-sidebar/sidebar.tsx
@@ -67,7 +67,7 @@ import { clearPressedKeys } from '@core/hotkey/state';
import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';
import type { ValidHotkey } from '@core/hotkey/types';
import { activateClosestDOMScope } from '@core/hotkey/utils';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import LogoIcon from '@icon/macro-logo.svg';
import { AnimatedActivityIcon } from '@icon/wide-activity';
import WideCalendarIcon from '@icon/wide-calendar.svg';
@@ -1087,7 +1087,7 @@ const buildSidebarLinks = (
};
const TeamInviteSidebarPromo = (props: { invite: TeamInviteDetails }) => {
- const [inviterName] = useDisplayName(tryMacroId(props.invite.invited_by));
+ const inviterName = () => getDisplayName(tryMacroId(props.invite.invited_by));
const joinTeamMutation = useJoinTeamMutation();
const rejectInvitationMutation = useRejectInvitationMutation();
const mutationPending = () =>
diff --git a/apps/web/src/components/app/app-sidebar/utils.ts b/apps/web/src/components/app/app-sidebar/utils.ts
index c1b70e509e..515e40df67 100644
--- a/apps/web/src/components/app/app-sidebar/utils.ts
+++ b/apps/web/src/components/app/app-sidebar/utils.ts
@@ -1,10 +1,10 @@
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, tryMacroId } from '@core/user';
export function useSenderName(senderId: string | null | undefined) {
- const nameParts = useDisplayNameParts(tryMacroId(senderId ?? ''));
return () => {
- const firstName = nameParts.firstName();
- const fullName = nameParts.fullName();
+ const { firstName, fullName } = getDisplayNameParts(
+ tryMacroId(senderId ?? '')
+ );
if (firstName || fullName) {
return firstName || fullName;
}
diff --git a/apps/web/src/components/app/side-panel/FileSidePanelSections.tsx b/apps/web/src/components/app/side-panel/FileSidePanelSections.tsx
index 49a9350f02..8b674fae86 100644
--- a/apps/web/src/components/app/side-panel/FileSidePanelSections.tsx
+++ b/apps/web/src/components/app/side-panel/FileSidePanelSections.tsx
@@ -7,7 +7,7 @@ import { EntityIcon } from '@core/component/EntityIcon';
import { openDocument } from '@core/component/LexicalMarkdown/component/core/BlockLink';
import { UserIcon } from '@core/component/UserIcon';
import { useCanEdit } from '@core/signal/permissions';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';
import { type DateValue, formatDate } from '@core/util/date';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
@@ -149,7 +149,7 @@ export function FolderLink(props: { projectId: string; projectName: string }) {
}
export function OwnerValue(props: { ownerId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.ownerId));
+ const displayName = () => getDisplayName(tryMacroId(props.ownerId));
return (
<SidePanel.Pill>
diff --git a/apps/web/src/features/block-call/component/sidepanel/CallSidePanelSections.tsx b/apps/web/src/features/block-call/component/sidepanel/CallSidePanelSections.tsx
index e24f58e3ab..c54b5a1072 100644
--- a/apps/web/src/features/block-call/component/sidepanel/CallSidePanelSections.tsx
+++ b/apps/web/src/features/block-call/component/sidepanel/CallSidePanelSections.tsx
@@ -4,7 +4,7 @@ import { SidePanel } from '@components/app/side-panel';
import { useBlockId } from '@core/block';
import { References } from '@core/component/References';
import { UserIcon } from '@core/component/UserIcon';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { type DateValue, formatDate } from '@core/util/date';
import ClockIcon from '@phosphor/clock.svg';
import {
@@ -113,7 +113,7 @@ function PropertiesSectionContent(props: { record: Accessor<CallRecord> }) {
}
function OwnerValue(props: { ownerId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.ownerId));
+ const displayName = () => getDisplayName(tryMacroId(props.ownerId));
return (
<SidePanel.Pill>
<UserIcon id={props.ownerId} size="sm" showTooltip suppressClick />
diff --git a/apps/web/src/features/block-channel/component/Compose.tsx b/apps/web/src/features/block-channel/component/Compose.tsx
index 063d1abf34..a8899d1dfd 100644
--- a/apps/web/src/features/block-channel/component/Compose.tsx
+++ b/apps/web/src/features/block-channel/component/Compose.tsx
@@ -24,8 +24,8 @@ import { RecipientSelector } from '@core/component/RecipientSelector';
import { isMobile } from '@core/mobile/isMobile';
import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
import {
+ getDisplayName,
tryMacroId,
- useDisplayName,
type WithCustomUserInput,
} from '@core/user';
import { useSendMessageToPeople } from '@core/util/channels';
@@ -69,10 +69,9 @@ export function ChannelCompose() {
return undefined;
});
- const dmUserName = createMemo<() => string | undefined>(() => {
+ const dmUserName = createMemo(() => {
const id = dmUserId();
- if (!id) return () => undefined;
- return useDisplayName(tryMacroId(id))[0];
+ return id ? getDisplayName(tryMacroId(id)) : undefined;
});
const [triedToSubmit, _setTriedToSubmit] = createSignal(false);
@@ -82,14 +81,14 @@ export function ChannelCompose() {
if (recipients.length === 0) {
return 'Draft message';
} else if (recipients.length === 1) {
- const dmName = dmUserName()();
+ const dmName = dmUserName();
return dmName ? `DM with ${dmName}` : 'Draft message';
} else {
const names = recipients
.slice(0, 2)
.map((r) => {
if (r.kind === 'user') {
- return useDisplayName(tryMacroId(r.data.id))[0]();
+ return getDisplayName(tryMacroId(r.data.id));
}
return r.data.email || 'Unknown';
})
diff --git a/apps/web/src/features/block-email/component/FromInboxSelector.tsx b/apps/web/src/features/block-email/component/FromInboxSelector.tsx
index ed8bc9151e..37ab84a410 100644
--- a/apps/web/src/features/block-email/component/FromInboxSelector.tsx
+++ b/apps/web/src/features/block-email/component/FromInboxSelector.tsx
@@ -1,6 +1,6 @@
import { inboxIconProps } from '@core/component/inboxIcon';
import { UserIcon } from '@core/component/UserIcon';
-import { emailToMacroId, useDisplayName } from '@core/user';
+import { emailToMacroId, getDisplayName } from '@core/user';
import ChevronDown from '@phosphor/caret-down.svg';
import Check from '@phosphor/check.svg';
import { cn, Dropdown } from '@ui';
@@ -14,7 +14,7 @@ type FromInbox = {
/** A single inbox: the account's user icon, name, and address. */
function FromInboxOption(props: { inbox: FromInbox }) {
- const [name] = useDisplayName(emailToMacroId(props.inbox.email_address));
+ const name = () => getDisplayName(emailToMacroId(props.inbox.email_address));
return (
<>
<UserIcon
@@ -34,7 +34,7 @@ function FromInboxOption(props: { inbox: FromInbox }) {
}
function FromInboxPill(props: { inbox: FromInbox; selectable: boolean }) {
- const [name] = useDisplayName(emailToMacroId(props.inbox.email_address));
+ const name = () => getDisplayName(emailToMacroId(props.inbox.email_address));
const label = () => name() || props.inbox.email_address;
return (
diff --git a/apps/web/src/features/block-email/component/compose/Compose.tsx b/apps/web/src/features/block-email/component/compose/Compose.tsx
index 31ae28015b..6ba67c6cce 100644
--- a/apps/web/src/features/block-email/component/compose/Compose.tsx
+++ b/apps/web/src/features/block-email/component/compose/Compose.tsx
@@ -39,9 +39,9 @@ import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
import {
type ContactInfo,
emailToId,
+ getDisplayName,
recipientEntityMapper,
tryMacroId,
- useDisplayName,
type WithCustomUserInput,
} from '@core/user';
import { $generateHtmlFromNodes } from '@lexical/html';
@@ -703,7 +703,7 @@ export function EmailCompose(props: EmailComposeProps) {
let recipientName = recipients[0].data.email;
if (recipients[0].kind === 'user') {
- recipientName = useDisplayName(tryMacroId(recipients[0].data.id))[0]();
+ recipientName = getDisplayName(tryMacroId(recipients[0].data.id));
}
return recipientName ? `Email to ${recipientName}` : 'Draft email';
@@ -713,7 +713,7 @@ export function EmailCompose(props: EmailComposeProps) {
.slice(0, 2)
.map((r) => {
if (r.kind === 'user') {
- return useDisplayName(tryMacroId(r.data.id))[0]();
+ return getDisplayName(tryMacroId(r.data.id));
}
return r.data.email || 'Unknown';
})
diff --git a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
index d70a2fc5f2..9c03b2d4fe 100644
--- a/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
+++ b/apps/web/src/features/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
@@ -27,7 +27,7 @@ import {
} from '@core/constant/featureFlags';
import { useUserId } from '@core/context/user';
import type { Entity, EntityType } from '@core/types';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { type DateValue, formatDate } from '@core/util/date';
import { openExternalUrl } from '@core/util/url';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
@@ -399,7 +399,7 @@ function FolderLink(props: { projectId: string; projectName: string }) {
}
function OwnerValue(props: { ownerId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.ownerId));
+ const displayName = () => getDisplayName(tryMacroId(props.ownerId));
return (
<SidePanel.Pill>
<UserIcon id={props.ownerId} size="sm" showTooltip suppressClick />
diff --git a/apps/web/src/features/block-md/history/HistoryContext.tsx b/apps/web/src/features/block-md/history/HistoryContext.tsx
index a95e742dce..9ca6eff075 100644
--- a/apps/web/src/features/block-md/history/HistoryContext.tsx
+++ b/apps/web/src/features/block-md/history/HistoryContext.tsx
@@ -1,5 +1,5 @@
import { MACRO_AGENT_BOT_ID } from '@core/constant/macroAgent';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { ThrownResultError } from '@core/util/result';
import { isAiPeer } from '@macro-inc/collaboration/collab/ai-peer';
import {
@@ -152,15 +152,14 @@ export function HistoryProvider(props: {
return null;
});
- // One stable useDisplayName per unique userId — batched into a single fetch.
+ // One stable display-name accessor per unique userId, batched into one fetch.
const uniqueUserIds = createMemo(() => {
const peers = loadedPeers();
return peers ? [...new Set(peers.values())] : [];
});
const userEntries = mapArray(uniqueUserIds, (userId) => {
- const [displayName] = useDisplayName(tryMacroId(userId), {
- emailFallback: 'local-part',
- });
+ const displayName = () =>
+ getDisplayName(tryMacroId(userId), { emailFallback: 'local-part' });
return { userId, displayName, color: userColor(userId) };
});
const userById = (userId: string): HistoryUser =>
diff --git a/apps/web/src/features/block-md/history/HistorySessionList.tsx b/apps/web/src/features/block-md/history/HistorySessionList.tsx
index 1166dd42d9..edbc15cd77 100644
--- a/apps/web/src/features/block-md/history/HistorySessionList.tsx
+++ b/apps/web/src/features/block-md/history/HistorySessionList.tsx
@@ -1,4 +1,4 @@
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, tryMacroId } from '@core/user';
import type { HistorySession } from '@service-sync/client';
import { cn } from '@ui';
import { type Accessor, createMemo, For, Show } from 'solid-js';
@@ -13,8 +13,8 @@ type HistorySessionListProps = {
};
function UserName(props: { userId: string }) {
- const { firstName } = useDisplayNameParts(tryMacroId(props.userId));
- return <>{firstName() || userLabel(props.userId)}</>;
+ const name = () => getDisplayNameParts(tryMacroId(props.userId)).firstName;
+ return <>{name() || userLabel(props.userId)}</>;
}
const MAX_NAMED = 3;
diff --git a/apps/web/src/features/calendar/events/EventDetails.tsx b/apps/web/src/features/calendar/events/EventDetails.tsx
index 9c7db41353..005a37e42a 100644
--- a/apps/web/src/features/calendar/events/EventDetails.tsx
+++ b/apps/web/src/features/calendar/events/EventDetails.tsx
@@ -2,8 +2,8 @@ import { UserIcon, type UserIconProps } from '@core/component/UserIcon';
import { ScrollIndicators } from '@core/component/VerticalScrollIndicators';
import {
emailToMacroId,
+ getDisplayName,
getInitialsFromName,
- useDisplayName,
} from '@core/user';
import { plural } from '@core/util/string';
import { openExternalUrl } from '@core/util/url';
@@ -89,12 +89,11 @@ function resolveCalendarAttendee(
attendee: CalendarAttendee
): ResolvedCalendarAttendee {
const macroId = emailToMacroId(attendee.email);
- const [macroDisplayName] = useDisplayName(macroId);
const iconProps: UserIconProps = macroId
? { id: macroId }
: { email: attendee.email };
const displayName = () => {
- const macroName = macroDisplayName().trim();
+ const macroName = getDisplayName(macroId).trim();
return isUsableDisplayName(macroName, attendee.email)
? macroName
: attendee.email;
@@ -314,10 +313,9 @@ function CalendarOrganizerItem(props: { organizer: CalendarOrganizer }) {
const macroId = props.organizer.email
? emailToMacroId(props.organizer.email)
: undefined;
- const [macroDisplayName] = useDisplayName(macroId);
const displayName = () => {
const email = props.organizer.email ?? '';
- const macroName = macroDisplayName().trim();
+ const macroName = getDisplayName(macroId).trim();
if (isUsableDisplayName(macroName, email)) return macroName;
const providerName = props.organizer.displayName?.trim() ?? '';
diff --git a/apps/web/src/features/channel/Call/CallOverlay.tsx b/apps/web/src/features/channel/Call/CallOverlay.tsx
index 6189096784..8aacd3d06a 100644
--- a/apps/web/src/features/channel/Call/CallOverlay.tsx
+++ b/apps/web/src/features/channel/Call/CallOverlay.tsx
@@ -2,7 +2,7 @@ import { useSplitPanel } from '@components/app/split-layout/layoutUtils';
import { UserIcon } from '@core/component/UserIcon';
import { useAuthor, useUserId } from '@core/context/user';
import { useProfilePictureUrl } from '@core/signal/profilePicture';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { cn, InlineCheckbox, Tooltip } from '@ui';
import type { RemoteParticipant, Track } from 'livekit-client';
import { For, type JSXElement, Show } from 'solid-js';
@@ -146,7 +146,7 @@ function LocalParticipantTile(props: {
function ParticipantTile(props: { participant: RemoteParticipant }) {
const callCtx = useCallContext();
const macroId = () => tryMacroId(props.participant.identity);
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const [profilePicUrl] = useProfilePictureUrl(macroId());
const cameraTrack = () => {
@@ -203,7 +203,7 @@ function ParticipantTile(props: { participant: RemoteParticipant }) {
function ScreenShareTile(props: { participant: RemoteParticipant }) {
const callCtx = useCallContext();
const macroId = () => tryMacroId(props.participant.identity);
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const screenTrack = () => {
callCtx.trackVersion();
return props.participant.getTrackPublication(LK_TRACK_SOURCE.ScreenShare)
diff --git a/apps/web/src/features/channel/Call/ChannelCallTab.tsx b/apps/web/src/features/channel/Call/ChannelCallTab.tsx
index ed7bad1cdc..c034e9fb0b 100644
--- a/apps/web/src/features/channel/Call/ChannelCallTab.tsx
+++ b/apps/web/src/features/channel/Call/ChannelCallTab.tsx
@@ -1,6 +1,6 @@
import { useChannelTab } from '@channel/Channel/ChannelTabContext';
import { UserGroup } from '@core/component/UserGroup';
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import PhoneIcon from '@icon/wide-call.svg';
import { useActiveCallQuery, useCallRecordQuery } from '@queries/call/call';
import { Button } from '@ui';
@@ -10,10 +10,10 @@ import { getCallJoinTab, getCallLeaveTab } from './call-tabs';
import { useCall } from './use-call';
function ParticipantFirstName(props: { id: string }) {
- const nameParts = useDisplayNameParts(tryMacroId(props.id));
- const name = createMemo(
- () => nameParts.firstName() || nameParts.fullName() || 'Someone'
- );
+ const name = createMemo(() => {
+ const fullName = getDisplayName(tryMacroId(props.id));
+ return fullName.trim().split(/\s+/)[0] || fullName || 'Someone';
+ });
return <>{name()}</>;
}
diff --git a/apps/web/src/features/channel/Call/InCallPanel/InCallParticipantsListPopover.tsx b/apps/web/src/features/channel/Call/InCallPanel/InCallParticipantsListPopover.tsx
index 1425359bfc..e2b15b9c11 100644
--- a/apps/web/src/features/channel/Call/InCallPanel/InCallParticipantsListPopover.tsx
+++ b/apps/web/src/features/channel/Call/InCallPanel/InCallParticipantsListPopover.tsx
@@ -1,6 +1,6 @@
import { useSplitLayout } from '@components/app/split-layout/layout';
import { toast } from '@core/component/Toast/Toast';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { Popover } from '@kobalte/core/popover';
import UsersThree from '@phosphor/users-three.svg';
import { useGetOrCreateDirectMessageMutation } from '@queries/channel/get-or-create-dm';
@@ -54,13 +54,12 @@ export function InCallParticipantNameRow(props: {
onError: () => toast.failure('Could not open direct message'),
});
- const raw = profilePictureIdForMember(props.panel, props.member);
- const [displayName] = useDisplayName(tryMacroId(raw ?? ''));
const label = createMemo(() => {
props.panel.callCtx.trackVersion();
const r = profilePictureIdForMember(props.panel, props.member);
+ const displayName = getDisplayName(tryMacroId(r ?? ''));
return (
- displayName() ||
+ displayName ||
r ||
(props.member.kind === 'local' ? 'You' : 'Participant')
);
diff --git a/apps/web/src/features/channel/Call/InCallPanel/InCallStripAvatarImage.tsx b/apps/web/src/features/channel/Call/InCallPanel/InCallStripAvatarImage.tsx
index 41a241d71b..ecdb1e2cc8 100644
--- a/apps/web/src/features/channel/Call/InCallPanel/InCallStripAvatarImage.tsx
+++ b/apps/web/src/features/channel/Call/InCallPanel/InCallStripAvatarImage.tsx
@@ -5,7 +5,7 @@ import {
stackedAvatarInnerClass,
} from '@core/component/StackedAvatarsRow';
import { UserIcon } from '@core/component/UserIcon';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { Tooltip } from '@ui';
import { type Component, Show } from 'solid-js';
@@ -25,9 +25,10 @@ export const InCallStripAvatarImage: Component<{
image: InCallStripImage;
trackCall?: () => unknown;
}> = (props) => {
- const [displayName] = useDisplayName(
- props.image.stripLocalPending ? undefined : tryMacroId(props.image.userId)
- );
+ const displayName = () =>
+ getDisplayName(
+ props.image.stripLocalPending ? undefined : tryMacroId(props.image.userId)
+ );
const nameLabel = () => {
props.trackCall?.();
diff --git a/apps/web/src/features/channel/Call/tests/call-overlay-muted.test.tsx b/apps/web/src/features/channel/Call/tests/call-overlay-muted.test.tsx
index c6447c6406..4b04fbe916 100644
--- a/apps/web/src/features/channel/Call/tests/call-overlay-muted.test.tsx
+++ b/apps/web/src/features/channel/Call/tests/call-overlay-muted.test.tsx
@@ -33,9 +33,8 @@ vi.mock('@core/signal/profilePicture', () => ({
vi.mock('@core/user', () => ({
tryMacroId: (identity: string) => identity,
- useDisplayName: (identity: string) => [
- () => mocks.displayNames.get(identity) ?? identity,
- ],
+ getDisplayName: (identity: string) =>
+ mocks.displayNames.get(identity) ?? identity,
}));
vi.mock('@ui', () => ({
diff --git a/apps/web/src/features/channel/CreateChannelModal.tsx b/apps/web/src/features/channel/CreateChannelModal.tsx
index 0b5ba7768e..1039a94bb6 100644
--- a/apps/web/src/features/channel/CreateChannelModal.tsx
+++ b/apps/web/src/features/channel/CreateChannelModal.tsx
@@ -7,8 +7,8 @@ import { UserIcon } from '@core/component/UserIcon';
import { useUserId } from '@core/context/user';
import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
import {
+ getDisplayName,
tryMacroId,
- useDisplayName,
type WithCustomUserInput,
} from '@core/user';
import { useFocusLock } from '@core/util/createControlledOpenSignal';
@@ -33,7 +33,7 @@ const CHANNEL_TYPE_TABS = [
type CreatableChannelType = 'private' | 'team';
function TeamMemberListItem(props: { member: TeamMember; isLast: boolean }) {
- const [displayName] = useDisplayName(tryMacroId(props.member.user_id));
+ const displayName = () => getDisplayName(tryMacroId(props.member.user_id));
return (
<div
diff --git a/apps/web/src/features/channel/Message/FromPill.tsx b/apps/web/src/features/channel/Message/FromPill.tsx
index 952d98c353..c5e0576e7b 100644
--- a/apps/web/src/features/channel/Message/FromPill.tsx
+++ b/apps/web/src/features/channel/Message/FromPill.tsx
@@ -1,6 +1,6 @@
import { HoverCard } from '@core/component/HoverCard';
import { UserTooltip } from '@core/component/UserTooltip';
-import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { cn } from '@ui';
import { createSignal, Show } from 'solid-js';
import { useMessage } from './context';
@@ -21,7 +21,7 @@ export function FromPill(props: FromPillProps) {
const id = triggeredBy();
return id ? tryMacroId(id) : undefined;
};
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const email = () => {
const id = macroId();
return id ? macroIdToEmail(id) : (triggeredBy() ?? '');
diff --git a/apps/web/src/features/channel/Message/SenderName.tsx b/apps/web/src/features/channel/Message/SenderName.tsx
index ed60b651e8..ffd26abd60 100644
--- a/apps/web/src/features/channel/Message/SenderName.tsx
+++ b/apps/web/src/features/channel/Message/SenderName.tsx
@@ -1,4 +1,4 @@
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { senderFromStorageId } from '@queries/channel/message-sender';
import type { ApiMessageSender } from '@service-storage/generated/schemas/apiMessageSender';
import { cn } from '@ui';
@@ -37,7 +37,7 @@ export function MessageSenderName(props: SenderNameProps) {
export function SenderName(props: { message: MessageData }) {
const macroId = () => tryMacroId(props.message.sender_id);
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const agentName = () =>
botName(props.message.sender_id, props.message.sender);
return <>{agentName() ?? displayName()}</>;
diff --git a/apps/web/src/features/channel/Thread/ChannelThread.tsx b/apps/web/src/features/channel/Thread/ChannelThread.tsx
index 852475d400..3e3d9b8850 100644
--- a/apps/web/src/features/channel/Thread/ChannelThread.tsx
+++ b/apps/web/src/features/channel/Thread/ChannelThread.tsx
@@ -1,7 +1,7 @@
import { DebugSuspense } from '@channel/DebugSuspense';
import { useUserId } from '@core/context/user';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { MarkMessageNotifications } from '@notifications/components/MarkMessageNotifications';
import { useThreadRepliesQuery } from '@queries/channel/thread-replies';
import type { ApiThreadReply } from '@service-storage/generated/schemas/apiThreadReply';
@@ -35,7 +35,7 @@ export function ChannelThread(props: ThreadProps) {
const userId = useUserId();
const replyUserId = () => userId() ?? props.data().sender_id;
const macroId = () => tryMacroId(replyUserId());
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const thread = () => props.data().thread;
const hasReplies = () => thread().reply_count > 0;
const fetchRepliesEnabled = createThreadRepliesFetchGate({
diff --git a/apps/web/src/features/entity/components/Badges.tsx b/apps/web/src/features/entity/components/Badges.tsx
index 1732474405..7789305c66 100644
--- a/apps/web/src/features/entity/components/Badges.tsx
+++ b/apps/web/src/features/entity/components/Badges.tsx
@@ -1,5 +1,5 @@
import { UserIcon } from '@core/component/UserIcon';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import HashIcon from '@phosphor/hash.svg';
import UserPlus from '@phosphor/user-plus.svg';
import { cn, HoverCard } from '@ui';
@@ -32,14 +32,7 @@ export function SharedBadge(props: { ownerId: string }) {
export function SharedBadgeSmall(props: { ownerId: string }) {
const id = () => tryMacroId(props.ownerId);
- const name = () => {
- const currentId = id();
- if (currentId) {
- let [name] = useDisplayName(currentId);
- return name;
- }
- return () => undefined;
- };
+ const name = () => getDisplayName(id()) || undefined;
return (
<HoverCard
@@ -51,7 +44,7 @@ export function SharedBadgeSmall(props: { ownerId: string }) {
suppressClick
showTooltip={false}
/>
- <span>{name()()} shared this with you</span>
+ <span>{name()} shared this with you</span>
</div>
}
>
@@ -64,14 +57,7 @@ export function SharedBadgeSmall(props: { ownerId: string }) {
export function CreatedByBadgeSmall(props: { ownerId: string }) {
const id = () => tryMacroId(props.ownerId);
- const name = () => {
- const currentId = id();
- if (currentId) {
- let [name] = useDisplayName(currentId);
- return name;
- }
- return () => undefined;
- };
+ const name = () => getDisplayName(id()) || undefined;
return (
<HoverCard
@@ -83,7 +69,7 @@ export function CreatedByBadgeSmall(props: { ownerId: string }) {
suppressClick
showTooltip={false}
/>
- <span>Created by {name()()}</span>
+ <span>Created by {name()}</span>
</div>
}
>
diff --git a/apps/web/src/features/entity/components/DisplayName.tsx b/apps/web/src/features/entity/components/DisplayName.tsx
index 544cf42fff..857fe968aa 100644
--- a/apps/web/src/features/entity/components/DisplayName.tsx
+++ b/apps/web/src/features/entity/components/DisplayName.tsx
@@ -1,4 +1,4 @@
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { truncateLabel } from '@core/util/string';
export function DisplayName(props: {
@@ -7,13 +7,17 @@ export function DisplayName(props: {
maxChars?: number;
}) {
const name = () => {
- const parts = useDisplayNameParts(tryMacroId(props.id));
+ const fullName = getDisplayName(tryMacroId(props.id));
const format = props.format ?? 'fullName';
- const raw =
- format === 'fullName'
- ? parts.fullName()
- : parts[format]() || parts.fullName();
+ const nameParts = fullName.trim().split(/\s+/).filter(Boolean);
+ const raw = (() => {
+ if (format === 'firstName') return nameParts[0] || fullName;
+ if (format === 'lastName') {
+ return nameParts.length > 1 ? (nameParts.at(-1) ?? '') : fullName;
+ }
+ return fullName;
+ })();
return truncateLabel(raw, props.maxChars);
};
diff --git a/apps/web/src/features/entity/composed/list-entity/channel.tsx b/apps/web/src/features/entity/composed/list-entity/channel.tsx
index 4ec86ab5a5..b3da112f9d 100644
--- a/apps/web/src/features/entity/composed/list-entity/channel.tsx
+++ b/apps/web/src/features/entity/composed/list-entity/channel.tsx
@@ -1,7 +1,7 @@
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import {
+ singleLineMarkdownTheme,
twoLineClampMarkdownTheme,
- unifiedListMarkdownTheme,
} from '@core/component/LexicalMarkdown/theme';
import { UserIcon } from '@core/component/UserIcon';
import { DisplayName } from '@entity/components/DisplayName';
@@ -59,7 +59,7 @@ function ChannelMessage(props: {
fallback={<span class="italic">Attached Items</span>}
>
<StaticMarkdown
- theme={unifiedListMarkdownTheme}
+ theme={singleLineMarkdownTheme}
markdown={props.message.content}
singleLine
/>
@@ -96,7 +96,6 @@ export function ChannelMessageNarrowBody(props: {
export function ChannelLatestMessageNarrowBody(props: {
message: NonNullable<ChannelEntity['latestMessage']>;
- senderFirstName?: string;
}) {
return (
<Entity.Slot
@@ -107,12 +106,12 @@ export function ChannelLatestMessageNarrowBody(props: {
when={props.message.content?.trim()}
fallback={<span class="italic">Attached Items</span>}
>
+ <span class="ph-no-capture font-medium text-ink-muted">
+ <DisplayName id={props.message.senderId} format="firstName" />:{' '}
+ </span>
<StaticMarkdown
theme={twoLineClampMarkdownTheme}
- markdown={
- (props.senderFirstName ? `**${props.senderFirstName}:** ` : '') +
- props.message.content.trim()
- }
+ markdown={props.message.content.trim()}
singleLine
/>
</Show>
diff --git a/apps/web/src/features/entity/composed/list-entity/narrow-inbox-layout.tsx b/apps/web/src/features/entity/composed/list-entity/narrow-inbox-layout.tsx
index 23c18c9322..cc2ba92338 100644
--- a/apps/web/src/features/entity/composed/list-entity/narrow-inbox-layout.tsx
+++ b/apps/web/src/features/entity/composed/list-entity/narrow-inbox-layout.tsx
@@ -1,5 +1,4 @@
import { useMaybeSoupView } from '@app/features/next-soup/soup-view/soup-view-context';
-import { tryMacroId, useDisplayNameParts } from '@core/user';
import { cn } from '@ui';
import { Match, Show, Switch } from 'solid-js';
import { MultiSelectCheckbox } from '../../components/MultiSelectCheckbox';
@@ -33,11 +32,6 @@ export function NarrowInboxLayout(props: LayoutProps) {
isChannelEntity(props.entity) &&
props.entity.channelType === 'direct_message';
- const mostRecentMessageSenderName = () =>
- isChannelEntity(props.entity) && props.entity.latestMessage?.senderId
- ? useDisplayNameParts(tryMacroId(props.entity.latestMessage?.senderId))
- : undefined;
-
const firstNotification = () => {
if (!isWithNotification(props.entity)) return undefined;
return filterNotDoneNotifications(
@@ -142,12 +136,7 @@ export function NarrowInboxLayout(props: LayoutProps) {
<Match
when={isChannelEntity(props.entity) && props.entity.latestMessage}
>
- {(msg) => (
- <ChannelLatestMessageNarrowBody
- message={msg()}
- senderFirstName={mostRecentMessageSenderName()?.firstName()}
- />
- )}
+ {(msg) => <ChannelLatestMessageNarrowBody message={msg()} />}
</Match>
<Match when={isEmailEntity(props.entity) && props.entity}>
{(entity) => (
diff --git a/apps/web/src/features/entity/extractors-notification/notification-description.tsx b/apps/web/src/features/entity/extractors-notification/notification-description.tsx
index b16b235a2f..42afcbcda0 100644
--- a/apps/web/src/features/entity/extractors-notification/notification-description.tsx
+++ b/apps/web/src/features/entity/extractors-notification/notification-description.tsx
@@ -1,5 +1,5 @@
import type { NotificationType } from '@core/types';
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, tryMacroId } from '@core/user';
import type { NotificationStack } from '@notifications';
import { createMemo } from 'solid-js';
import type { Notification } from '../types/notification';
@@ -48,10 +48,10 @@ export function NotificationDescription(props: NotificationDescriptionProps) {
};
const macroFirstName = (id: string) => {
- const parts = useDisplayNameParts(tryMacroId(id), {
+ const parts = getDisplayNameParts(tryMacroId(id), {
emailFallback: 'local-part',
});
- return parts.firstName() || parts.fullName();
+ return parts.firstName || parts.fullName;
};
// Sender display labels for the notification/stack. GitHub PR senders are
diff --git a/apps/web/src/features/entity/extractors/entity-email-participants.tsx b/apps/web/src/features/entity/extractors/entity-email-participants.tsx
index f5484f8b8a..8295770180 100644
--- a/apps/web/src/features/entity/extractors/entity-email-participants.tsx
+++ b/apps/web/src/features/entity/extractors/entity-email-participants.tsx
@@ -4,7 +4,7 @@ import { unifiedListMarkdownTheme } from '@core/component/LexicalMarkdown/theme'
import { toast } from '@core/component/Toast/Toast';
import { UserTooltip } from '@core/component/UserTooltip';
import { useEmail } from '@core/context/user';
-import { emailToMacroId, useDisplayName } from '@core/user';
+import { emailToMacroId, getDisplayName } from '@core/user';
import {
highlightTermsInText,
mergeAdjacentMacroEmTags,
@@ -54,7 +54,7 @@ function ParticipantWithTooltip(props: {
highlighted?: string;
}) {
const macroId = () => emailToMacroId(props.participant.email);
- const [macroDisplayName] = useDisplayName(macroId());
+ const macroDisplayName = () => getDisplayName(macroId());
const tooltipName = () =>
resolveParticipantName(props.participant, macroDisplayName());
const [open, setOpen] = createSignal(false);
@@ -176,7 +176,7 @@ function HiddenParticipantsTooltip(props: { hidden: ResolvedParticipant[] }) {
export function EntityEmailParticipants(props: { entity: EmailEntity }) {
const userEmail = useEmail();
const fetchDisplayName = (email: string) =>
- useDisplayName(emailToMacroId(email))[0]();
+ getDisplayName(emailToMacroId(email));
const participants = () =>
abbreviateParticipants(
diff --git a/apps/web/src/features/entity/extractors/entity-owner.tsx b/apps/web/src/features/entity/extractors/entity-owner.tsx
index accf889bb9..84445e3a1c 100644
--- a/apps/web/src/features/entity/extractors/entity-owner.tsx
+++ b/apps/web/src/features/entity/extractors/entity-owner.tsx
@@ -1,5 +1,5 @@
import { useUserId } from '@core/context/user';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import type { EntityData } from '../types/entity';
export function EntityOwner(props: { entity: EntityData }) {
@@ -9,7 +9,7 @@ export function EntityOwner(props: { entity: EntityData }) {
const ownerDisplayName = () => {
const owner = ownerId();
if (!owner) return undefined;
- return useDisplayName(tryMacroId(owner))[0]();
+ return getDisplayName(tryMacroId(owner));
};
const displayText = () => {
diff --git a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx
index 73852b102f..84c881a1d4 100644
--- a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx
+++ b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx
@@ -13,7 +13,7 @@ import {
import { UserIcon } from '@core/component/UserIcon';
import { isMacroAgentId } from '@core/constant/macroAgent';
import { useUserId } from '@core/context/user';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { plural } from '@core/util/string';
import {
DraftBadge,
@@ -394,7 +394,10 @@ const createSenderDisplayName = (
return id ? tryMacroId(id) : undefined;
};
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => {
+ const id = macroId();
+ return id ? getDisplayName(id) : undefined;
+ };
const botName = () => {
const id = senderId();
diff --git a/apps/web/src/features/next-soup/soup-view/views/tasks/task-grid-layout.tsx b/apps/web/src/features/next-soup/soup-view/views/tasks/task-grid-layout.tsx
index 1e02ed4b0c..b69f5d641e 100644
--- a/apps/web/src/features/next-soup/soup-view/views/tasks/task-grid-layout.tsx
+++ b/apps/web/src/features/next-soup/soup-view/views/tasks/task-grid-layout.tsx
@@ -1,6 +1,6 @@
import { useMaybeSoupView } from '@app/features/next-soup/soup-view/soup-view-context';
import { UserIcon } from '@core/component/UserIcon';
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, tryMacroId } from '@core/user';
import {
Entity,
type EntityData,
@@ -71,10 +71,11 @@ export function TaskGridLayout(props: LayoutProps) {
const isShared = () => props.entity.ownerId !== currentId();
// Get owner's first name for the Created By column
- const ownerNameParts = () =>
- useDisplayNameParts(tryMacroId(props.entity.ownerId));
const ownerDisplayName = () =>
- isShared() ? ownerNameParts().firstName() || 'Unknown' : 'Me';
+ isShared()
+ ? getDisplayNameParts(tryMacroId(props.entity.ownerId)).firstName ||
+ 'Unknown'
+ : 'Me';
const propertyMap = createMemo(() => {
const map = new Map<string, Property>();
diff --git a/apps/web/src/features/next-soup/soup-view/views/tasks/task-group-header.tsx b/apps/web/src/features/next-soup/soup-view/views/tasks/task-group-header.tsx
index 6ad760f6ed..c75f192ba7 100644
--- a/apps/web/src/features/next-soup/soup-view/views/tasks/task-group-header.tsx
+++ b/apps/web/src/features/next-soup/soup-view/views/tasks/task-group-header.tsx
@@ -2,7 +2,7 @@ import type { GroupHeaderProps } from '@app/features/next-soup/create-soup-state
import { SoupSectionHeader } from '@app/features/next-soup/soup-view/section-header';
import { useSoupView } from '@app/features/next-soup/soup-view/soup-view-context';
import { UserIcon } from '@core/component/UserIcon';
-import { type MacroId, tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, type MacroId, tryMacroId } from '@core/user';
import ChevronRightIcon from '@phosphor/caret-right.svg';
import CircleDashed from '@phosphor/circle-dashed.svg';
import { PROPERTY_OPTION_IDS, SYSTEM_PROPERTY_IDS } from '@property';
@@ -14,9 +14,8 @@ const AssigneeGroupContent = (props: {
assigneeId: MacroId;
fallbackLabel: string;
}) => {
- const [assigneeName] = useDisplayName(props.assigneeId, {
- emailFallback: 'local-part',
- });
+ const assigneeName = () =>
+ getDisplayName(props.assigneeId, { emailFallback: 'local-part' });
return (
<>
<UserIcon
diff --git a/apps/web/src/features/notifications/notification-resolvers.ts b/apps/web/src/features/notifications/notification-resolvers.ts
index 9bbedf857c..e6bd6df610 100644
--- a/apps/web/src/features/notifications/notification-resolvers.ts
+++ b/apps/web/src/features/notifications/notification-resolvers.ts
@@ -1,7 +1,7 @@
import type { BlockName } from '@core/block';
import { itemToResolvedBlockName } from '@core/constant/allBlocks';
import type { EntityType } from '@core/types';
-import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { getItemPreview, isAccessiblePreviewItem } from '@queries/preview';
import { stringToItemType } from '@service-storage/client';
import { raceTimeout, until } from '@solid-primitives/promise';
@@ -22,7 +22,7 @@ const RESOLVER_TIMEOUT = 1000;
export const DefaultUserNameResolver: UserNameResolver = async (id: string) => {
const macroId = tryMacroId(id);
const resolvedName = await raceTimeout(
- until(useDisplayName(macroId)[0]),
+ until(() => getDisplayName(macroId)),
RESOLVER_TIMEOUT
);
if (resolvedName) return resolvedName;
diff --git a/apps/web/src/features/notifications/tests/notification-resolvers.test.ts b/apps/web/src/features/notifications/tests/notification-resolvers.test.ts
index 13ace42528..1127b442fe 100644
--- a/apps/web/src/features/notifications/tests/notification-resolvers.test.ts
+++ b/apps/web/src/features/notifications/tests/notification-resolvers.test.ts
@@ -11,7 +11,7 @@ vi.mock('@queries/preview', () => ({
vi.mock('@core/user', () => ({
tryMacroId: () => undefined,
macroIdToEmail: () => undefined,
- useDisplayName: () => [() => undefined],
+ getDisplayName: () => undefined,
}));
vi.mock('@core/constant/allBlocks', () => ({
diff --git a/apps/web/src/features/property/extractors/PropertyText.tsx b/apps/web/src/features/property/extractors/PropertyText.tsx
index dc495f519b..b9c0512a04 100644
--- a/apps/web/src/features/property/extractors/PropertyText.tsx
+++ b/apps/web/src/features/property/extractors/PropertyText.tsx
@@ -1,4 +1,4 @@
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, tryMacroId } from '@core/user';
import { cn } from '@ui';
import { type JSX, Show } from 'solid-js';
import type { Property } from '../types';
@@ -97,10 +97,12 @@ function UserPropertyText(props: {
fallback?: JSX.Element;
class?: string;
}) {
- const parts = useDisplayNameParts(tryMacroId(props.id), {
- emailFallback: 'local-part',
- });
- const text = () => parts.firstName() || parts.fullName();
+ const text = () => {
+ const parts = getDisplayNameParts(tryMacroId(props.id), {
+ emailFallback: 'local-part',
+ });
+ return parts.firstName || parts.fullName;
+ };
return (
<Show when={text()} fallback={props.fallback ?? null}>
diff --git a/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx b/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx
index 40c9bf89ae..ec4427836d 100644
--- a/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx
+++ b/apps/web/src/features/property/hooks/usePropertyEntityDisplay.tsx
@@ -3,7 +3,7 @@ import { EntityIcon as CoreEntityIcon } from '@core/component/EntityIcon';
import { UserIcon } from '@core/component/UserIcon';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { useChannelName } from '@core/context/channels';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { isAccessiblePreviewItem, useItemPreview } from '@queries/preview';
import type { EntityType } from '@service-properties/generated/schemas/entityType';
import { type Accessor, createMemo, type JSX } from 'solid-js';
@@ -85,7 +85,7 @@ export function usePropertyEntityDisplay(
const userNameWrapper = () => {
const eType = entityType();
if (eType === 'USER') {
- return useDisplayName(tryMacroId(entityId()))[0];
+ return () => getDisplayName(tryMacroId(entityId()));
}
};
const userName = createMemo(() => userNameWrapper()?.() ?? '');
diff --git a/apps/web/src/features/settings/Team.tsx b/apps/web/src/features/settings/Team.tsx
index 35bb67de1a..a028553e64 100644
--- a/apps/web/src/features/settings/Team.tsx
+++ b/apps/web/src/features/settings/Team.tsx
@@ -2,7 +2,7 @@ import { toast } from '@core/component/Toast/Toast';
import { UserIcon } from '@core/component/UserIcon';
import { SERVER_HOSTS } from '@core/constant/servers';
import { useUserId } from '@core/context/user';
-import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { debouncedDependent } from '@core/util/debounce';
import { fuzzyFilter } from '@core/util/fuzzy';
import { getWebOrigin } from '@core/util/webOrigin';
@@ -308,7 +308,7 @@ function MemberRow(props: {
onRemove: () => void;
onRoleChange: (role: TeamRole) => void;
}) {
- const [displayName] = useDisplayName(tryMacroId(props.member.user_id));
+ const displayName = () => getDisplayName(tryMacroId(props.member.user_id));
const isMemberOwner = () => props.member.role === TeamRole.owner;
const email = () => {
const id = tryMacroId(props.member.user_id);
@@ -383,7 +383,7 @@ function MemberRow(props: {
}
function MemberName(props: { memberId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.memberId));
+ const displayName = () => getDisplayName(tryMacroId(props.memberId));
return <span class="font-medium">{displayName()}</span>;
}
@@ -454,7 +454,7 @@ function InviteRow(props: {
}
function InviterName(props: { inviterId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.inviterId));
+ const displayName = () => getDisplayName(tryMacroId(props.inviterId));
return <span class="font-medium">{displayName()}</span>;
}
@@ -916,7 +916,7 @@ function TeamManagement(props: {
// disposes it when the member leaves the list.
const memberSearchIndex = mapArray(members, (member) => {
const macroId = tryMacroId(member.user_id);
- const [displayName] = useDisplayName(macroId);
+ const displayName = () => getDisplayName(macroId);
const email = macroId ? macroIdToEmail(macroId) : '';
// Memoized so the lowercased search string is built once (and only rebuilt
// when the name resolves), not re-allocated for every member on each scan.
diff --git a/apps/web/src/features/team-invitations/TeamInviteAcceptance.tsx b/apps/web/src/features/team-invitations/TeamInviteAcceptance.tsx
index ad476b28cb..52b4c58404 100644
--- a/apps/web/src/features/team-invitations/TeamInviteAcceptance.tsx
+++ b/apps/web/src/features/team-invitations/TeamInviteAcceptance.tsx
@@ -1,6 +1,6 @@
import { LoadingBlock } from '@core/component/LoadingBlock';
import { PcNoiseGrid } from '@core/component/PcNoiseGrid';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import LogoIcon from '@icon/macro-logo.svg';
import EnvelopeIcon from '@phosphor/envelope.svg';
import SpinnerIcon from '@phosphor/spinner.svg';
@@ -260,7 +260,7 @@ function InviteDetails(props: {
};
const isDisabled = () => props.isJoining || props.isDeclining;
- const [invitedBy] = useDisplayName(tryMacroId(props.invitedBy));
+ const invitedBy = () => getDisplayName(tryMacroId(props.invitedBy));
return (
<div class="flex flex-col items-center gap-6 text-center w-full">
diff --git a/apps/web/src/lib/core/comments/discussion/Discussion.tsx b/apps/web/src/lib/core/comments/discussion/Discussion.tsx
index d48368e0d9..e0cdadd3f6 100644
--- a/apps/web/src/lib/core/comments/discussion/Discussion.tsx
+++ b/apps/web/src/lib/core/comments/discussion/Discussion.tsx
@@ -7,7 +7,7 @@ import { ThreadReplyInputConnector } from '@channel/Thread/ThreadReplyInputConne
import { replyInputOffsetX } from '@channel/Thread/utils/thread-rail-geometry';
import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { toast } from '@core/component/Toast/Toast';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import CaretDown from '@phosphor/caret-down.svg';
import CaretRight from '@phosphor/caret-right.svg';
import { Key } from '@solid-primitives/keyed';
@@ -174,7 +174,7 @@ export function DiscussionThreadView(props: {
const replyUserId = () => source.currentUserId() ?? root()?.authorId ?? '';
const macroId = () => tryMacroId(replyUserId());
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const isOwn = (comment: DiscussionComment) =>
comment.authorId === source.currentUserId();
diff --git a/apps/web/src/lib/core/component/AI/component/tool/ListTeamMembers.tsx b/apps/web/src/lib/core/component/AI/component/tool/ListTeamMembers.tsx
index 9cdcaba384..5551fd1bf0 100644
--- a/apps/web/src/lib/core/component/AI/component/tool/ListTeamMembers.tsx
+++ b/apps/web/src/lib/core/component/AI/component/tool/ListTeamMembers.tsx
@@ -1,5 +1,5 @@
import { UserIcon } from '@core/component/UserIcon';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import Envelope from '@phosphor-icons/core/regular/envelope.svg';
import Users from '@phosphor-icons/core/regular/users.svg';
import type { NamedTool } from '@service-cognition/generated/tools/tool';
@@ -16,7 +16,7 @@ type TeamInvite = ListTeamMembersResponse['invited'][number];
const formatRole = (role: string) => role.split('_').join(' ');
function TeamMemberRow(props: { member: TeamMember }) {
- const [displayName] = useDisplayName(tryMacroId(props.member.userId));
+ const displayName = () => getDisplayName(tryMacroId(props.member.userId));
const name = () => displayName() || props.member.userId;
return (
diff --git a/apps/web/src/lib/core/component/DetailsDrawer.tsx b/apps/web/src/lib/core/component/DetailsDrawer.tsx
index 2870ec57ad..919ae7001e 100644
--- a/apps/web/src/lib/core/component/DetailsDrawer.tsx
+++ b/apps/web/src/lib/core/component/DetailsDrawer.tsx
@@ -2,7 +2,7 @@ import { SplitDrawer } from '@components/app/split-layout/components/SplitDrawer
import { EntityIcon } from '@core/component/EntityIcon';
import { openDocument } from '@core/component/LexicalMarkdown/component/core/BlockLink';
import { UserIcon } from '@core/component/UserIcon';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { type DateValue, formatDate } from '@core/util/date';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
import { useChatDataQuery } from '@queries/cognition/chat-data';
@@ -170,7 +170,7 @@ function FolderLink(props: { projectId: string; projectName: string }) {
}
function OwnerValue(props: { ownerId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.ownerId));
+ const displayName = () => getDisplayName(tryMacroId(props.ownerId));
return (
<>
<UserIcon id={props.ownerId} size="sm" showTooltip suppressClick />
diff --git a/apps/web/src/lib/core/component/DocumentPreview.tsx b/apps/web/src/lib/core/component/DocumentPreview.tsx
index 92688ba905..c2343f0f47 100644
--- a/apps/web/src/lib/core/component/DocumentPreview.tsx
+++ b/apps/web/src/lib/core/component/DocumentPreview.tsx
@@ -16,7 +16,7 @@ import { channelTheme } from '@core/component/LexicalMarkdown/theme';
import { toast } from '@core/component/Toast/Toast';
import { UserIcon as UserIconComponent } from '@core/component/UserIcon';
import { itemToBlockName, resolveBlockAlias } from '@core/constant/allBlocks';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, tryMacroId } from '@core/user';
import { copyBranchNameToClipboard } from '@core/util/branchName';
import { matches } from '@core/util/match';
import MacroEmbed from '@icon/macro-embed.svg';
@@ -269,7 +269,7 @@ function MetadataInfo(props: {
* User info with icon and display name
*/
function UserInfo(props: { userId: string }) {
- const [displayName] = useDisplayName(tryMacroId(props.userId));
+ const displayName = () => getDisplayName(tryMacroId(props.userId));
return (
<div class="justify-left mt-2 w-fit max-w-[66%] text-ink-muted truncate flex items-center gap-1.5">
<UserIconComponent
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx
index ee39b8a8c9..1870de0165 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx
@@ -1,6 +1,6 @@
import { HoverCard } from '@core/component/HoverCard';
import { UserTooltip } from '@core/component/UserTooltip';
-import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import type { UserMentionDecoratorProps } from '@macro-inc/lexical-core';
import { cn } from '@ui';
import { createMemo, createSignal, useContext } from 'solid-js';
@@ -24,7 +24,7 @@ export function UserMention(props: UserMentionDecoratorProps) {
props.userId ? tryMacroId(userId()) : undefined
);
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const email = createMemo(() => {
const id = macroId();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/blame-tooltip/BlameTooltip.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/blame-tooltip/BlameTooltip.tsx
index bb20682326..add7e42a2b 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/blame-tooltip/BlameTooltip.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/blame-tooltip/BlameTooltip.tsx
@@ -1,5 +1,5 @@
import { UserIcon } from '@core/component/UserIcon';
-import { macroIdToEmail, tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, macroIdToEmail, tryMacroId } from '@core/user';
import { formatRelativeTimestamp } from '@entity';
import { useNodeBlameQuery } from '@queries/blame';
import { createScheduled, debounce } from '@solid-primitives/scheduled';
@@ -19,9 +19,9 @@ const SHOW_DELAY_MS = 500;
function UserLine(props: { userId: string; editedAt: Date }) {
const macroId = tryMacroId(props.userId);
- const { firstName } = useDisplayNameParts(macroId);
const name = () =>
- firstName() || (macroId ? macroIdToEmail(macroId) : props.userId);
+ getDisplayNameParts(macroId).firstName ||
+ (macroId ? macroIdToEmail(macroId) : props.userId);
return (
<span class="inline-flex items-center gap-1">
diff --git a/apps/web/src/lib/core/component/NotificationRenderer.tsx b/apps/web/src/lib/core/component/NotificationRenderer.tsx
index 45cfee5fd1..4a74efc74d 100644
--- a/apps/web/src/lib/core/component/NotificationRenderer.tsx
+++ b/apps/web/src/lib/core/component/NotificationRenderer.tsx
@@ -1,6 +1,6 @@
import { InlineItemPreview } from '@core/component/ItemPreview';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
-import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
+import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { formatDate } from '@core/util/date';
import {
getNotificationAction,
@@ -20,9 +20,8 @@ export function NotificationRenderer(props: NotificationRendererProps) {
const time = () => formatDate(props.notification.created_at);
const actorId = () => props.notification.sender_id ?? '';
const macroId = () => tryMacroId(actorId());
- const [actorName] = useDisplayName(macroId(), {
- emailFallback: 'local-part',
- });
+ const actorName = () =>
+ getDisplayName(macroId(), { emailFallback: 'local-part' });
const emailFallback = () => {
const mid = macroId();
return mid ? macroIdToEmail(mid) : actorId() || undefined;
diff --git a/apps/web/src/lib/core/component/References.tsx b/apps/web/src/lib/core/component/References.tsx
index e5c5bcfddb..0831536fb4 100644
--- a/apps/web/src/lib/core/component/References.tsx
+++ b/apps/web/src/lib/core/component/References.tsx
@@ -5,7 +5,7 @@ import { useSplitLayout } from '@components/app/split-layout/layout';
import type { BlockAlias, BlockName } from '@core/block';
import { toast } from '@core/component/Toast/Toast';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
-import { tryMacroId, useDisplayNameParts } from '@core/user';
+import { getDisplayNameParts, tryMacroId } from '@core/user';
import { compareDateDesc, type DateValue } from '@core/util/date';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
import { formatRelativeTimestamp } from '@entity';
@@ -134,11 +134,12 @@ function ChannelReferenceRow(props: {
reference: ChannelRef;
onOpen: (e: KeyboardEvent | MouseEvent) => void;
}) {
- const { firstName, fullName } = useDisplayNameParts(
- tryMacroId(props.reference.sender_id),
- { emailFallback: 'local-part' }
- );
- const senderName = () => firstName() || fullName();
+ const senderName = () => {
+ const parts = getDisplayNameParts(tryMacroId(props.reference.sender_id), {
+ emailFallback: 'local-part',
+ });
+ return parts.firstName || parts.fullName;
+ };
const hasContent = () => {
const content = props.reference.message_content?.trim();
if (!content) return false;
@@ -179,10 +180,12 @@ function GenericReferenceRow(props: {
onOpen: (item: PreviewItem, e?: KeyboardEvent | MouseEvent) => void;
}) {
const userId = props.reference.user_id!;
- const { firstName, fullName } = useDisplayNameParts(tryMacroId(userId), {
- emailFallback: 'local-part',
- });
- const senderName = () => firstName() || fullName();
+ const senderName = () => {
+ const parts = getDisplayNameParts(tryMacroId(userId), {
+ emailFallback: 'local-part',
+ });
+ return parts.firstName || parts.fullName;
+ };
const [item] = useItemPreview(() => ({
id: props.reference.source_entity_id,
type: props.reference.source_entity_type as ItemType,
diff --git a/apps/web/src/lib/core/component/UserIcon.tsx b/apps/web/src/lib/core/component/UserIcon.tsx
index cabd808981..846c428f0e 100644
--- a/apps/web/src/lib/core/component/UserIcon.tsx
+++ b/apps/web/src/lib/core/component/UserIcon.tsx
@@ -5,11 +5,11 @@ import { staticFileSizedUrl } from '@core/constant/servers';
import { internalDrag } from '@core/directive/internalDragState';
import { useProfilePictureUrl } from '@core/signal/profilePicture';
import {
+ getDisplayName,
+ getDisplayNameParts,
getInitials,
macroIdToEmail,
tryMacroId,
- useDisplayName,
- useDisplayNameParts,
useIsConnectedSecondaryInbox,
} from '@core/user';
import MacroLogo from '@icon/macro-logo.svg';
@@ -60,9 +60,10 @@ function ProfileImage(props: {
return props.email || 'User';
});
- const { firstName, lastName } = useDisplayNameParts(macroId());
-
- const initials = () => getInitials(firstName(), lastName(), email());
+ const initials = () => {
+ const { firstName, lastName } = getDisplayNameParts(macroId());
+ return getInitials(firstName, lastName, email());
+ };
if (!ENABLE_PROFILE_PICTURES) {
return (
@@ -139,7 +140,7 @@ export function UserIcon(props: UserIconProps) {
props.id ? tryMacroId(props.id) : undefined
);
- const [displayName] = useDisplayName(macroId());
+ const displayName = () => getDisplayName(macroId());
const email = createMemo(() => {
const id = macroId();
diff --git a/apps/web/src/lib/core/user/displayName.ts b/apps/web/src/lib/core/user/displayName.ts
index b22628ce00..ca266c7b4d 100644
--- a/apps/web/src/lib/core/user/displayName.ts
+++ b/apps/web/src/lib/core/user/displayName.ts
@@ -67,6 +67,12 @@ type DisplayNameOptions = {
emailFallback?: 'full' | 'local-part';
};
+type DisplayNamePartStrings = {
+ firstName: string;
+ lastName: string;
+ fullName: string;
+};
+
function formatEmailFallback(email: string, options?: DisplayNameOptions) {
if (options?.emailFallback !== 'local-part') return email;
return email.split('@')[0] || email;
@@ -176,6 +182,26 @@ export function getDisplayName(
return defaultNameTransform(getUserNameItem(id), options);
}
+/** Resolves structured display name parts from the shared reactive cache. */
+export function getDisplayNameParts(
+ id: MacroId | undefined | null,
+ options?: DisplayNameOptions
+): DisplayNamePartStrings {
+ if (!id) return { firstName: '', lastName: '', fullName: '' };
+
+ const item = getUserNameItem(id);
+ const fullName = defaultNameTransform(item, options);
+
+ if (item.loading) return { firstName: '', lastName: '', fullName };
+
+ const firstName =
+ item.firstName && item.firstName !== 'N/A' ? item.firstName : '';
+ const lastName =
+ item.lastName && item.lastName !== 'N/A' ? item.lastName : '';
+
+ return { firstName, lastName, fullName };
+}
+
/** Shared hook that handles caching/fetching and returns the underlying UserNameItem */
function useUserNameItem(id: MacroId) {
ensureUserNameItem(id);
@@ -205,6 +231,10 @@ type DisplayNameParts = {
refetch: () => void;
};
+/**
+ * @deprecated Prefer `getDisplayNameParts` inside a reactive accessor so the
+ * current id is resolved when props/list rows change.
+ */
export function useDisplayNameParts(
id: MacroId | undefined | null,
options?: DisplayNameOptions
@@ -239,6 +269,10 @@ export function useDisplayNameParts(
return { firstName, lastName, fullName, refetch };
}
+/**
+ * @deprecated Prefer `getDisplayName` inside a reactive accessor so the
+ * current id is resolved when props/list rows change.
+ */
export function useDisplayName(
id: MacroId | undefined | null,
options?: DisplayNameOptions
diff --git a/apps/web/src/lib/core/user/index.ts b/apps/web/src/lib/core/user/index.ts
index e15a0a7a54..8bb417318a 100644
--- a/apps/web/src/lib/core/user/index.ts
+++ b/apps/web/src/lib/core/user/index.ts
@@ -8,6 +8,8 @@ export {
} from './combinedRecipient';
export { useContacts } from './contactService';
export {
+ getDisplayName,
+ getDisplayNameParts,
getInitials,
getInitialsFromName,
seedMockDisplayNames,