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(favorites): use preview for favorites name resolution (#4541)

teo6e18ae479304
diff --git a/js/app/packages/app/component/FavoriteIcon.tsx b/js/app/packages/app/component/FavoriteIcon.tsx
new file mode 100644
index 0000000000..1066281c4b
--- /dev/null
+++ b/js/app/packages/app/component/FavoriteIcon.tsx
@@ -0,0 +1,42 @@
+import {
+ favoriteIconType,
+ useFavoriteDmRecipientId,
+} from '@app/util/favorites';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { UserIcon } from '@core/component/UserIcon';
+import type { Favorite } from '@service-storage/generated/schemas/favorite';
+import { Show } from 'solid-js';
+
+/**
+ * Icon for a favorite. DM channel favorites show the other participant's
+ * avatar, matching how channel rows render elsewhere in the sidebar;
+ * everything else shows its entity icon.
+ *
+ * The favorite's identity must be stable for the component's lifetime
+ * (favorites lists key rows by entity, so it is).
+ */
+export function FavoriteIcon(props: { favorite: Favorite; class?: string }) {
+ const dmRecipientId = useFavoriteDmRecipientId(props.favorite);
+ return (
+ <Show
+ when={dmRecipientId()}
+ fallback={
+ <EntityIcon
+ size="xs"
+ targetType={favoriteIconType(props.favorite)}
+ class={props.class}
+ />
+ }
+ >
+ {(recipientId) => (
+ <UserIcon
+ id={recipientId()}
+ size="sm"
+ suppressClick
+ showTooltip={false}
+ class={props.class}
+ />
+ )}
+ </Show>
+ );
+}
diff --git a/js/app/packages/app/component/ItemDragAndDrop.tsx b/js/app/packages/app/component/ItemDragAndDrop.tsx
index 48e121a766..18b37cb335 100644
--- a/js/app/packages/app/component/ItemDragAndDrop.tsx
+++ b/js/app/packages/app/component/ItemDragAndDrop.tsx
@@ -1,4 +1,5 @@
import { TruncatedText } from '@core/component/FileList/TruncatedText';
+import { UserIcon } from '@core/component/UserIcon';
import type { EntityDragData } from '@entity';
import {
type CollisionDetector,
@@ -20,6 +21,7 @@ import {
createSignal,
type JSXElement,
onCleanup,
+ Show,
useContext,
} from 'solid-js';
@@ -88,6 +90,14 @@ function ItemDragOverlay() {
return getEntityIconType(data as EntityDragData);
});
+ // DM channel favorites show the other participant's avatar instead of the
+ // entity icon, matching their sidebar row (see FavoriteIcon).
+ const dmRecipientId = createMemo((): string | undefined => {
+ const data = activeDraggable()?.data;
+ if (data?.dragType !== 'favorite') return undefined;
+ return data.dmRecipientId as string | undefined;
+ });
+
const centeredOnPointerStyle = createMemo(() => {
const overlay = state?.active.overlay;
const sensor = state?.active.sensor;
@@ -105,7 +115,19 @@ function ItemDragOverlay() {
style={centeredOnPointerStyle()}
>
<div class="flex flex-row items-center gap-2">
- <EntityIcon size="xs" targetType={iconType()} />
+ <Show
+ when={dmRecipientId()}
+ fallback={<EntityIcon size="xs" targetType={iconType()} />}
+ >
+ {(recipientId) => (
+ <UserIcon
+ id={recipientId()}
+ size="sm"
+ suppressClick
+ showTooltip={false}
+ />
+ )}
+ </Show>
<TruncatedText size="xs">
{activeDraggable()?.data.name}
</TruncatedText>
diff --git a/js/app/packages/app/component/app-sidebar/favorites-section.tsx b/js/app/packages/app/component/app-sidebar/favorites-section.tsx
index 1d34f95192..dad4c70189 100644
--- a/js/app/packages/app/component/app-sidebar/favorites-section.tsx
+++ b/js/app/packages/app/component/app-sidebar/favorites-section.tsx
@@ -1,16 +1,15 @@
import type { SidebarState } from '@app/component/app-sidebar/sidebar';
+import { FavoriteIcon } from '@app/component/FavoriteIcon';
import { useSplitLayout } from '@app/component/split-layout/layout';
import { globalSplitManager } from '@app/signal/splitLayout';
import {
- favoriteDisplayName,
favoriteIconType,
favoriteSplitContent,
+ useFavoriteDisplayName,
+ useFavoriteDmRecipientId,
} from '@app/util/favorites';
import { ContextMenuContent, MenuItem } from '@core/component/ContextMenu';
-import {
- EntityIcon,
- type EntityIconSelector,
-} from '@core/component/EntityIcon';
+import type { EntityIconSelector } from '@core/component/EntityIcon';
import { ContextMenu } from '@kobalte/core/context-menu';
import CaretDownIcon from '@phosphor/caret-down.svg';
import {
@@ -38,6 +37,9 @@ export type FavoriteDragData = {
dragType: 'favorite';
iconType: EntityIconSelector;
name: string;
+ /** Other participant of a DM channel favorite; the drag overlay shows
+ * their avatar instead of the entity icon. */
+ dmRecipientId?: string;
/** Read by the `pointerWithin` collision detector to skip collapsed rows. */
isDropTargetDisabled: () => boolean;
};
@@ -166,8 +168,8 @@ const FavoriteRow = (props: { favorite: Favorite; disabled: boolean }) => {
const removeMutation = useRemoveFavoriteMutation();
const [dndState] = useDragDropContext() ?? [];
- const iconType = () => favoriteIconType(props.favorite);
- const displayName = () => favoriteDisplayName(props.favorite);
+ const displayName = useFavoriteDisplayName(props.favorite);
+ const dmRecipientId = useFavoriteDmRecipientId(props.favorite);
// `For` keys rows by favorite identity, so the favorite (and drag data
// derived from it) is stable for the row's lifetime.
@@ -177,12 +179,21 @@ const FavoriteRow = (props: { favorite: Favorite; disabled: boolean }) => {
// (clipped to 0 height for the expand/collapse animation), so without this
// their stale layout rects would capture drops. Gating on `disabled` keeps
// collapsed rows out of collision detection entirely.
+ //
+ // `name` and `dmRecipientId` are getters so the drag overlay chip reads
+ // the row's live values (names resolve asynchronously through the preview
+ // cache, DM recipients through the channels list).
const sortable = createSortable(
favoriteEntityKey(props.favorite.entityType, props.favorite.entityId),
{
dragType: 'favorite',
iconType: favoriteIconType(props.favorite),
- name: favoriteDisplayName(props.favorite),
+ get name() {
+ return displayName();
+ },
+ get dmRecipientId() {
+ return dmRecipientId();
+ },
isDropTargetDisabled: () => props.disabled,
} satisfies FavoriteDragData
);
@@ -241,7 +252,7 @@ const FavoriteRow = (props: { favorite: Favorite; disabled: boolean }) => {
fullWidth
onClick={open}
>
- <EntityIcon size="xs" targetType={iconType()} />
+ <FavoriteIcon favorite={props.favorite} />
<span class="truncate">{displayName()}</span>
</NavRow>
</ContextMenu.Trigger>
diff --git a/js/app/packages/app/component/command/FavoritesCommands.tsx b/js/app/packages/app/component/command/FavoritesCommands.tsx
index dadb300ace..7b6a7a0d7a 100644
--- a/js/app/packages/app/component/command/FavoritesCommands.tsx
+++ b/js/app/packages/app/component/command/FavoritesCommands.tsx
@@ -1,9 +1,5 @@
-import {
- favoriteDisplayName,
- favoriteIconType,
- favoriteSplitContent,
-} from '@app/util/favorites';
-import { EntityIcon } from '@core/component/EntityIcon';
+import { FavoriteIcon } from '@app/component/FavoriteIcon';
+import { favoriteDisplayName, favoriteSplitContent } from '@app/util/favorites';
import { registerScope } from '@core/hotkey/utils';
import Star from '@phosphor/star.svg';
import { useFavoritesData } from '@queries/favorites/favorites';
@@ -80,16 +76,16 @@ export function FavoritesCommands() {
dynamicGroup.add(
registerHotkey({
scopeId: FAVORITES_COMMAND_SCOPE,
- description: favoriteDisplayName(favorite),
+ // A callback so each render re-reads the preview cache, where
+ // names resolve (and renames land), warmed by the sidebar's
+ // favorite rows.
+ description: () => favoriteDisplayName(favorite),
keyDownHandler: () => {
openFavorite(favorite);
return true;
},
commandPaletteIcon: (props) => (
- <EntityIcon
- targetType={favoriteIconType(favorite)}
- class={props.class}
- />
+ <FavoriteIcon favorite={favorite} class={props.class} />
),
runWithInputFocused: true,
})
diff --git a/js/app/packages/app/util/favorites.ts b/js/app/packages/app/util/favorites.ts
index d93f5b575e..e4827c3db5 100644
--- a/js/app/packages/app/util/favorites.ts
+++ b/js/app/packages/app/util/favorites.ts
@@ -3,7 +3,18 @@ import { getChannelParams } from '@block-channel/utils/link';
import type { EntityIconSelector } from '@core/component/EntityIcon';
import { getIconConfig } from '@core/component/EntityIcon';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { useChannelsContext } from '@core/context/channels';
+import { useUserId } from '@core/context/user';
+import {
+ defaultNameTransform,
+ getCachedItemPreview,
+ type ItemEntity,
+ isAccessiblePreviewItem,
+ useItemPreview,
+} from '@queries/preview';
+import { ChannelTypeEnum } from '@service-storage/client';
import type { Favorite } from '@service-storage/generated/schemas/favorite';
+import { type Accessor, createMemo } from 'solid-js';
/** The block to open for a favorite (also its URL type segment). */
export function favoriteBlockName(favorite: Favorite) {
@@ -48,10 +59,104 @@ export function favoriteIconType(favorite: Favorite): EntityIconSelector {
return favoriteBlockName(favorite);
}
+/**
+ * The preview entity that names a favorite: the favorite's own entity for
+ * kinds the preview pipeline covers, the owning channel for channel-message
+ * favorites, and undefined for kinds without a preview fetcher
+ * (e.g. crm_contact), which fall back to their entity-kind label.
+ */
+function favoritePreviewEntity(favorite: Favorite): ItemEntity | undefined {
+ switch (favorite.entityType) {
+ case 'channel':
+ return { id: favorite.entityId, type: 'channel' };
+ case 'channel_message':
+ return favorite.channelId
+ ? { id: favorite.channelId, type: 'channel' }
+ : undefined;
+ case 'email_thread':
+ return { id: favorite.entityId, type: 'email' };
+ case 'document':
+ case 'chat':
+ case 'project':
+ case 'call':
+ case 'crm_company':
+ return { id: favorite.entityId, type: favorite.entityType };
+ default:
+ return undefined;
+ }
+}
+
+/**
+ * Non-reactive display name for a favorite, read from the preview cache.
+ * Previews are the app-wide name pipeline: viewer-relative for DM channels
+ * and written to by optimistic renames, so favorites need no rename
+ * special-casing (the favorites API deliberately returns no name). Falls
+ * back to the entity-kind label for previews not yet cached and kinds
+ * previews don't cover.
+ *
+ * Inside components prefer `useFavoriteDisplayName`, which subscribes to the
+ * preview instead of only reading whatever happens to be cached.
+ */
export function favoriteDisplayName(favorite: Favorite): string {
+ const entity = favoritePreviewEntity(favorite);
+ const cached = entity && getCachedItemPreview(entity.id);
+ if (cached) {
+ // The transform `useItemPreview` applies, so both paths agree.
+ const preview = defaultNameTransform(cached);
+ if (isAccessiblePreviewItem(preview) && preview.name.trim()) {
+ return preview.name;
+ }
+ }
return (
- favorite.name?.trim() ||
getIconConfig(favoriteIconType(favorite) ?? 'default').prettyName ||
'Untitled'
);
}
+
+/**
+ * The user whose avatar represents a DM channel favorite: the other
+ * participant, resolved from the channels list like the channel rows in the
+ * rest of the sidebar. Undefined for non-DM favorites (and while the channel
+ * list loads), so callers can fall back to the entity icon.
+ *
+ * Call during component setup. The favorite's identity must be stable for
+ * the component's lifetime (favorites lists key rows by entity, so it is).
+ */
+export function useFavoriteDmRecipientId(
+ favorite: Favorite
+): Accessor<string | undefined> {
+ const entity = favoritePreviewEntity(favorite);
+ const channelId = entity?.type === 'channel' ? entity.id : undefined;
+ if (!channelId) return () => undefined;
+ const ctx = useChannelsContext();
+ const userId = useUserId();
+ return createMemo(() => {
+ const channel = ctx.channelsById()[channelId];
+ if (channel?.channel_type !== ChannelTypeEnum.DirectMessage) {
+ return undefined;
+ }
+ // A self-DM has no other participant; show the viewer's own avatar.
+ const recipient =
+ channel.participants.find((p) => p.user_id !== userId()) ??
+ channel.participants[0];
+ return recipient?.user_id;
+ });
+}
+
+/**
+ * Reactive display name for a favorite: subscribes to the entity's preview
+ * (fetching it if needed) and resolves like `favoriteDisplayName`.
+ *
+ * Call during component setup. The favorite's identity must be stable for
+ * the component's lifetime (favorites lists key rows by entity, so it is).
+ */
+export function useFavoriteDisplayName(favorite: Favorite): Accessor<string> {
+ const entity = favoritePreviewEntity(favorite);
+ if (!entity) return () => favoriteDisplayName(favorite);
+ const [preview] = useItemPreview(() => entity);
+ return () => {
+ const item = preview();
+ if (isAccessiblePreviewItem(item) && item.name.trim()) return item.name;
+ return favoriteDisplayName(favorite);
+ };
+}
diff --git a/js/app/packages/queries/preview/index.ts b/js/app/packages/queries/preview/index.ts
index 46f74326db..83d55fcbb1 100644
--- a/js/app/packages/queries/preview/index.ts
+++ b/js/app/packages/queries/preview/index.ts
@@ -1,3 +1,4 @@
+export { defaultNameTransform } from './fetchers';
export {
getCachedItemPreview,
getItemPreview,
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/favorite.ts b/js/app/packages/service-clients/service-storage/generated/schemas/favorite.ts
index 76994c720a..49e42957e8 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/favorite.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/favorite.ts
@@ -9,11 +9,12 @@ import type { FavoriteChannelType } from './favoriteChannelType';
import type { FavoriteDocumentSubType } from './favoriteDocumentSubType';
import type { FavoriteEntityType } from './favoriteEntityType';
import type { FavoriteFileType } from './favoriteFileType';
-import type { FavoriteName } from './favoriteName';
/**
* A single favorited entity, including display metadata hydrated from the
-favorited entity where available.
+favorited entity where available. Display names are deliberately not
+included: clients resolve them from the entity previews pipeline, which
+is viewer-relative for DM channels and updated by renames.
A favorite is identified by `(entity_type, entity_id)` within the user's
collection; there is no surrogate id.
@@ -33,8 +34,6 @@ export interface Favorite {
entityType: FavoriteEntityType;
/** File type of the favorited document, when applicable. */
fileType?: FavoriteFileType;
- /** Display name of the favorited entity, when it could be resolved. */
- name?: FavoriteName;
/** Manual ordering value; lower sorts first. */
sortOrder: number;
}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/favoriteName.ts b/js/app/packages/service-clients/service-storage/generated/schemas/favoriteName.ts
deleted file mode 100644
index f49e328d57..0000000000
--- a/js/app/packages/service-clients/service-storage/generated/schemas/favoriteName.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * document_storage_service
- * OpenAPI spec version: 0.1.0
- */
-
-/**
- * Display name of the favorited entity, when it could be resolved.
- */
-export type FavoriteName = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index a1d209517e..1e562bdb4e 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -510,7 +510,6 @@ export * from './favoriteEntityRef';
export * from './favoriteEntityRefEntityType';
export * from './favoriteEntityType';
export * from './favoriteFileType';
-export * from './favoriteName';
export * from './favoritesList';
export * from './fileSystemNodeWithIds';
export * from './fileSystemNodeWithIdsOneOf';
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 5096a09534..dd37cfc194 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -6273,18 +6273,12 @@ export const listFavoritesResponse = zod
.describe(
'File type of the favorited document, when applicable.'
),
- name: zod
- .string()
- .nullish()
- .describe(
- 'Display name of the favorited entity, when it could be resolved.'
- ),
sortOrder: zod
.number()
.describe('Manual ordering value; lower sorts first.'),
})
.describe(
- "A single favorited entity, including display metadata hydrated from the\nfavorited entity where available.\n\nA favorite is identified by `(entity_type, entity_id)` within the user's\ncollection; there is no surrogate id."
+ "A single favorited entity, including display metadata hydrated from the\nfavorited entity where available. Display names are deliberately not\nincluded: clients resolve them from the entity previews pipeline, which\nis viewer-relative for DM channels and updated by renames.\n\nA favorite is identified by `(entity_type, entity_id)` within the user's\ncollection; there is no surrogate id."
)
)
.describe("The requesting user's favorites, in manual order."),
@@ -6362,18 +6356,12 @@ export const addFavoriteResponse = zod
.string()
.nullish()
.describe('File type of the favorited document, when applicable.'),
- name: zod
- .string()
- .nullish()
- .describe(
- 'Display name of the favorited entity, when it could be resolved.'
- ),
sortOrder: zod
.number()
.describe('Manual ordering value; lower sorts first.'),
})
.describe(
- "A single favorited entity, including display metadata hydrated from the\nfavorited entity where available.\n\nA favorite is identified by `(entity_type, entity_id)` within the user's\ncollection; there is no surrogate id."
+ "A single favorited entity, including display metadata hydrated from the\nfavorited entity where available. Display names are deliberately not\nincluded: clients resolve them from the entity previews pipeline, which\nis viewer-relative for DM channels and updated by renames.\n\nA favorite is identified by `(entity_type, entity_id)` within the user's\ncollection; there is no surrogate id."
);
/**
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 0b6b71c690..5515bb95ba 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -14333,7 +14333,7 @@
},
"Favorite": {
"type": "object",
- "description": "A single favorited entity, including display metadata hydrated from the\nfavorited entity where available.\n\nA favorite is identified by `(entity_type, entity_id)` within the user's\ncollection; there is no surrogate id.",
+ "description": "A single favorited entity, including display metadata hydrated from the\nfavorited entity where available. Display names are deliberately not\nincluded: clients resolve them from the entity previews pipeline, which\nis viewer-relative for DM channels and updated by renames.\n\nA favorite is identified by `(entity_type, entity_id)` within the user's\ncollection; there is no surrogate id.",
"required": ["entityType", "entityId", "sortOrder", "createdAt"],
"properties": {
"channelId": {
@@ -14385,10 +14385,6 @@
"type": ["string", "null"],
"description": "File type of the favorited document, when applicable."
},
- "name": {
- "type": ["string", "null"],
- "description": "Display name of the favorited entity, when it could be resolved."
- },
"sortOrder": {
"type": "number",
"format": "double",
diff --git a/rust/cloud-storage/.sqlx/query-125c32f6efd3f81dbd4a01e20aeb668399f153c44c0ac147af1612cac86f1360.json b/rust/cloud-storage/.sqlx/query-125c32f6efd3f81dbd4a01e20aeb668399f153c44c0ac147af1612cac86f1360.json
deleted file mode 100644
index 318a70d683..0000000000
--- a/rust/cloud-storage/.sqlx/query-125c32f6efd3f81dbd4a01e20aeb668399f153c44c0ac147af1612cac86f1360.json
+++ /dev/null
@@ -1,70 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n f.entity_type as \"entity_type!\",\n f.entity_id as \"entity_id!\",\n f.sort_order as \"sort_order!\",\n f.created_at as \"created_at!\",\n CASE f.entity_type\n WHEN 'document' THEN d.name\n WHEN 'chat' THEN c.name\n WHEN 'project' THEN p.name\n WHEN 'channel' THEN ch.name::text\n WHEN 'email_thread' THEN em.subject\n END as \"name?\",\n d.\"fileType\" as \"file_type?\",\n dt.sub_type::text as \"document_sub_type?\",\n ch.channel_type::text as \"channel_type?\",\n cm.channel_id::text as \"channel_id?\"\n FROM favorite f\n -- The comms/email tables key on uuid while favorite.entity_id is\n -- text. Compare in uuid (casting the favorite side) so their\n -- primary-key indexes are usable; casting the table side to text\n -- forced a full scan of each table on every listing. The regex\n -- guard keeps non-uuid entity_ids from failing the cast: they\n -- yield NULL and simply don't hydrate.\n CROSS JOIN LATERAL (\n SELECT CASE\n WHEN f.entity_id ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'\n THEN f.entity_id::uuid\n END AS entity_uuid\n ) fid\n LEFT JOIN \"Document\" d ON f.entity_type = 'document' AND d.id = f.entity_id\n LEFT JOIN document_sub_type dt ON f.entity_type = 'document' AND dt.document_id = f.entity_id\n LEFT JOIN \"Chat\" c ON f.entity_type = 'chat' AND c.id = f.entity_id\n LEFT JOIN \"Project\" p ON f.entity_type = 'project' AND p.id = f.entity_id\n LEFT JOIN comms_channels ch ON f.entity_type = 'channel' AND ch.id = fid.entity_uuid\n LEFT JOIN comms_messages cm ON f.entity_type = 'channel_message' AND cm.id = fid.entity_uuid\n LEFT JOIN email_threads et ON f.entity_type = 'email_thread' AND et.id = fid.entity_uuid\n LEFT JOIN LATERAL (\n SELECT m.subject\n FROM email_messages m\n WHERE m.thread_id = et.id AND m.is_draft = false\n ORDER BY m.internal_date_ts DESC NULLS LAST\n LIMIT 1\n ) em ON f.entity_type = 'email_thread'\n WHERE f.user_id = $1\n AND (f.entity_type <> 'document' OR (d.id IS NOT NULL AND d.\"deletedAt\" IS NULL))\n AND (f.entity_type <> 'chat' OR (c.id IS NOT NULL AND c.\"deletedAt\" IS NULL))\n AND (f.entity_type <> 'project' OR (p.id IS NOT NULL AND p.\"deletedAt\" IS NULL))\n ORDER BY f.sort_order ASC, f.created_at ASC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "entity_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "entity_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "sort_order!",
- "type_info": "Float8"
- },
- {
- "ordinal": 3,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 4,
- "name": "name?",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "file_type?",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "document_sub_type?",
- "type_info": "Text"
- },
- {
- "ordinal": 7,
- "name": "channel_type?",
- "type_info": "Text"
- },
- {
- "ordinal": 8,
- "name": "channel_id?",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- null,
- true,
- null,
- null,
- null
- ]
- },
- "hash": "125c32f6efd3f81dbd4a01e20aeb668399f153c44c0ac147af1612cac86f1360"
-}
diff --git a/rust/cloud-storage/.sqlx/query-6f3e5a9da9b4b7707fe669543cca05cee88e530856bb0e1c8512c973b8bc9574.json b/rust/cloud-storage/.sqlx/query-6f3e5a9da9b4b7707fe669543cca05cee88e530856bb0e1c8512c973b8bc9574.json
new file mode 100644
index 0000000000..5cefe36f50
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-6f3e5a9da9b4b7707fe669543cca05cee88e530856bb0e1c8512c973b8bc9574.json
@@ -0,0 +1,64 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n f.entity_type as \"entity_type!\",\n f.entity_id as \"entity_id!\",\n f.sort_order as \"sort_order!\",\n f.created_at as \"created_at!\",\n d.\"fileType\" as \"file_type?\",\n dt.sub_type::text as \"document_sub_type?\",\n ch.channel_type::text as \"channel_type?\",\n cm.channel_id::text as \"channel_id?\"\n FROM favorite f\n -- The comms tables key on uuid while favorite.entity_id is text.\n -- Compare in uuid (casting the favorite side) so their\n -- primary-key indexes are usable; casting the table side to text\n -- forced a full scan of each table on every listing. The regex\n -- guard keeps non-uuid entity_ids from failing the cast: they\n -- yield NULL and simply don't hydrate.\n CROSS JOIN LATERAL (\n SELECT CASE\n WHEN f.entity_id ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'\n THEN f.entity_id::uuid\n END AS entity_uuid\n ) fid\n LEFT JOIN \"Document\" d ON f.entity_type = 'document' AND d.id = f.entity_id\n LEFT JOIN document_sub_type dt ON f.entity_type = 'document' AND dt.document_id = f.entity_id\n LEFT JOIN \"Chat\" c ON f.entity_type = 'chat' AND c.id = f.entity_id\n LEFT JOIN \"Project\" p ON f.entity_type = 'project' AND p.id = f.entity_id\n LEFT JOIN comms_channels ch ON f.entity_type = 'channel' AND ch.id = fid.entity_uuid\n LEFT JOIN comms_messages cm ON f.entity_type = 'channel_message' AND cm.id = fid.entity_uuid\n WHERE f.user_id = $1\n AND (f.entity_type <> 'document' OR (d.id IS NOT NULL AND d.\"deletedAt\" IS NULL))\n AND (f.entity_type <> 'chat' OR (c.id IS NOT NULL AND c.\"deletedAt\" IS NULL))\n AND (f.entity_type <> 'project' OR (p.id IS NOT NULL AND p.\"deletedAt\" IS NULL))\n ORDER BY f.sort_order ASC, f.created_at ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "sort_order!",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "file_type?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "document_sub_type?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "channel_type?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "channel_id?",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ true,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "6f3e5a9da9b4b7707fe669543cca05cee88e530856bb0e1c8512c973b8bc9574"
+}
diff --git a/rust/cloud-storage/.sqlx/query-cdeb95aa35e2207dc99cd6d6935eef5787ce1ef740b56c75c998746732743416.json b/rust/cloud-storage/.sqlx/query-fc23180cd6d21a0a22ad0414c440d41068e04bc1e8a1a64d52382dc2e47be889.json
similarity index 79%
rename from rust/cloud-storage/.sqlx/query-cdeb95aa35e2207dc99cd6d6935eef5787ce1ef740b56c75c998746732743416.json
rename to rust/cloud-storage/.sqlx/query-fc23180cd6d21a0a22ad0414c440d41068e04bc1e8a1a64d52382dc2e47be889.json
index 3a14193d11..18cb487e73 100644
--- a/rust/cloud-storage/.sqlx/query-cdeb95aa35e2207dc99cd6d6935eef5787ce1ef740b56c75c998746732743416.json
+++ b/rust/cloud-storage/.sqlx/query-fc23180cd6d21a0a22ad0414c440d41068e04bc1e8a1a64d52382dc2e47be889.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO favorite (user_id, entity_type, entity_id, sort_order)\n VALUES (\n $1, $2, $3,\n COALESCE((SELECT MAX(sort_order) + 1 FROM favorite WHERE user_id = $1), 0)\n )\n ON CONFLICT (user_id, entity_type, entity_id)\n DO UPDATE SET updated_at = now()\n RETURNING\n entity_type as \"entity_type!\",\n entity_id as \"entity_id!\",\n sort_order as \"sort_order!\",\n created_at as \"created_at!\",\n NULL::text as \"name?\",\n NULL::text as \"file_type?\",\n NULL::text as \"document_sub_type?\",\n NULL::text as \"channel_type?\",\n NULL::text as \"channel_id?\"\n ",
+ "query": "\n INSERT INTO favorite (user_id, entity_type, entity_id, sort_order)\n VALUES (\n $1, $2, $3,\n COALESCE((SELECT MAX(sort_order) + 1 FROM favorite WHERE user_id = $1), 0)\n )\n ON CONFLICT (user_id, entity_type, entity_id)\n DO UPDATE SET updated_at = now()\n RETURNING\n entity_type as \"entity_type!\",\n entity_id as \"entity_id!\",\n sort_order as \"sort_order!\",\n created_at as \"created_at!\",\n NULL::text as \"file_type?\",\n NULL::text as \"document_sub_type?\",\n NULL::text as \"channel_type?\",\n NULL::text as \"channel_id?\"\n ",
"describe": {
"columns": [
{
@@ -25,26 +25,21 @@
},
{
"ordinal": 4,
- "name": "name?",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
"name": "file_type?",
"type_info": "Text"
},
{
- "ordinal": 6,
+ "ordinal": 5,
"name": "document_sub_type?",
"type_info": "Text"
},
{
- "ordinal": 7,
+ "ordinal": 6,
"name": "channel_type?",
"type_info": "Text"
},
{
- "ordinal": 8,
+ "ordinal": 7,
"name": "channel_id?",
"type_info": "Text"
}
@@ -64,9 +59,8 @@
null,
null,
null,
- null,
null
]
},
- "hash": "cdeb95aa35e2207dc99cd6d6935eef5787ce1ef740b56c75c998746732743416"
+ "hash": "fc23180cd6d21a0a22ad0414c440d41068e04bc1e8a1a64d52382dc2e47be889"
}
diff --git a/rust/cloud-storage/favorites/src/domain/models.rs b/rust/cloud-storage/favorites/src/domain/models.rs
index ad6fa03309..c4c7411f3a 100644
--- a/rust/cloud-storage/favorites/src/domain/models.rs
+++ b/rust/cloud-storage/favorites/src/domain/models.rs
@@ -5,7 +5,9 @@ use model_entity::{Entity, EntityType};
use serde::{Deserialize, Serialize};
/// A single favorited entity, including display metadata hydrated from the
-/// favorited entity where available.
+/// favorited entity where available. Display names are deliberately not
+/// included: clients resolve them from the entity previews pipeline, which
+/// is viewer-relative for DM channels and updated by renames.
///
/// A favorite is identified by `(entity_type, entity_id)` within the user's
/// collection; there is no surrogate id.
@@ -24,9 +26,6 @@ pub struct Favorite {
pub sort_order: f64,
/// When the favorite was created.
pub created_at: DateTime<Utc>,
- /// Display name of the favorited entity, when it could be resolved.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub name: Option<String>,
/// File type of the favorited document, when applicable.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_type: Option<String>,
diff --git a/rust/cloud-storage/favorites/src/inbound/axum_router.rs b/rust/cloud-storage/favorites/src/inbound/axum_router.rs
index 87f784afd7..4c505308bc 100644
--- a/rust/cloud-storage/favorites/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/favorites/src/inbound/axum_router.rs
@@ -52,11 +52,11 @@ where
/// Ensure the caller has at least view access to the entity they are trying
/// to favorite.
///
-/// Favorites hydrate display metadata (names, email subjects, channel types)
-/// on read, so without this check a caller could favorite an arbitrary id and
-/// use `GET /favorites` as an oracle for entities they cannot see. Entity
-/// types the access layer does not recognize (e.g. channel messages) resolve
-/// to "no access" and are rejected.
+/// Favorites hydrate display metadata (channel types, file types) on read,
+/// so without this check a caller could favorite an arbitrary id and use
+/// `GET /favorites` as an oracle for entities they cannot see. Entity types
+/// the access layer does not recognize (e.g. channel messages) resolve to
+/// "no access" and are rejected.
async fn ensure_entity_access<AccessSvc>(
access_service: &AccessSvc,
user: &MacroUserExtractor,
@@ -202,7 +202,7 @@ where
AccessSvc: EntityAccessService,
{
// Only let the caller favorite entities they can actually access, so a
- // favorite can't be used as an oracle for entity metadata (name, subject,
+ // favorite can't be used as an oracle for entity metadata (file type,
// private-channel type) they were never allowed to see.
ensure_entity_access(
state.access_service.as_ref(),
diff --git a/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo.rs b/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo.rs
index 242032dfe3..c82bf7ffc8 100644
--- a/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo.rs
+++ b/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo.rs
@@ -42,7 +42,6 @@ struct FavoriteRow {
entity_id: String,
sort_order: f64,
created_at: DateTime<Utc>,
- name: Option<String>,
file_type: Option<String>,
document_sub_type: Option<String>,
channel_type: Option<String>,
@@ -60,7 +59,6 @@ impl FavoriteRow {
entity_id: self.entity_id,
sort_order: self.sort_order,
created_at: self.created_at,
- name: self.name,
file_type: self.file_type,
document_sub_type: self.document_sub_type,
channel_type: self.channel_type,
@@ -94,7 +92,6 @@ impl FavoritesRepo for PgFavoritesRepo {
entity_id as "entity_id!",
sort_order as "sort_order!",
created_at as "created_at!",
- NULL::text as "name?",
NULL::text as "file_type?",
NULL::text as "document_sub_type?",
NULL::text as "channel_type?",
@@ -125,8 +122,9 @@ impl FavoritesRepo for PgFavoritesRepo {
&self,
user_id: &MacroUserIdStr<'_>,
) -> Result<Vec<Favorite>, Self::Err> {
- // Resolves display metadata for the favorited entity where possible and
- // omits favorites whose target is deleted.
+ // Resolves display metadata for the favorited entity where possible
+ // and omits favorites whose target is deleted. Display names are not
+ // hydrated here: clients resolve them from entity previews.
let rows = sqlx::query_as!(
FavoriteRow,
r#"
@@ -135,20 +133,13 @@ impl FavoritesRepo for PgFavoritesRepo {
f.entity_id as "entity_id!",
f.sort_order as "sort_order!",
f.created_at as "created_at!",
- CASE f.entity_type
- WHEN 'document' THEN d.name
- WHEN 'chat' THEN c.name
- WHEN 'project' THEN p.name
- WHEN 'channel' THEN ch.name::text
- WHEN 'email_thread' THEN em.subject
- END as "name?",
d."fileType" as "file_type?",
dt.sub_type::text as "document_sub_type?",
ch.channel_type::text as "channel_type?",
cm.channel_id::text as "channel_id?"
FROM favorite f
- -- The comms/email tables key on uuid while favorite.entity_id is
- -- text. Compare in uuid (casting the favorite side) so their
+ -- The comms tables key on uuid while favorite.entity_id is text.
+ -- Compare in uuid (casting the favorite side) so their
-- primary-key indexes are usable; casting the table side to text
-- forced a full scan of each table on every listing. The regex
-- guard keeps non-uuid entity_ids from failing the cast: they
@@ -165,14 +156,6 @@ impl FavoritesRepo for PgFavoritesRepo {
LEFT JOIN "Project" p ON f.entity_type = 'project' AND p.id = f.entity_id
LEFT JOIN comms_channels ch ON f.entity_type = 'channel' AND ch.id = fid.entity_uuid
LEFT JOIN comms_messages cm ON f.entity_type = 'channel_message' AND cm.id = fid.entity_uuid
- LEFT JOIN email_threads et ON f.entity_type = 'email_thread' AND et.id = fid.entity_uuid
- LEFT JOIN LATERAL (
- SELECT m.subject
- FROM email_messages m
- WHERE m.thread_id = et.id AND m.is_draft = false
- ORDER BY m.internal_date_ts DESC NULLS LAST
- LIMIT 1
- ) em ON f.entity_type = 'email_thread'
WHERE f.user_id = $1
AND (f.entity_type <> 'document' OR (d.id IS NOT NULL AND d."deletedAt" IS NULL))
AND (f.entity_type <> 'chat' OR (c.id IS NOT NULL AND c."deletedAt" IS NULL))
diff --git a/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo/tests.rs b/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo/tests.rs
index 3802aab16d..5465cecaee 100644
--- a/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo/tests.rs
+++ b/rust/cloud-storage/favorites/src/outbound/pg_favorites_repo/tests.rs
@@ -118,7 +118,7 @@ async fn count_favorites_counts_user_collection(pool: PgPool) {
}
#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
-async fn list_favorites_hydrates_names_and_skips_deleted(pool: PgPool) {
+async fn list_favorites_skips_deleted(pool: PgPool) {
insert_user(&pool, USER_A).await;
insert_document(&pool, "doc-live", "Launch plan", USER_A).await;
insert_document(&pool, "doc-gone", "Old doc", USER_A).await;
@@ -150,9 +150,7 @@ async fn list_favorites_hydrates_names_and_skips_deleted(pool: PgPool) {
.expect("favorites should list");
assert_eq!(favorites.len(), 2);
assert_eq!(favorites[0].entity_id, "doc-live");
- assert_eq!(favorites[0].name.as_deref(), Some("Launch plan"));
assert_eq!(favorites[1].entity_type, EntityType::EmailThread);
- assert_eq!(favorites[1].name, None);
}
#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
@@ -191,10 +189,8 @@ async fn list_favorites_hydrates_uuid_keyed_entities(pool: PgPool) {
.expect("favorites should list");
assert_eq!(favorites.len(), 2);
assert_eq!(favorites[0].entity_id, channel_id);
- assert_eq!(favorites[0].name.as_deref(), Some("Eng"));
assert_eq!(favorites[0].channel_type.as_deref(), Some("public"));
assert_eq!(favorites[1].entity_id, "not-a-uuid");
- assert_eq!(favorites[1].name, None);
assert_eq!(favorites[1].channel_type, None);
}