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.

feat(search): channel message entity (#2359)

gbirman2a1fe9b3402b
diff --git a/js/app/packages/app/component/PreviewPanel.tsx b/js/app/packages/app/component/PreviewPanel.tsx
index f60be74673..7286e56960 100644
--- a/js/app/packages/app/component/PreviewPanel.tsx
+++ b/js/app/packages/app/component/PreviewPanel.tsx
@@ -1,8 +1,8 @@
-import type { BlockAliasContext } from '@core/block';
+import type { BlockAliasContext, BlockName } from '@core/block';
import { fileTypeToResolvedBlockName } from '@core/constant/allBlocks';
import type { BlockOrchestrator } from '@core/orchestrator';
import type { NonNullableFields } from '@core/util/withRequired';
-import { type EntityData, isTaskEntity } from '@entity';
+import { type EntityData, isTaskEntity, isChannelMessageEntity } from '@entity';
import {
type Component,
createRenderEffect,
@@ -18,6 +18,7 @@ import { useSplitPanelOrThrow } from './split-layout/layoutUtils';
import { Suspense } from 'solid-js';
import { createContextProvider } from '@solid-primitives/context';
import { throttledDependent } from '@core/util/debounce';
+import { getChannelParams } from '@block-channel/utils/link';
export const [PreviewPanelContext, useMaybePreviewPanel] =
createContextProvider(
@@ -67,13 +68,23 @@ const PreviewPanelContent: Component<NonNullableFields<PreviewPanel>> = (
baseType: 'md',
} as BlockAliasContext)
: undefined;
- return props.orchestrator.createBlockInstance(
- props.selectedEntity.type === 'document'
- ? fileTypeToResolvedBlockName(props.selectedEntity.fileType)
- : props.selectedEntity.type,
- props.selectedEntity.id,
- { aliasContext }
- );
+
+ let blockType: BlockName;
+ let blockId: string;
+ if (props.selectedEntity.type === 'document') {
+ blockType = fileTypeToResolvedBlockName(props.selectedEntity.fileType);
+ blockId = props.selectedEntity.id;
+ } else if (props.selectedEntity.type === 'channel_message') {
+ blockType = 'channel';
+ blockId = props.selectedEntity.channelId;
+ } else {
+ blockType = props.selectedEntity.type;
+ blockId = props.selectedEntity.id;
+ }
+
+ return props.orchestrator.createBlockInstance(blockType, blockId, {
+ aliasContext,
+ });
};
const [interactedWith, setInteractedWith] = createSignal(false);
@@ -82,6 +93,17 @@ const PreviewPanelContent: Component<NonNullableFields<PreviewPanel>> = (
if (id !== prevId) {
setInteractedWith(false);
}
+
+ const entity = props.selectedEntity;
+ if (isChannelMessageEntity(entity)) {
+ const channelId = entity.channelId;
+ const messageId = entity.messageId;
+ const threadId = entity.threadId;
+ props.orchestrator.getBlockHandle(channelId).then((handle) => {
+ handle?.goToLocationFromParams(getChannelParams(messageId, threadId));
+ });
+ }
+
return id;
}, props.selectedEntity.id);
@@ -98,8 +120,6 @@ const PreviewPanelContent: Component<NonNullableFields<PreviewPanel>> = (
class="flex flex-col size-full"
onFocusIn={(event) => {
if (interactedWith()) return;
- const relatedTarget = event.relatedTarget;
- const currentTarget = event.currentTarget;
// TODO: use state instead to determine when preview block can recieve focus
if (event.target.hasAttribute('data-allow-focus-in-preview')) {
@@ -107,10 +127,19 @@ const PreviewPanelContent: Component<NonNullableFields<PreviewPanel>> = (
return;
}
- if (relatedTarget instanceof HTMLElement) {
- if (!currentTarget.contains(relatedTarget)) {
- relatedTarget.focus();
- }
+ // Prevent blocks from stealing focus in preview mode.
+ // Redirect to the previous element if it was outside the preview,
+ // otherwise blur the target to keep focus on the search list.
+ const relatedTarget = event.relatedTarget;
+ const currentTarget = event.currentTarget;
+
+ if (
+ relatedTarget instanceof HTMLElement &&
+ !currentTarget.contains(relatedTarget)
+ ) {
+ relatedTarget.focus();
+ } else {
+ (event.target as HTMLElement).blur?.();
}
}}
onPointerDown={() => {
diff --git a/js/app/packages/app/component/command/CommandMenu.tsx b/js/app/packages/app/component/command/CommandMenu.tsx
index 0fcce36b42..c8dc613fbf 100644
--- a/js/app/packages/app/component/command/CommandMenu.tsx
+++ b/js/app/packages/app/component/command/CommandMenu.tsx
@@ -9,7 +9,6 @@ import { runCommand } from '@core/hotkey/utils';
import { Dialog } from '@kobalte/core/dialog';
import { Tabs } from '@kobalte/core/tabs';
import { registerHotkey, useHotkeyDOMScope } from 'core/hotkey/hotkeys';
-import type { BlockName, BlockAlias } from '@core/block';
import {
createEffect,
createMemo,
@@ -53,15 +52,6 @@ const VIRTUAL_ITEM_HEIGHT = 40; // tailwind h-10
const MAX_LIST_HEIGHT = VIRTUAL_ITEM_HEIGHT * 8;
const EMPTY_STATE_HEIGHT = VIRTUAL_ITEM_HEIGHT * 1.5;
-export function getBlockNameForEntity(
- item: CommandMenuItem
-): BlockName | BlockAlias | undefined {
- if (isEntityItem(item)) {
- return itemToBlockName(item.data);
- }
- return undefined; // no block for commands or users
-}
-
export function CommandMenu() {
const [commandMenuRef, setCommandMenuRef] = createSignal<HTMLDivElement>();
const splitManager = globalSplitManager();
@@ -168,7 +158,7 @@ export function CommandMenuInner(props: {
// Handle entity items (documents, channels, chats, etc.)
if (isEntityItem(item)) {
- const blockName = getBlockNameForEntity(item);
+ const blockName = itemToBlockName(item.data);
if (blockName) {
openWithSplit(
{ type: blockName, id: item.id },
diff --git a/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsx b/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsx
index 9f77c506d2..b7560529b6 100644
--- a/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsx
+++ b/js/app/packages/app/component/global-share-modal/GlobalShareModal.tsx
@@ -9,8 +9,13 @@ import { createSignal, Show } from 'solid-js';
type ShareableEntityType = 'document' | 'chat' | 'project';
+export type ShareableEntityData = Extract<
+ EntityData,
+ { type: ShareableEntityType }
+>;
+
export type GlobalShareModalProps = {
- entity: EntityData;
+ entity: ShareableEntityData;
onClose?: () => void;
};
@@ -26,12 +31,14 @@ export const isShareableEntityType = (
return type === 'document' || type === 'chat' || type === 'project';
};
-const getEntityBlockAlias = (entity: EntityData): BlockName | BlockAlias => {
+const getEntityBlockAlias = (
+ entity: ShareableEntityData
+): BlockName | BlockAlias => {
return itemToBlockName(entity) ?? 'unknown';
};
-const getEntityItemType = (entity: EntityData): ItemType => {
- return entity.type as ItemType;
+const getEntityItemType = (entity: ShareableEntityData): ItemType => {
+ return entity.type;
};
export const openGlobalShareModal = (props: GlobalShareModalProps) => {
diff --git a/js/app/packages/app/component/import-linear/ImportLinear.tsx b/js/app/packages/app/component/import-linear/ImportLinear.tsx
index 6a08156f7f..893e39a5f4 100644
--- a/js/app/packages/app/component/import-linear/ImportLinear.tsx
+++ b/js/app/packages/app/component/import-linear/ImportLinear.tsx
@@ -331,7 +331,7 @@ export default function ImportLinear() {
{(id) => (
<a
class="text-sm text-ink underline underline-offset-2"
- href={buildSimpleEntityUrl({ type: 'task', id }, {})}
+ href={buildSimpleEntityUrl({ type: 'task', id })}
target="_blank"
rel="noreferrer"
>
diff --git a/js/app/packages/app/component/mobile/MobileSearch.tsx b/js/app/packages/app/component/mobile/MobileSearch.tsx
index 3216736cb5..3514edd388 100644
--- a/js/app/packages/app/component/mobile/MobileSearch.tsx
+++ b/js/app/packages/app/component/mobile/MobileSearch.tsx
@@ -31,11 +31,11 @@ import {
} from '../command/useCommandItems';
import { SearchState } from './mobileSearchState';
import { CommandItem } from '../command/CommandItem';
-import { getBlockNameForEntity } from '../command/CommandMenu';
import { useFullTextSearch } from '@queries/soup/useFullTextSearch';
import { windowSearchMatch } from '@core/util/searchHighlight';
import { TailSpinner } from '@core/component/TailSpinner';
import { ScrollIndicators } from '@core/component/VerticalScrollIndicators';
+import { itemToBlockName } from '@core/constant/allBlocks';
const CATEGORIES: { id: CategoryFilter; label: string }[] = [
{ id: 'all', label: 'All' },
@@ -109,7 +109,7 @@ export function MobileSearchInner() {
// Handle entity items (documents, channels, chats, etc.)
if (isEntityItem(item)) {
- const blockName = getBlockNameForEntity(item);
+ const blockName = itemToBlockName(item.data);
if (blockName) {
openWithSplit(
{ type: blockName, id: item.id },
diff --git a/js/app/packages/app/component/next-soup/actions/make-copy-action.ts b/js/app/packages/app/component/next-soup/actions/make-copy-action.ts
index 88a6b1f9a9..2f5a84c3dd 100644
--- a/js/app/packages/app/component/next-soup/actions/make-copy-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-copy-action.ts
@@ -7,7 +7,11 @@ export const makeCopyAction = () => {
const bulkCopyMutation = createBulkCopyDssEntityMutation();
const canExecute = (entity: EntityData): boolean => {
- return entity.type !== 'channel' && entity.type !== 'email';
+ return (
+ entity.type !== 'channel' &&
+ entity.type !== 'email' &&
+ entity.type !== 'channel_message'
+ );
};
const execute = async (entities: EntityData[]) => {
diff --git a/js/app/packages/app/component/next-soup/actions/make-copy-link-action.ts b/js/app/packages/app/component/next-soup/actions/make-copy-link-action.ts
index 2b63b5e10d..e6850d42e4 100644
--- a/js/app/packages/app/component/next-soup/actions/make-copy-link-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-copy-link-action.ts
@@ -3,6 +3,7 @@ import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { buildSimpleEntityUrl } from '@core/util/url';
import type { EntityData } from '@entity';
import type { SoupState } from '../create-soup-state';
+import { getChannelParams } from '@block-channel/utils/link';
/**
* Get the URL type/path segment for an entity
@@ -11,10 +12,36 @@ const getEntityUrlType = (entity: EntityData): string => {
if (entity.type === 'document') {
const { fileType, subType } = entity;
return fileTypeToBlockName(subType?.type ?? fileType);
+ } else if (entity.type === 'channel_message') {
+ return 'channel';
}
return entity.type;
};
+const getEntityUrlId = (entity: EntityData): string => {
+ if (entity.type === 'channel_message') {
+ return entity.channelId;
+ }
+ return entity.id;
+};
+
+const getEntityUrlParams = (
+ entity: EntityData
+): Record<string, string> | undefined => {
+ if (entity.type !== 'channel_message') return undefined;
+ return getChannelParams(entity.messageId, entity.threadId);
+};
+
+const getEntityUrl = (entity: EntityData): string => {
+ return buildSimpleEntityUrl(
+ {
+ type: getEntityUrlType(entity),
+ id: getEntityUrlId(entity),
+ },
+ getEntityUrlParams(entity)
+ );
+};
+
export const makeCopyLinkAction = () => {
const canExecute = (_entity: EntityData): boolean => {
// Can copy link for any entity type
@@ -26,13 +53,7 @@ export const makeCopyLinkAction = () => {
const entity = entities[0];
if (!entity) return;
- const url = buildSimpleEntityUrl(
- {
- type: getEntityUrlType(entity),
- id: entity.id,
- },
- {}
- );
+ const url = getEntityUrl(entity);
await navigator.clipboard.writeText(url);
toast.success('Link copied to clipboard');
diff --git a/js/app/packages/app/component/next-soup/actions/make-delete-action.ts b/js/app/packages/app/component/next-soup/actions/make-delete-action.ts
index 5c10d2f14c..26ec3d0380 100644
--- a/js/app/packages/app/component/next-soup/actions/make-delete-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-delete-action.ts
@@ -16,6 +16,7 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {
const { userId } = options;
const canExecute = (entity: EntityData): boolean => {
+ if (entity.type === 'channel_message') return false;
if (entity.type === 'email') {
return true;
}
diff --git a/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts b/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts
index 44513074cb..2b6ec6117c 100644
--- a/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-mark-done-action.ts
@@ -37,6 +37,7 @@ export const makeMarkDoneAction = (options: MakeMarkDoneOptions) => {
useSetPropertyStatusCompleteMutation();
const canExecute = (entity: EntityData): boolean => {
+ if (entity.type === 'channel_message') return false;
if (
entity.type === 'email' ||
entity.type === 'channel' ||
diff --git a/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts b/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts
index 68f733770f..787464eed1 100644
--- a/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-move-to-project-action.ts
@@ -7,7 +7,7 @@ import { useMaybePreviewPanel } from '@app/component/PreviewPanel';
export const makeMoveToProjectAction = () => {
const canExecute = (entity: EntityData): boolean => {
- return entity.type !== 'channel';
+ return entity.type !== 'channel' && entity.type !== 'channel_message';
};
const execute = async (entities: EntityData[]) => {
diff --git a/js/app/packages/app/component/next-soup/actions/make-rename-action.ts b/js/app/packages/app/component/next-soup/actions/make-rename-action.ts
index bf304fee26..05b695c003 100644
--- a/js/app/packages/app/component/next-soup/actions/make-rename-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-rename-action.ts
@@ -14,6 +14,7 @@ export const makeRenameAction = (options: MakeRenameOptions) => {
const canExecute = (entity: EntityData): boolean => {
if (entity.type === 'email') return false;
+ if (entity.type === 'channel_message') return false;
if (entity.type === 'channel') {
if (entity.channelType === 'direct_message') return false;
diff --git a/js/app/packages/app/component/next-soup/actions/make-share-action.ts b/js/app/packages/app/component/next-soup/actions/make-share-action.ts
index 2ffc96efae..822c6789f5 100644
--- a/js/app/packages/app/component/next-soup/actions/make-share-action.ts
+++ b/js/app/packages/app/component/next-soup/actions/make-share-action.ts
@@ -3,6 +3,7 @@ import type { SoupState } from '../create-soup-state';
import {
isShareableEntityType,
openGlobalShareModal,
+ type ShareableEntityData,
} from '@app/component/global-share-modal/GlobalShareModal';
export const makeShareAction = () => {
@@ -20,7 +21,8 @@ export const makeShareAction = () => {
}
openGlobalShareModal({
- entity,
+ // TODO: use type guard on entity data, not the type
+ entity: entity as ShareableEntityData,
});
};
diff --git a/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts b/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
index e95eb5f950..33a99b827c 100644
--- a/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
+++ b/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
@@ -125,7 +125,7 @@ export const useEntityActionHotkeys = (
keyDownHandler: () => {
const entities = getEntitiesForAction();
if (entities.length === 0) return false;
- if (!entities.some(markDone.canExecute)) return false;
+ if (!entities.every(markDone.canExecute)) return false;
markDone.executeWithSoup(entities, soup, openNextEntity);
return true;
@@ -133,7 +133,7 @@ export const useEntityActionHotkeys = (
condition: () => {
if (condition && !condition()) return false;
const entities = getEntitiesForAction();
- return entities.some(markDone.canExecute);
+ return entities.length > 0 && entities.every(markDone.canExecute);
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
@@ -203,7 +203,7 @@ export const useEntityActionHotkeys = (
keyDownHandler: () => {
const entities = getEntitiesForAction();
if (entities.length === 0) return false;
- if (!entities.some(copyAction.canExecute)) return false;
+ if (!entities.every(copyAction.canExecute)) return false;
copyAction.executeWithSoup(entities, soup);
return true;
@@ -211,7 +211,7 @@ export const useEntityActionHotkeys = (
condition: () => {
if (condition && !condition()) return false;
const entities = getEntitiesForAction();
- return entities.some(copyAction.canExecute);
+ return entities.length > 0 && entities.every(copyAction.canExecute);
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
@@ -229,7 +229,7 @@ export const useEntityActionHotkeys = (
keyDownHandler: () => {
const entities = getEntitiesForAction();
if (entities.length === 0) return false;
- if (!entities.some(moveToProjectAction.canExecute)) return false;
+ if (!entities.every(moveToProjectAction.canExecute)) return false;
moveToProjectAction.executeWithSoup(entities, soup);
return true;
@@ -237,7 +237,9 @@ export const useEntityActionHotkeys = (
condition: () => {
if (condition && !condition()) return false;
const entities = getEntitiesForAction();
- return entities.some(moveToProjectAction.canExecute);
+ return (
+ entities.length > 0 && entities.every(moveToProjectAction.canExecute)
+ );
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
diff --git a/js/app/packages/app/component/next-soup/filters/inbox-filters.ts b/js/app/packages/app/component/next-soup/filters/inbox-filters.ts
index 36f64931f9..3fb99c45c6 100644
--- a/js/app/packages/app/component/next-soup/filters/inbox-filters.ts
+++ b/js/app/packages/app/component/next-soup/filters/inbox-filters.ts
@@ -154,6 +154,8 @@ export function signalFilter(entity: EntityData): boolean {
return isSignalEmail(entity) || entity.isDraft;
case 'project':
return true;
+ case 'channel_message':
+ return true;
}
}
diff --git a/js/app/packages/app/component/next-soup/filters/predicates.ts b/js/app/packages/app/component/next-soup/filters/predicates.ts
index 09a086d93f..d144a3bb94 100644
--- a/js/app/packages/app/component/next-soup/filters/predicates.ts
+++ b/js/app/packages/app/component/next-soup/filters/predicates.ts
@@ -66,11 +66,17 @@ export function emailFilter(entity: EntityData): boolean {
}
export function peopleFilter(entity: EntityData): boolean {
- return entity.type === 'channel' && entity.channelType === 'direct_message';
+ return (
+ (entity.type === 'channel' || entity.type === 'channel_message') &&
+ entity.channelType === 'direct_message'
+ );
}
export function teamsFilter(entity: EntityData): boolean {
- return entity.type === 'channel' && entity.channelType !== 'direct_message';
+ return (
+ (entity.type === 'channel' || entity.type === 'channel_message') &&
+ entity.channelType !== 'direct_message'
+ );
}
export function agentFilter(entity: EntityData): boolean {
@@ -88,7 +94,7 @@ export function fileFilter(entity: EntityData): boolean {
}
export function channelsFilter(entity: EntityData): boolean {
- return entity.type === 'channel';
+ return entity.type === 'channel' || entity.type === 'channel_message';
}
export function filesAndFolderFilter(entity: EntityData): boolean {
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx
index 9af1293839..b1721da4dc 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-entity-actions-menu.tsx
@@ -1,7 +1,7 @@
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
import { globalSplitManager } from '@app/signal/splitLayout';
import { MenuItem } from '@core/component/Menu';
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { fileTypeToBlockName, itemToBlockName } from '@core/constant/allBlocks';
import type { EntityData } from '@entity';
import {
makeBlockSenderAction,
@@ -21,6 +21,7 @@ import { useUserId } from '@core/context/user';
import { useAnalytics } from '@app/component/analytics-context';
import { Show } from 'solid-js';
import { useSoupView } from './soup-view-context';
+import { getChannelParams } from '@block-channel/utils/link';
const SIGNAL_TABS = new Set<string | undefined>([
undefined,
@@ -70,9 +71,6 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
const markSenderSignalAction = makeMarkSenderSignalAction();
const markSenderNoiseAction = makeMarkSenderNoiseAction();
- const canExecuteAny = (canExecute: (e: EntityData) => boolean) =>
- props.entities.some(canExecute);
-
const canExecuteAll = (canExecute: (e: EntityData) => boolean) =>
props.entities.length > 0 && props.entities.every(canExecute);
@@ -86,12 +84,15 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
const canOpenInSplit = () => {
if (props.entities.length !== 1) return false;
const entity = props.entities[0];
- const splits = globalSplitManager()?.splits;
- if (!splits) return false;
- return !splits().some((split) => split.content.id === entity.id);
+ const splitManager = globalSplitManager();
+ if (!splitManager) return false;
+ const contentId =
+ entity.type === 'channel_message' ? entity.channelId : entity.id;
+ const contentType = itemToBlockName(entity);
+ return !splitManager.getSplitByContent(contentType, contentId);
};
- const openInNewSplit = () => {
+ const openInNewSplit = async () => {
const entity = props.entities[0];
if (!entity) return;
@@ -109,6 +110,25 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
},
referredFrom: 'entity-actions-menu',
});
+ } else if (entity.type === 'channel_message') {
+ splitManager.createNewSplit({
+ content: {
+ type: 'channel',
+ id: entity.channelId,
+ params: getChannelParams(entity.messageId, entity.threadId),
+ },
+ referredFrom: 'entity-actions-menu',
+ });
+
+ const orchestrator = splitManager.getOrchestrator();
+ const handle = await orchestrator.getBlockHandle(
+ entity.channelId,
+ 'channel'
+ );
+
+ await handle?.goToLocationFromParams(
+ getChannelParams(entity.messageId, entity.threadId)
+ );
} else {
splitManager.createNewSplit({
content: {
@@ -121,12 +141,12 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
};
const showTopGroup = () =>
- canExecuteAny(markDone.canExecute) || canOpenInSplit();
+ canExecuteAll(markDone.canExecute) || canOpenInSplit();
const showMiddleGroup = () =>
canExecuteAll(renameAction.canExecute) ||
- canExecuteAny(moveToProjectAction.canExecute) ||
- canExecuteAny(copyAction.canExecute) ||
+ canExecuteAll(moveToProjectAction.canExecute) ||
+ canExecuteAll(copyAction.canExecute) ||
props.entities.length === 1;
const showSenderGroup = () => canExecuteAll(blockSenderAction.canExecute);
@@ -135,7 +155,7 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
return (
<>
- <Show when={canExecuteAny(markDone.canExecute)}>
+ <Show when={canExecuteAll(markDone.canExecute)}>
<MenuItem
text="Mark Done"
onClick={() => handleAction(markDone.executeWithSoup)}
@@ -157,14 +177,14 @@ export const SoupEntityActionsMenu = (props: SoupEntityActionsMenuProps) => {
/>
</Show>
- <Show when={canExecuteAny(moveToProjectAction.canExecute)}>
+ <Show when={canExecuteAll(moveToProjectAction.canExecute)}>
<MenuItem
text="Move to folder"
onClick={() => handleAction(moveToProjectAction.executeWithSoup)}
/>
</Show>
- <Show when={canExecuteAny(copyAction.canExecute)}>
+ <Show when={canExecuteAll(copyAction.canExecute)}>
<MenuItem
text="Duplicate"
onClick={() => handleAction(copyAction.executeWithSoup)}
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
index 9fbe00083a..ba74eb1603 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-context.tsx
@@ -304,7 +304,7 @@ export const SoupViewContextProvider: FlowComponent<
transformed = deduplicateEntities(next);
const sorts = soup.sort.active();
- if (sorts.length > 0) {
+ if (sorts.length > 0 && !search.isSearching()) {
transformed.sort((a, b) => {
for (const sort of sorts) {
const result = sort.fn(a, b);
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index 41e07b2dc8..56128e137f 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -517,6 +517,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
type === 'entity' ? args.entity : args.projectEntity
) as EntityData;
+ // FIXME: this never gets called because we have overrides
if (event.metaKey || event.ctrlKey) {
openEntityInNewTab({ entity, location });
return;
diff --git a/js/app/packages/app/component/next-soup/utils.ts b/js/app/packages/app/component/next-soup/utils.ts
index 6f4603e08e..37f14c22fe 100644
--- a/js/app/packages/app/component/next-soup/utils.ts
+++ b/js/app/packages/app/component/next-soup/utils.ts
@@ -27,6 +27,7 @@ import {
} from '@queries/soup/cache';
import { match } from 'ts-pattern';
import { isAfter } from 'date-fns';
+import { getChannelParams } from '@block-channel/utils/link';
const mergeSearchEntities = <T extends EntityData>(
first: WithSearch<T>,
@@ -154,20 +155,31 @@ export const openEntityInNewTab = ({
const { fileType, subType } = entity;
const blockName = fileTypeToBlockName(subType?.type ?? fileType);
entityPath = `/app/${blockName}/${entity.id}`;
+ } else if (entity.type === 'channel_message') {
+ entityPath = `/app/channel/${entity.channelId}`;
} else {
entityPath = `/app/${entity.type}/${entity.id}`;
}
// Add location params if present
- const entityUrl = new URL(entityPath, window.location.origin);
- if (location) {
+ let entityUrl = new URL(entityPath, window.location.origin);
+
+ if (entity.type === 'channel_message') {
+ entityUrl.searchParams.set(CHANNEL_PARAMS.message, entity.messageId);
+ if (entity.threadId) {
+ entityUrl.searchParams.set(CHANNEL_PARAMS.thread, entity.threadId);
+ }
+ } else if (location) {
switch (location.type) {
case 'channel':
if (location.messageId) {
- entityUrl.searchParams.set('channel_message_id', location.messageId);
+ entityUrl.searchParams.set(
+ CHANNEL_PARAMS.message,
+ location.messageId
+ );
}
if (location.threadId) {
- entityUrl.searchParams.set('thread', location.threadId);
+ entityUrl.searchParams.set(CHANNEL_PARAMS.thread, location.threadId);
}
break;
case 'email':
@@ -287,14 +299,12 @@ export const openEntityInSplitFromUnifiedList = async (
const content = getEntitySplitContent(entity);
- // Build params for channel entities with location
- const params =
- entity.type === 'channel' && location?.type === 'channel'
- ? {
- [CHANNEL_PARAMS.message]: location.messageId,
- [CHANNEL_PARAMS.thread]: location.threadId,
- }
- : undefined;
+ let params: Record<string, string> | undefined;
+ if (entity.type === 'channel' && location?.type === 'channel') {
+ params = getChannelParams(location.messageId, location.threadId);
+ } else if (entity.type === 'channel_message') {
+ params = getChannelParams(entity.messageId, entity.threadId);
+ }
splitManager.openWithSplit(
{ ...content, params },
@@ -308,9 +318,20 @@ export const openEntityInSplitFromUnifiedList = async (
);
// Navigate to specific location if provided
- if (!location) return;
-
- await navigateToLocation(entity.id, location, blockOrchestrator);
+ if (location) {
+ await navigateToLocation(content.id, location, blockOrchestrator);
+ } else if (entity.type === 'channel_message') {
+ // NOTE: This will force target message navigation in case the split is already open.
+ await navigateToLocation(
+ entity.channelId,
+ {
+ type: 'channel',
+ messageId: entity.messageId,
+ threadId: entity.threadId,
+ },
+ blockOrchestrator
+ );
+ }
};
function getEntitySplitContent(entity: EntityData) {
@@ -321,6 +342,9 @@ function getEntitySplitContent(entity: EntityData) {
return { type: blockName, id };
})
+ .with({ type: 'channel_message' }, (entity) => {
+ return { type: 'channel' as const, id: entity.channelId };
+ })
.otherwise((entity) => {
return { type: entity.type, id: entity.id };
});
@@ -340,10 +364,9 @@ async function navigateToLocation(
switch (location.type) {
case 'channel': {
// NOTE: this is handled by the channel block params but this can be used to re-flash an open channel
- await blockHandle.goToLocationFromParams({
- [CHANNEL_PARAMS.thread]: location.threadId,
- [CHANNEL_PARAMS.message]: location.messageId,
- });
+ await blockHandle.goToLocationFromParams(
+ getChannelParams(location.messageId, location.threadId)
+ );
break;
}
case 'email': {
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index c2130ac169..08da63f4ab 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -248,6 +248,12 @@ export type SplitManager = {
*/
reconcile: (splits: SplitContent[]) => void;
+ /** Replace all splits with a single split containing the given content. */
+ replaceAllSplits: (
+ content: SplitContent,
+ options?: { referredFrom?: string | null }
+ ) => SplitHandle;
+
/** Check if a split exists by its split id */
hasSplit: (type: SplitContentType, id: string) => boolean;
@@ -1024,6 +1030,23 @@ export function createSplitLayout(
}
}
+ function replaceAllSplits(
+ content: SplitContent,
+ options: { referredFrom?: ReferredFrom } = {}
+ ): SplitHandle {
+ reconcileSplits([content]);
+ const handle = getSplitByContent(content.type, content.id);
+ if (handle) {
+ handle.activate();
+ return handle;
+ }
+ return createNewSplit({
+ content,
+ activate: true,
+ referredFrom: options.referredFrom ?? null,
+ });
+ }
+
const activeSplit = () => {
const id = state.activeSplitId;
return id ? getSplit(id) : undefined;
@@ -1036,6 +1059,7 @@ export function createSplitLayout(
lastActiveSplitId: () => state.lastActiveSplitId,
events: lastEvent,
reconcile: reconcileSplits,
+ replaceAllSplits,
getSplit,
openWithSplit,
removeSplit,
diff --git a/js/app/packages/block-canvas/component/CanvasController.tsx b/js/app/packages/block-canvas/component/CanvasController.tsx
index 0a3227107b..e05f8363dc 100644
--- a/js/app/packages/block-canvas/component/CanvasController.tsx
+++ b/js/app/packages/block-canvas/component/CanvasController.tsx
@@ -861,6 +861,8 @@ export function CanvasController(props: ParentProps) {
if (!event.droppable) return;
const entityType = event.draggable.data.type;
+ // TODO: add channel message support
+ if (entityType === 'channel_message') return;
// Track document mention and get UUID
let mentionUuid: string | undefined;
diff --git a/js/app/packages/block-channel/component/ChannelBlockSwitch.tsx b/js/app/packages/block-channel/component/ChannelBlockSwitch.tsx
index 485d206472..3d4b25feef 100644
--- a/js/app/packages/block-channel/component/ChannelBlockSwitch.tsx
+++ b/js/app/packages/block-channel/component/ChannelBlockSwitch.tsx
@@ -11,7 +11,7 @@ export function ChannelBlockSwitch(props: BlockChannelProps) {
enabledOverride={ENABLE_NEW_CHANNELS()}
fallback={<BlockChannel {...props} />}
>
- <NewChannelBlockAdapter />
+ <NewChannelBlockAdapter {...props} />
</ShowFeatureFlag>
);
}
diff --git a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx
index ca3e3ef5f8..d45587954f 100644
--- a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx
+++ b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx
@@ -1,6 +1,7 @@
import {
Channel as NewChannel,
type ChannelHandle,
+ type ChannelProps,
} from '@channel/Channel/Channel';
import { ChannelTopBarLiveIndicators } from '@channel/Channel/ChannelTopBarLiveIndicators';
import { useBlockId } from '@core/block';
@@ -23,6 +24,17 @@ import { ChannelAttachmentsTab } from '@channel/Attachments/ChannelAttachmentsTa
import { ChannelParticipantsTab } from '@channel/Participants/ChannelParticipantsTab';
import { ChannelDebouncedNotificationReadMarker } from '@notifications/components/DebouncedNotificationReadMarker';
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
+import type { BlockChannelProps } from './Block';
+
+type ChannelTargetMessageParams = {
+ [URL_PARAMS.message]?: string;
+ [URL_PARAMS.thread]?: string;
+};
+
+type ChannelPropsTargetMessage = Pick<
+ ChannelProps,
+ 'targetMessageId' | 'targetMessageReplyId'
+>;
function NewTop(props: {
channelId: string;
@@ -55,7 +67,7 @@ function NewTop(props: {
);
}
-export function NewChannelBlockAdapter() {
+export function NewChannelBlockAdapter(props: BlockChannelProps) {
useBlockEntityCommands();
const notificationSource = useGlobalNotificationSource();
@@ -65,21 +77,33 @@ export function NewChannelBlockAdapter() {
const [activeTab, setActiveTab] =
createSignal<ChannelTabId>(DEFAULT_CHANNEL_TAB);
+ const convertTargetMessage = (
+ params: ChannelTargetMessageParams
+ ): ChannelPropsTargetMessage => {
+ const messageId = params[URL_PARAMS.message] as string | undefined;
+ const threadId = params[URL_PARAMS.thread] as string | undefined;
+
+ // For compatibility the naming is a little strange here.
+ // New channels index by top level message and then separately handle replies.
+ // If we have a threadId that is actually the top level message and the reply is the message id.
+ const topLevelMessageId = threadId ? threadId : messageId;
+ const messageReplyId = threadId ? messageId : threadId;
+
+ return {
+ targetMessageId: topLevelMessageId,
+ targetMessageReplyId: messageReplyId,
+ };
+ };
+
const onChannelReady = (handle: ChannelHandle) => {
createMethodRegistration(blockHandle, {
- goToLocationFromParams: async (params: Record<string, unknown>) => {
- const threadId = params[URL_PARAMS.thread] as string | undefined;
- const messageId = params[URL_PARAMS.message] as string | undefined;
-
- // For compatibility the naming is a little strange here.
- // New channels index by top level message and then spertately handle replies.
- // If we have a threadId that is actually the top level message and the reply is the message id.
- const topLevelMessageId = threadId ? threadId : messageId;
- const messageReplyId = threadId ? messageId : threadId;
+ goToLocationFromParams: async (params: ChannelTargetMessageParams) => {
+ const { targetMessageId, targetMessageReplyId } =
+ convertTargetMessage(params);
- if (topLevelMessageId && handle) {
+ if (targetMessageId && handle) {
setActiveTab(DEFAULT_CHANNEL_TAB);
- handle.goToMessage(topLevelMessageId, messageReplyId);
+ handle.goToMessage(targetMessageId, targetMessageReplyId);
}
},
});
@@ -95,7 +119,11 @@ export function NewChannelBlockAdapter() {
<div class="relative h-full flex flex-col">
<Switch>
<Match when={activeTab() === 'messages'}>
- <NewChannel channelId={channelId} onHandleReady={onChannelReady} />
+ <NewChannel
+ channelId={channelId}
+ onHandleReady={onChannelReady}
+ {...convertTargetMessage(props)}
+ />
</Match>
<Match when={activeTab() === 'attachments'}>
<ChannelAttachmentsTab channelId={channelId} />
diff --git a/js/app/packages/block-channel/component/Top.tsx b/js/app/packages/block-channel/component/Top.tsx
index 81f2b8c2e5..32ce764099 100644
--- a/js/app/packages/block-channel/component/Top.tsx
+++ b/js/app/packages/block-channel/component/Top.tsx
@@ -132,13 +132,10 @@ export function Top(props: TopProps) {
function handleCopyLink() {
navigator.clipboard.writeText(
- buildSimpleEntityUrl(
- {
- type: 'channel',
- id: blockId,
- },
- {}
- )
+ buildSimpleEntityUrl({
+ type: 'channel',
+ id: blockId,
+ })
);
toast.success('Link copied to clipboard');
}
diff --git a/js/app/packages/block-channel/utils/link.ts b/js/app/packages/block-channel/utils/link.ts
index c761a6ef7a..7baafd70eb 100644
--- a/js/app/packages/block-channel/utils/link.ts
+++ b/js/app/packages/block-channel/utils/link.ts
@@ -1,5 +1,19 @@
import { URL_PARAMS } from '@block-channel/constants';
+export function getChannelParams(
+ messageId: string,
+ threadId?: string
+): Record<string, string> {
+ const params: Record<string, string> = {};
+ params[URL_PARAMS.message] = messageId;
+
+ if (threadId) {
+ params[URL_PARAMS.thread] = threadId;
+ }
+
+ return params;
+}
+
export function getUrlToMessage(
channelId: string,
messageId: string,
diff --git a/js/app/packages/block-chat/client.ts b/js/app/packages/block-chat/client.ts
index 4a98b3d382..f91377c8dd 100644
--- a/js/app/packages/block-chat/client.ts
+++ b/js/app/packages/block-chat/client.ts
@@ -2,8 +2,6 @@ import type { BlockName } from '@core/block';
import { usePaywallState } from '@core/constant/PaywallState';
import { isPaymentError } from '@core/util/handlePaymentError';
import { isErr } from '@core/util/maybeResult';
-import { propsToHref } from '@core/util/url';
-import { postNewHistoryItem } from '@queries/history/history';
import { cognitionApiServiceClient } from '@service-cognition/client';
export function useOpenChatForAttachment() {
@@ -55,25 +53,3 @@ export function useOpenChatForAttachment() {
}
};
}
-
-export async function copyChat(args: { id: string; name: string }) {
- const { showPaywall } = usePaywallState();
- const result = await cognitionApiServiceClient.copyChat({
- chat_id: args.id,
- name: args.name,
- });
- if (isPaymentError(result)) {
- showPaywall();
- throw result[0];
- }
- if (isErr(result)) {
- throw result[0];
- }
- const [_, { id }] = result;
- postNewHistoryItem('chat', id);
- const href = propsToHref({
- id,
- fileType: 'chat',
- });
- return { id, href };
-}
diff --git a/js/app/packages/block-chat/component/Block.tsx b/js/app/packages/block-chat/component/Block.tsx
index 8d44c8bdfc..b5b23f5f31 100644
--- a/js/app/packages/block-chat/component/Block.tsx
+++ b/js/app/packages/block-chat/component/Block.tsx
@@ -18,11 +18,11 @@ export default function ChatBlock() {
return (
<DocumentBlockContainer title={name()}>
- <DebouncedNotificationReadMarker
- notificationSource={notificationSource}
- entity={{ type: 'chat', id: blockId }}
- />
<div class="size-full bracket-never" tabIndex={-1}>
+ <DebouncedNotificationReadMarker
+ notificationSource={notificationSource}
+ entity={{ type: 'chat', id: blockId }}
+ />
<ModalsProvider>
<Show when={chatBlockData()}>{(data) => <Chat data={data()} />}</Show>
</ModalsProvider>
diff --git a/js/app/packages/block-md/component/ComposeTask.tsx b/js/app/packages/block-md/component/ComposeTask.tsx
index eaa17fa7e0..08f3c87873 100644
--- a/js/app/packages/block-md/component/ComposeTask.tsx
+++ b/js/app/packages/block-md/component/ComposeTask.tsx
@@ -335,7 +335,7 @@ export function ComposeTask(props: ComposeTaskProps) {
);
// Auto-copy link to clipboard
- const url = buildSimpleEntityUrl({ type: 'task', id: documentId }, {});
+ const url = buildSimpleEntityUrl({ type: 'task', id: documentId });
let linkCopied = false;
try {
await navigator.clipboard.writeText(url);
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index f0a1fac219..b578e5d66b 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -180,6 +180,7 @@ import { MarkdownPopup } from './MarkdownPopup';
import { isMobile } from '@core/mobile/isMobile';
import { isIOS } from '@solid-primitives/platform';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
false && fileFolderDrop;
@@ -315,8 +316,12 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {
const item = event.draggable.data;
const blockName = fileTypeToBlockName(item.fileType ?? item.type);
if (!blockName) return;
+ let id = event.draggable.data.id as string;
+ if (event.draggable.data.type === 'channel_message') {
+ id = event.draggable.data.channelId;
+ }
return {
- id: event.draggable.data.id as string,
+ id,
blockName: blockName as BlockName,
mousePos,
item,
@@ -347,10 +352,21 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {
const mentionId = await trackMention(blockId, 'document', res.id);
editor.update(() => {
+ let blockParams: Record<string, string> | undefined;
+ if (res.blockName === 'channel') {
+ blockParams = {};
+ if (res.item.messageId) {
+ blockParams[CHANNEL_PARAMS.message] = res.item.messageId;
+ }
+ if (res.item.threadId) {
+ blockParams[CHANNEL_PARAMS.thread] = res.item.threadId;
+ }
+ }
const mention = $createDocumentMentionNode({
documentId: res.id,
documentName: res.item.name,
blockName: res.blockName,
+ blockParams,
mentionUuid: mentionId,
});
diff --git a/js/app/packages/block-md/component/TopBar.tsx b/js/app/packages/block-md/component/TopBar.tsx
index eaf1f64dfc..c14d227a6f 100644
--- a/js/app/packages/block-md/component/TopBar.tsx
+++ b/js/app/packages/block-md/component/TopBar.tsx
@@ -90,10 +90,7 @@ export function TopBar() {
const isTask = blockAliasedName === 'task';
const copyLink = () => {
- const url = buildSimpleEntityUrl(
- { id: blockId, type: blockAliasedName },
- {}
- );
+ const url = buildSimpleEntityUrl({ id: blockId, type: blockAliasedName });
navigator.clipboard.writeText(url);
toast.success(
'Link copied to clipboard.',
diff --git a/js/app/packages/block-project/component/TopBar.tsx b/js/app/packages/block-project/component/TopBar.tsx
index 1ff9f003b3..b27364465f 100644
--- a/js/app/packages/block-project/component/TopBar.tsx
+++ b/js/app/packages/block-project/component/TopBar.tsx
@@ -61,13 +61,10 @@ export function TopBar() {
function handleCopyLink() {
navigator.clipboard.writeText(
- buildSimpleEntityUrl(
- {
- type: 'project',
- id,
- },
- {}
- )
+ buildSimpleEntityUrl({
+ type: 'project',
+ id,
+ })
);
toast.success('Link copied to clipboard');
}
diff --git a/js/app/packages/channel/Attachments/attachment-utils.ts b/js/app/packages/channel/Attachments/attachment-utils.ts
index 8f0c4a1a37..9d199e7fce 100644
--- a/js/app/packages/channel/Attachments/attachment-utils.ts
+++ b/js/app/packages/channel/Attachments/attachment-utils.ts
@@ -3,6 +3,8 @@ import { stringToItemType } from '@service-storage/client';
import type { EntityData } from '@entity';
import { match } from 'ts-pattern';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import type { SplitContent } from '@app/component/split-layout/layoutManager';
+import { getChannelParams } from '@channel/Channel/link';
/** size-23 = 92px */
export const THUMB_SIZE = 92;
@@ -70,7 +72,7 @@ export function buildAttachmentEntityFilters(
};
}
-export function getEntityClickContent(entity: EntityData) {
+export function getEntityClickContent(entity: EntityData): SplitContent {
return match(entity)
.with({ type: 'document' }, (e) => ({
type: fileTypeToBlockName(e.subType?.type ?? e.fileType),
@@ -86,5 +88,10 @@ export function getEntityClickContent(entity: EntityData) {
type: 'project' as const,
id: e.id,
}))
+ .with({ type: 'channel_message' }, (e) => ({
+ type: 'channel' as const,
+ id: e.channelId,
+ params: getChannelParams(e.messageId, e.threadId),
+ }))
.exhaustive();
}
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index 2ad33cdad4..bf398c46d7 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -79,7 +79,7 @@ import {
scrollReplyInputIntoView,
} from '../scroll-utils';
-type ChannelProps = {
+export type ChannelProps = {
channelId: string;
targetMessageId?: string | undefined;
targetMessageReplyId?: string | undefined;
diff --git a/js/app/packages/channel/Channel/create-channel-message-actions.ts b/js/app/packages/channel/Channel/create-channel-message-actions.ts
index 1571241c3d..ba762a66f6 100644
--- a/js/app/packages/channel/Channel/create-channel-message-actions.ts
+++ b/js/app/packages/channel/Channel/create-channel-message-actions.ts
@@ -138,7 +138,12 @@ export function createChannelMessageActions(
: undefined,
onCopyLink: async () => {
try {
- const url = buildMessageLink(effects.getLocationHref(), message.id);
+ const channelId = options.channelId();
+ const url = buildMessageLink(
+ channelId,
+ message.id,
+ message.thread_id
+ );
await effects.copyToClipboard(url);
effects.notifyCopyLinkSuccess();
} catch (error) {
diff --git a/js/app/packages/channel/Channel/link.ts b/js/app/packages/channel/Channel/link.ts
new file mode 100644
index 0000000000..9407920ce5
--- /dev/null
+++ b/js/app/packages/channel/Channel/link.ts
@@ -0,0 +1,23 @@
+// These constants intentionally duplicate block-channel/constants.ts and
+// block-channel/utils/link.ts. The `channel` package is being migrated to
+// replace `block-channel`, and we don't want `channel` to import from
+// `block-channel` to keep the import tree clean during the transition.
+
+export const URL_PARAMS = {
+ thread: 'channel_thread_id',
+ message: 'channel_message_id',
+};
+
+export function getChannelParams(
+ messageId: string,
+ threadId?: string | null
+): Record<string, string> {
+ const params: Record<string, string> = {};
+ params[URL_PARAMS.message] = messageId;
+
+ if (threadId) {
+ params[URL_PARAMS.thread] = threadId;
+ }
+
+ return params;
+}
diff --git a/js/app/packages/channel/Message/types.ts b/js/app/packages/channel/Message/types.ts
index 7d71f79421..2a00b17e77 100644
--- a/js/app/packages/channel/Message/types.ts
+++ b/js/app/packages/channel/Message/types.ts
@@ -9,6 +9,7 @@ export type MessageData = {
updated_at: string;
deleted_at?: string | null;
edited_at?: string | null;
+ thread_id?: string | null;
attachments: ApiMessageAttachment[];
reactions: ApiCountedReaction[];
};
diff --git a/js/app/packages/channel/Thread/tests/message-actions.test.ts b/js/app/packages/channel/Thread/tests/message-actions.test.ts
index b15088e9af..e505a0edaf 100644
--- a/js/app/packages/channel/Thread/tests/message-actions.test.ts
+++ b/js/app/packages/channel/Thread/tests/message-actions.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest';
+import { URL_PARAMS } from '@channel/Channel/link';
import {
buildMessageLink,
canEditOrDeleteMessage,
@@ -58,13 +59,19 @@ describe('message-actions helpers', () => {
);
});
- it('builds message links with targetMessageId and hash', () => {
- const url = buildMessageLink(
- 'https://example.com/app/component/unified-list?foo=bar',
- 'msg-123'
+ it('builds message links with channel_message_id param', () => {
+ const parsed = new URL(buildMessageLink('channel-123', 'msg-123'));
+ expect(parsed.pathname).toBe('/app/channel/channel-123');
+ expect(parsed.searchParams.get(URL_PARAMS.message)).toBe('msg-123');
+ expect(parsed.searchParams.has(URL_PARAMS.thread)).toBe(false);
+ });
+
+ it('builds message links with thread param', () => {
+ const parsed = new URL(
+ buildMessageLink('channel-123', 'msg-123', 'thread-456')
);
- expect(url).toContain('foo=bar');
- expect(url).toContain('targetMessageId=msg-123');
- expect(url).toContain('#message-msg-123');
+ expect(parsed.pathname).toBe('/app/channel/channel-123');
+ expect(parsed.searchParams.get(URL_PARAMS.message)).toBe('msg-123');
+ expect(parsed.searchParams.get(URL_PARAMS.thread)).toBe('thread-456');
});
});
diff --git a/js/app/packages/channel/Thread/utils/message-actions.ts b/js/app/packages/channel/Thread/utils/message-actions.ts
index 67b4a5bbc5..e9fa8bbc4c 100644
--- a/js/app/packages/channel/Thread/utils/message-actions.ts
+++ b/js/app/packages/channel/Thread/utils/message-actions.ts
@@ -1,4 +1,6 @@
+import { buildSimpleEntityUrl } from '@core/util/url';
import type { MessageData } from '../../Message';
+import { getChannelParams } from '@channel/Channel/link';
export const DEFAULT_REACTION_EMOJI = '👍';
@@ -41,9 +43,11 @@ export function hasReactionFromUser(
);
}
-export function buildMessageLink(baseHref: string, messageId: string): string {
- const url = new URL(baseHref);
- url.searchParams.set('targetMessageId', messageId);
- url.hash = `message-${messageId}`;
- return url.toString();
+export function buildMessageLink(
+ channelId: string,
+ messageId: string,
+ threadId?: string | null
+): string {
+ const params = getChannelParams(messageId, threadId);
+ return buildSimpleEntityUrl({ type: 'channel', id: channelId }, params);
}
diff --git a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx b/js/app/packages/core/component/AI/component/message/ChatMessages.tsx
index 45947f6ea7..05050eeae3 100644
--- a/js/app/packages/core/component/AI/component/message/ChatMessages.tsx
+++ b/js/app/packages/core/component/AI/component/message/ChatMessages.tsx
@@ -90,7 +90,6 @@ export function ChatMessages(props: ChatMessagesProps) {
const isStream = () => {
const s = stream();
- console.log('isStream', Boolean(s));
if (!s) return false;
return !s.isDone();
};
diff --git a/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts b/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts
index fd9c7a6789..fe6b55c147 100644
--- a/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts
+++ b/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts
@@ -1,4 +1,4 @@
-import { match } from 'ts-pattern';
+import { match, P } from 'ts-pattern';
import { SUPPORTED_CHAT_ATTACHMENT_BLOCKS } from '@core/component/AI/constant';
import type { Attachment, Attachments } from '@core/component/AI/types';
import { asFileType } from '@core/component/AI/util';
@@ -98,13 +98,16 @@ export function useEntityDropAttachment(
},
} satisfies Attachment;
})
- .with('channel', () => {
+ .with(P.union('channel', 'channel_message'), () => {
const channelType =
'channelType' in data ? data.channelType : 'organization';
+ const channelId =
+ 'channelId' in data ? (data.channelId as string) : entityId;
+ // TODO: channel_message attachments only reference the full channel, not the message
return {
- id: `${entityId}-channel-attachment`,
- attachmentId: entityId,
+ id: `${channelId}-channel-attachment`,
+ attachmentId: channelId,
attachmentType: 'channel' satisfies AttachmentType,
metadata: {
type: 'channel',
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index ab6ae101b7..8412285f21 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -1,6 +1,6 @@
// URL params constants
import { URL_PARAMS as URL_PARAMS_CANVAS } from '@block-canvas/constants';
-import { URL_PARAMS as URL_PARAMS_CHANNEL } from '@block-channel/constants';
+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { useOpenChatForAttachment } from '@block-chat/client';
import { URL_PARAMS as URL_PARAMS_MD } from '@block-md/constants';
import { URL_PARAMS as URL_PARAMS_PDF } from '@block-pdf/signal/location';
@@ -170,8 +170,8 @@ export const mentionsAccessories = (
}
// Channel block handling
else if (blockName === 'channel') {
- const threadId = params[URL_PARAMS_CHANNEL.thread];
- const messageId = params[URL_PARAMS_CHANNEL.message];
+ const threadId = params[CHANNEL_PARAMS.thread];
+ const messageId = params[CHANNEL_PARAMS.message];
if (threadId) {
return {
icon: 'thread',
@@ -211,7 +211,10 @@ function PopupIconButton(props: {
return (
<Tooltip tooltip={props.tooltip}>
<button
- onClick={props.onClick}
+ onClick={(e) => {
+ e.stopPropagation();
+ props.onClick();
+ }}
class="rounded-md py-1 hover:bg-hover transition flex items-center gap-1.5"
>
<div class="w-fit flex justify-right items-center mx-0.5 my-0.5 text-xs font-normal text-current/90">
@@ -381,9 +384,9 @@ export function PopupPreview(props: {
let messageId: string | undefined;
if (
type === 'channel' &&
- URL_PARAMS_CHANNEL.message in props.documentInfo.params
+ CHANNEL_PARAMS.message in props.documentInfo.params
) {
- messageId = props.documentInfo.params[URL_PARAMS_CHANNEL.message];
+ messageId = props.documentInfo.params[CHANNEL_PARAMS.message];
}
return { id: props.documentInfo.id, type, messageId };
};
@@ -411,18 +414,29 @@ export function PopupPreview(props: {
props.collapseInfo?.handleCollapse();
};
- const openDocument = createCallback(() => {
- let link = `/${props.documentInfo.type}/${props.documentInfo.id}`;
- if (props.documentInfo.params) {
- const queryParams = new URLSearchParams(
- props.documentInfo.params
- ).toString();
- link += `?${queryParams}`;
+ const openDocument = createCallback(async () => {
+ const splitManager = globalSplitManager();
+ if (!splitManager) {
+ console.warn('No split manager found');
+ let link = `/${props.documentInfo.type}/${props.documentInfo.id}`;
+ if (props.documentInfo.params) {
+ const queryParams = new URLSearchParams(
+ props.documentInfo.params
+ ).toString();
+ link += `?${queryParams}`;
+ }
+ navigate(link);
+ return;
}
- navigate(`${link}`);
+
+ splitManager.replaceAllSplits({
+ type: props.documentInfo.type,
+ id: props.documentInfo.id,
+ params: props.documentInfo.params,
+ });
});
- // Handle opening document in chat
+ // H opening document in chat
const openChatForAttachment = useOpenChatForAttachment();
const handleOpenInChat = () => {
openChatForAttachment({
@@ -465,9 +479,26 @@ export function PopupPreview(props: {
copyBranchNameToClipboard(props.documentInfo.id, docName);
};
- const openInNewSplit = createCallback(() => {
+ const isSplitAlreadyOpen = () => {
+ const splitManager = globalSplitManager();
+ if (!splitManager) return false;
+ return !!splitManager.getSplitByContent(
+ props.documentInfo.type,
+ props.documentInfo.id
+ );
+ };
+
+ const openInNewSplit = createCallback(async () => {
const splitManager = globalSplitManager();
- if (splitManager) {
+ if (!splitManager) return;
+
+ const existing = splitManager.getSplitByContent(
+ props.documentInfo.type,
+ props.documentInfo.id
+ );
+ if (existing) {
+ existing.activate();
+ } else {
splitManager.createNewSplit({
content: {
type: props.documentInfo.type,
@@ -477,6 +508,16 @@ export function PopupPreview(props: {
referredFrom: null,
});
}
+
+ if (props.documentInfo.type !== 'channel') return;
+
+ const orchestrator = splitManager.getOrchestrator();
+ const handle = await orchestrator.getBlockHandle(
+ props.documentInfo.id,
+ 'channel'
+ );
+
+ await handle?.goToLocationFromParams(props.documentInfo.params);
});
/**
@@ -565,13 +606,15 @@ export function PopupPreview(props: {
/>
);
- buttons.push(
- <PopupIconButton
- tooltip="Open in New Split"
- onClick={openInNewSplit}
- icon={ColumnsPlusRight}
- />
- );
+ if (!isSplitAlreadyOpen()) {
+ buttons.push(
+ <PopupIconButton
+ tooltip="Open in New Split"
+ onClick={openInNewSplit}
+ icon={ColumnsPlusRight}
+ />
+ );
+ }
}
if (props.delete) {
diff --git a/js/app/packages/core/component/EntityIcon.tsx b/js/app/packages/core/component/EntityIcon.tsx
index f23901f743..f0610d46c2 100644
--- a/js/app/packages/core/component/EntityIcon.tsx
+++ b/js/app/packages/core/component/EntityIcon.tsx
@@ -428,6 +428,7 @@ type EntityIconData = Pick<EntityData, 'type'> & {
export function getEntityIconType(entity: EntityIconData): EntityWithValidIcon {
const typeString = match(entity)
.with({ type: 'channel' }, (e) => e.channelType || 'channel')
+ .with({ type: 'channel_message' }, (e) => e.channelType || 'channel')
.with({ type: 'document' }, (e) => itemToBlockName(e, true) ?? 'default')
.with({ type: 'email', isRead: true }, () => 'emailRead')
.with({ type: 'email' }, () => 'email')
diff --git a/js/app/packages/core/component/FileList/itemOperations.ts b/js/app/packages/core/component/FileList/itemOperations.ts
index ace9c884f3..a3ca650042 100644
--- a/js/app/packages/core/component/FileList/itemOperations.ts
+++ b/js/app/packages/core/component/FileList/itemOperations.ts
@@ -159,8 +159,12 @@ export async function deleteItem(args: {
return false;
}
} else {
- if (itemType === 'channel') return false;
- if (itemType === 'email') return false;
+ if (
+ itemType === 'channel' ||
+ itemType === 'email' ||
+ itemType === 'channel_message'
+ )
+ return false;
const removed = await removeHistoryItem(itemType, id);
if (!removed) return false;
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
index 2f4bc571b3..ddd5a10392 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
@@ -17,7 +17,7 @@ import {
verifyBlockName,
} from '@core/constant/allBlocks';
import { ENABLE_BLOCK_IN_BLOCK } from '@core/constant/featureFlags';
-import { URL_PARAMS as CHANNEL_URL_PARAMS } from '@block-channel/constants';
+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { canNestBlock } from '@core/orchestrator';
import {
isAccessiblePreviewItem,
@@ -303,11 +303,11 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
if (
previewType === 'channel' &&
props.blockParams &&
- CHANNEL_URL_PARAMS.message in props.blockParams
+ CHANNEL_PARAMS.message in props.blockParams
) {
return {
...baseEntity,
- messageId: props.blockParams[CHANNEL_URL_PARAMS.message],
+ messageId: props.blockParams[CHANNEL_PARAMS.message],
};
}
return baseEntity;
diff --git a/js/app/packages/core/component/LexicalMarkdown/theme.ts b/js/app/packages/core/component/LexicalMarkdown/theme.ts
index 8f76544e12..5aab6b8755 100644
--- a/js/app/packages/core/component/LexicalMarkdown/theme.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/theme.ts
@@ -228,6 +228,12 @@ export const searchContentHitMarkdownTheme = createTheme({
root: `${theme.root} pr-[2px] cursor-default overflow-x-auto`,
});
+export const singleLineMarkdownTheme = createTheme({
+ ...unifiedListMarkdownTheme,
+ root: `${theme.root} pr-[2px] cursor-default overflow-hidden truncate`,
+ paragraph: 'md-p text-[1em] truncate',
+});
+
export const twoLineClampMarkdownTheme = createTheme({
...unifiedListMarkdownTheme,
root: `${theme.root} pr-[2px] cursor-default`,
diff --git a/js/app/packages/core/component/NewMessage.tsx b/js/app/packages/core/component/NewMessage.tsx
index f82d757556..0733847413 100644
--- a/js/app/packages/core/component/NewMessage.tsx
+++ b/js/app/packages/core/component/NewMessage.tsx
@@ -50,13 +50,10 @@ function CopyLinkButton() {
function handleCopyLink() {
navigator.clipboard.writeText(
- buildSimpleEntityUrl(
- {
- type: blockName,
- id: blockId,
- },
- {}
- )
+ buildSimpleEntityUrl({
+ type: blockName,
+ id: blockId,
+ })
);
toast.success('Link copied to clipboard');
}
diff --git a/js/app/packages/core/component/Properties/hooks/usePropertyEntityDisplay.tsx b/js/app/packages/core/component/Properties/hooks/usePropertyEntityDisplay.tsx
index a588acd8cc..22d1028c19 100644
--- a/js/app/packages/core/component/Properties/hooks/usePropertyEntityDisplay.tsx
+++ b/js/app/packages/core/component/Properties/hooks/usePropertyEntityDisplay.tsx
@@ -8,6 +8,7 @@ import type { EntityType } from '@service-properties/generated/schemas/entityTyp
import { type Accessor, createMemo, type JSX } from 'solid-js';
import { entityTypeToItemType } from '../utils';
import { match } from 'ts-pattern';
+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
const PREVIEWABLE_ENTITY_TYPES: EntityType[] = [
'DOCUMENT',
@@ -164,7 +165,7 @@ export function usePropertyEntityDisplay(
return match(entityType())
.with('THREAD', () => ({ email_message_id: messageId }))
- .with('CHANNEL', () => ({ channel_message_id: messageId }))
+ .with('CHANNEL', () => ({ [CHANNEL_PARAMS.message]: messageId }))
.with('CHAT', () => ({ message_id: messageId }))
.otherwise(() => undefined);
});
diff --git a/js/app/packages/core/component/Properties/utils/entityConversion.ts b/js/app/packages/core/component/Properties/utils/entityConversion.ts
index 5cd7d9d4f8..c3fc80a2c1 100644
--- a/js/app/packages/core/component/Properties/utils/entityConversion.ts
+++ b/js/app/packages/core/component/Properties/utils/entityConversion.ts
@@ -71,5 +71,6 @@ export function macroEntityToPropertyEntityType(
.with({ type: 'project' }, () => EntityType.PROJECT)
.with({ type: 'email' }, () => EntityType.THREAD)
.with({ type: 'document' }, () => EntityType.DOCUMENT)
+ .with({ type: 'channel_message' }, () => EntityType.CHANNEL)
.exhaustive();
}
diff --git a/js/app/packages/core/component/References.tsx b/js/app/packages/core/component/References.tsx
index 3bd3e727af..72478e96cb 100644
--- a/js/app/packages/core/component/References.tsx
+++ b/js/app/packages/core/component/References.tsx
@@ -19,8 +19,8 @@ import { createMemo, createResource, For, Show } from 'solid-js';
import { InlineItemPreview } from './ItemPreview';
import { StaticMarkdown } from './LexicalMarkdown/component/core/StaticMarkdown';
import { UserIcon } from './UserIcon';
-import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { compareDateDesc, type DateValue } from '@core/util/date';
+import { getChannelParams } from '@block-channel/utils/link';
export type ReferenceProps = {
documentId: string;
@@ -30,6 +30,7 @@ export type ReferenceProps = {
function isChannelReference(ref: EntityReference): ref is EntityReference & {
channel_id: string;
message_id: string;
+ thread_id?: string;
sender_id: string;
attachment_created_at: string;
message_content?: string;
@@ -80,16 +81,15 @@ export function References(props: ReferenceProps) {
const { openWithSplit } = useSplitLayout();
const blockOrchestrator = useGlobalBlockOrchestrator();
- const messageLocation = async (
+ const goToMessageLocation = async (
channelId: string,
messageId: string,
threadId?: string
) => {
const blockHandle = await blockOrchestrator.getBlockHandle(channelId);
- await blockHandle?.goToLocationFromParams({
- [CHANNEL_PARAMS.message]: messageId,
- [CHANNEL_PARAMS.thread]: threadId,
- });
+ await blockHandle?.goToLocationFromParams(
+ getChannelParams(messageId, threadId)
+ );
};
const navigateToItem = ({
@@ -123,7 +123,7 @@ export function References(props: ReferenceProps) {
blockName: 'channel',
blockId: channelId,
});
- messageLocation(channelId, messageId, threadId);
+ goToMessageLocation(channelId, messageId, threadId);
};
const navigateToGenericReference = (
@@ -190,6 +190,7 @@ export function References(props: ReferenceProps) {
event: e,
channelId: ref.channel_id,
messageId: ref.message_id,
+ threadId: ref.thread_id,
})
);
diff --git a/js/app/packages/core/component/TopBar/ShareButton.tsx b/js/app/packages/core/component/TopBar/ShareButton.tsx
index 188126720a..a753697065 100644
--- a/js/app/packages/core/component/TopBar/ShareButton.tsx
+++ b/js/app/packages/core/component/TopBar/ShareButton.tsx
@@ -914,7 +914,7 @@ export function ShareTrigger(props: { copyLink?: () => void }) {
if (code) {
params.referral_code = code;
}
- return buildSimpleEntityUrl({ id: blockId ?? '', type: blockType }, params);
+ return buildSimpleEntityUrl({ id: blockId, type: blockType }, params);
};
const copyLink = createCallback(() => {
diff --git a/js/app/packages/core/constant/allBlocks.ts b/js/app/packages/core/constant/allBlocks.ts
index 4e11519ff7..adbeb32eb3 100644
--- a/js/app/packages/core/constant/allBlocks.ts
+++ b/js/app/packages/core/constant/allBlocks.ts
@@ -157,6 +157,8 @@ export function fileTypeToBlockName(
): BlockName | BlockAlias {
if (!blockOrFiletype) return 'unknown';
+ if (blockOrFiletype === 'channel_message') return 'channel';
+
if (ENABLE_DOCX_TO_PDF) {
if (blockOrFiletype === 'docx' || blockOrFiletype === 'write') {
return icon ? 'write' : 'pdf';
@@ -218,12 +220,12 @@ type ItemLike = {
* itemToBlockName({ type: 'document', fileType: 'py' }) // 'code'
* itemToBlockName({ type: 'document', fileType: 'md', subType: { type: 'task', is_completed: false } }) // 'task'
* itemToBlockName({ type: 'chat' }) // 'chat'
- * @return The block name or undefined if there is no appropriate block.
+ * @return The block name
*/
export function itemToBlockName(
item: ItemLike,
icon?: boolean
-): BlockName | BlockAlias | undefined {
+): BlockName | BlockAlias {
const subTypeName =
item.subType && 'type' in item.subType
? (item.subType.type as string)
@@ -242,11 +244,10 @@ export function itemToBlockName(
* aliases.
* @example
* itemToBlockName({ type: 'document', fileType: 'md', subType: 'task' }) // 'md'
- * @return The block name or undefined if there is no appropriate block.
+ * @return The block name
*/
export function itemToResolvedBlockName(item: ItemLike) {
const maybeAliased = itemToBlockName(item);
- if (!maybeAliased) return;
return resolveBlockAlias(maybeAliased);
}
diff --git a/js/app/packages/core/types/index.ts b/js/app/packages/core/types/index.ts
index 1e3b0ca4a2..89c75df700 100644
--- a/js/app/packages/core/types/index.ts
+++ b/js/app/packages/core/types/index.ts
@@ -4,6 +4,7 @@ import { EntityType as BaseEntityType } from '@service-connection/generated/sche
export const EntityType = {
...BaseEntityType,
email: 'email',
+ channel_message: 'channel_message',
} as const;
export type EntityType = (typeof EntityType)[keyof typeof EntityType];
diff --git a/js/app/packages/core/util/url.ts b/js/app/packages/core/util/url.ts
index b212747667..26c7ca848c 100644
--- a/js/app/packages/core/util/url.ts
+++ b/js/app/packages/core/util/url.ts
@@ -1,6 +1,6 @@
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
import shortuuid from 'short-uuid';
import { getWebOrigin } from './webOrigin';
+
const short = shortuuid(shortuuid.constants.flickrBase58, {
consistentLength: false,
});
@@ -27,20 +27,16 @@ export function transformShortIdInUrlPathname(pathname: string) {
return newPathname;
}
-export function propsToHref(props: { fileType?: string | null; id: string }) {
- const id = props.id;
- const blockName = fileTypeToBlockName(props.fileType);
- return `/${blockName}/${id}`;
-}
-
export function buildSimpleEntityUrl(
entity: { type: string; id: string },
- params: Record<string, any>
+ params?: Record<string, string>
): string {
const urlString = `${getWebOrigin()}/app/${entity.type}/${entity.id}`;
const url = new URL(urlString);
- for (const [key, value] of Object.entries(params)) {
- url.searchParams.set(key, value);
+ if (params) {
+ for (const [key, value] of Object.entries(params)) {
+ url.searchParams.set(key, value);
+ }
}
return url.toString();
}
diff --git a/js/app/packages/entity/src/composed/ListEntity.tsx b/js/app/packages/entity/src/composed/ListEntity.tsx
index 280b0d7401..1b21538949 100644
--- a/js/app/packages/entity/src/composed/ListEntity.tsx
+++ b/js/app/packages/entity/src/composed/ListEntity.tsx
@@ -9,6 +9,7 @@ import { Entity } from '../entity';
import type { StreamEvent } from '@service-connection/generated/schemas';
import {
isChannelEntity,
+ isChannelMessageEntity,
isEmailEntity,
isProjectContainedEntity,
type ChannelEntity,
@@ -49,6 +50,9 @@ import {
} from '@core/component/LexicalMarkdown/theme';
import type { SearchLocation } from '../types/search';
import { isSearchEntity } from '../types/search';
+import { UserIcon } from '@core/component/UserIcon';
+import { SearchContent } from '../extractors-search/search-content';
+import { SearchSender } from '../extractors-search/search-sender';
import { createEntityDraggable } from '../utils/draggable';
import { UnreadIndicator } from '../components/UnreadIndicator';
import { MultiSelectCheckbox } from '../components/MultiSelectCheckbox';
@@ -291,7 +295,41 @@ function NarrowLayout(props: LayoutProps) {
<div class="size-4 shrink-0">
<Entity.Icon entity={props.entity} streamState={props.streamState} />
</div>
- <Entity.Title entity={props.entity} />
+ <Show
+ when={isChannelMessageEntity(props.entity) && props.entity}
+ fallback={<Entity.Title entity={props.entity} />}
+ >
+ {(entity) => {
+ const hit = () => {
+ const e = entity() as EntityData;
+ return isSearchEntity(e)
+ ? e.search.contentHitData?.[0]
+ : undefined;
+ };
+ return (
+ <span class="flex items-center gap-1 min-w-0 truncate">
+ <span class="shrink-0 text-ink-muted text-xs whitespace-nowrap">
+ {entity().channelName}
+ </span>
+ <Show when={entity().senderId}>
+ {(id) => <UserIcon id={id()} size="xs" />}
+ </Show>
+ <Show when={hit()}>
+ {(h) => (
+ <span class="shrink-0 text-ink-extra-muted text-xs whitespace-nowrap">
+ <SearchSender hit={h()} />
+ </span>
+ )}
+ </Show>
+ <span class="text-ink/50 font-normal truncate min-w-0">
+ <Show when={hit()} fallback={entity().content}>
+ {(h) => <SearchContent hit={h()} singleLine />}
+ </Show>
+ </span>
+ </span>
+ );
+ }}
+ </Show>
</Entity.Slot>
<Show
@@ -424,6 +462,38 @@ function NarrowInboxLayout(props: LayoutProps) {
</Entity.Slot>
<Switch>
+ <Match when={isChannelMessageEntity(props.entity) && props.entity}>
+ {(entity) => {
+ const hit = () => {
+ const e = entity() as EntityData;
+ return isSearchEntity(e)
+ ? e.search.contentHitData?.[0]
+ : undefined;
+ };
+ return (
+ <Entity.Slot
+ placement="body"
+ class="flex flex-col pb-2 min-h-[2lh] pr-4"
+ >
+ <Show when={hit()}>
+ {(h) => (
+ <>
+ <span class="text-ink-muted text-xs flex items-center gap-1">
+ <Show when={entity().senderId}>
+ {(id) => <UserIcon id={id()} size="xs" />}
+ </Show>
+ <SearchSender hit={h()} />
+ </span>
+ <span class="text-ink-extra-muted truncate">
+ <SearchContent hit={h()} />
+ </span>
+ </>
+ )}
+ </Show>
+ </Entity.Slot>
+ );
+ }}
+ </Match>
<Match
when={isChannelEntity(props.entity) && props.entity.latestMessage}
>
@@ -569,16 +639,59 @@ function WideLayout(props: LayoutProps) {
</>
)}
</Match>
+ <Match when={isChannelMessageEntity(props.entity) && props.entity}>
+ {(entity) => {
+ const hit = () => {
+ const e = entity() as EntityData;
+ return isSearchEntity(e)
+ ? e.search.contentHitData?.[0]
+ : undefined;
+ };
+ return (
+ <>
+ <span class="shrink-0 flex gap-1.5 items-center">
+ <span class="text-ink-muted whitespace-nowrap">
+ {entity().channelName}
+ </span>
+ <Show when={entity().senderId}>
+ {(id) => <UserIcon id={id()} size="xs" />}
+ </Show>
+ <Show when={hit()}>
+ {(h) => (
+ <span class="text-ink-extra-muted text-xs whitespace-nowrap">
+ <SearchSender hit={h()} />
+ </span>
+ )}
+ </Show>
+ </span>
+ <div class="text-ink/50 font-medium flex-1 min-w-0 overflow-hidden">
+ <Show when={hit()} fallback={entity().content}>
+ {(h) => <SearchContent hit={h()} singleLine />}
+ </Show>
+ </div>
+ </>
+ );
+ }}
+ </Match>
<Match when={isChannelEntity(props.entity) && props.entity}>
{(entity) => (
- <>
- <span class="w-(--title-width) shrink-0 truncate flex gap-2">
- <Entity.Title entity={entity()} />
- </span>
- <Show when={!props.hasNotifications && entity().latestMessage}>
- {(msg) => <ChannelMessage message={msg()} />}
- </Show>
- </>
+ <Show
+ when={!props.hasNotifications && entity().latestMessage}
+ fallback={
+ <span class="truncate flex gap-2">
+ <Entity.Title entity={entity()} />
+ </span>
+ }
+ >
+ {(msg) => (
+ <>
+ <span class="w-(--title-width) shrink truncate flex gap-2">
+ <Entity.Title entity={entity()} />
+ </span>
+ <ChannelMessage message={msg()} />
+ </>
+ )}
+ </Show>
)}
</Match>
<Match when={props.entity}>
diff --git a/js/app/packages/entity/src/extractors-property/entity-key-properties.tsx b/js/app/packages/entity/src/extractors-property/entity-key-properties.tsx
index 0c0d90fc4d..e4fbb6338e 100644
--- a/js/app/packages/entity/src/extractors-property/entity-key-properties.tsx
+++ b/js/app/packages/entity/src/extractors-property/entity-key-properties.tsx
@@ -30,6 +30,7 @@ function getEntityType(entity: EntityData): EntityType {
.with({ type: 'project' }, () => EntityType.PROJECT)
.with({ type: 'email' }, () => EntityType.THREAD)
.with({ type: 'document' }, () => EntityType.DOCUMENT)
+ .with({ type: 'channel_message' }, () => EntityType.CHANNEL)
.exhaustive();
}
diff --git a/js/app/packages/entity/src/extractors-search/content-hits.tsx b/js/app/packages/entity/src/extractors-search/content-hits.tsx
index 06b980a974..bfd0bcbce7 100644
--- a/js/app/packages/entity/src/extractors-search/content-hits.tsx
+++ b/js/app/packages/entity/src/extractors-search/content-hits.tsx
@@ -17,6 +17,9 @@ interface ExtractorContentHitsProps {
export function ContentHits(props: ExtractorContentHitsProps) {
const contentHits = () => {
if (!isSearchEntity(props.entity)) return [];
+ // channel_message entities render their content inline in the row,
+ // so skip the expandable content hits section to avoid duplication
+ if (props.entity.type === 'channel_message') return [];
return props.entity.search.contentHitData ?? [];
};
diff --git a/js/app/packages/entity/src/extractors-search/search-content.tsx b/js/app/packages/entity/src/extractors-search/search-content.tsx
index f2225aedcd..e615240c30 100644
--- a/js/app/packages/entity/src/extractors-search/search-content.tsx
+++ b/js/app/packages/entity/src/extractors-search/search-content.tsx
@@ -2,6 +2,7 @@ import { Show } from 'solid-js';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import {
searchContentHitMarkdownTheme,
+ singleLineMarkdownTheme,
twoLineClampMarkdownTheme,
} from '@core/component/LexicalMarkdown/theme';
import type { ContentHitData } from '../types/search';
@@ -9,6 +10,7 @@ import type { ContentHitData } from '../types/search';
interface SearchContentProps {
hit?: ContentHitData;
twoLineClamp?: boolean;
+ singleLine?: boolean;
}
/**
@@ -19,6 +21,8 @@ export function SearchContent(props: SearchContentProps) {
const theme = () => {
if (props.twoLineClamp) {
return twoLineClampMarkdownTheme;
+ } else if (props.singleLine) {
+ return singleLineMarkdownTheme;
} else {
return searchContentHitMarkdownTheme;
}
diff --git a/js/app/packages/entity/src/extractors/entity-icon.tsx b/js/app/packages/entity/src/extractors/entity-icon.tsx
index 39eff43cd5..744802c92c 100644
--- a/js/app/packages/entity/src/extractors/entity-icon.tsx
+++ b/js/app/packages/entity/src/extractors/entity-icon.tsx
@@ -10,7 +10,11 @@ import { Match, Show, Switch } from 'solid-js';
import { match } from 'ts-pattern';
import { PulsingStar } from '../components/PulsingStar';
import type { ChannelEntity, EntityData } from '../types/entity';
-import { isChannelEntity, isTaskEntity } from '../types/entity';
+import {
+ isChannelEntity,
+ isChannelMessageEntity,
+ isTaskEntity,
+} from '../types/entity';
interface EntityIconProps {
entity: EntityData;
@@ -54,6 +58,7 @@ export function EntityIcon(props: EntityIconProps) {
const iconType = () => {
return match(props.entity)
.when(isChannelEntity, ({ channelType }) => channelType)
+ .when(isChannelMessageEntity, ({ channelType }) => channelType)
.when(isTaskEntity, () => 'task')
.with({ type: 'document' }, ({ fileType }) => {
return fileType ?? 'default';
diff --git a/js/app/packages/entity/src/extractors/entity-title.tsx b/js/app/packages/entity/src/extractors/entity-title.tsx
index 36da546634..faadd02a65 100644
--- a/js/app/packages/entity/src/extractors/entity-title.tsx
+++ b/js/app/packages/entity/src/extractors/entity-title.tsx
@@ -15,6 +15,7 @@ function extractRawTitle(entity: EntityData): string {
)
.with({ type: 'project' }, (e) => e.name)
.with({ type: 'channel' }, (e) => e.name)
+ .with({ type: 'channel_message' }, (e) => e.channelName)
.with({ type: 'email' }, (e) => e.name || '(No Subject)')
.with({ type: 'chat' }, (e) => e.name)
.otherwise(() => 'Unknown');
diff --git a/js/app/packages/entity/src/types/entity.ts b/js/app/packages/entity/src/types/entity.ts
index f3527a9b01..61126d102b 100644
--- a/js/app/packages/entity/src/types/entity.ts
+++ b/js/app/packages/entity/src/types/entity.ts
@@ -35,6 +35,17 @@ export type ChannelEntity = EntityBase & {
};
};
+export type ChannelMessageEntity = EntityBase & {
+ type: 'channel_message';
+ channelId: string;
+ channelName: string;
+ channelType: ChannelEntity['channelType'];
+ messageId: string;
+ threadId?: string;
+ senderId: string;
+ content: string;
+};
+
export type ChatEntity = EntityBase & {
type: 'chat';
projectId?: string;
@@ -110,6 +121,7 @@ export type ProjectEntity = EntityBase & {
export type EntityData =
| ChannelEntity
+ | ChannelMessageEntity
| ChatEntity
| DocumentEntity
| TaskEntity
@@ -142,6 +154,12 @@ export const isChannelEntity = (
return entity.type === 'channel';
};
+export const isChannelMessageEntity = (
+ entity: EntityData
+): entity is ChannelMessageEntity => {
+ return entity.type === 'channel_message';
+};
+
export const isChatEntity = (entity: EntityData): entity is ChatEntity => {
return entity.type === 'chat';
};
diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.ts
index 5b7491d311..d024c085d4 100644
--- a/js/app/packages/macro-entity/src/queries/dss.ts
+++ b/js/app/packages/macro-entity/src/queries/dss.ts
@@ -28,9 +28,11 @@ export function createBulkDeleteDssItemsMutation() {
}
return await Promise.all(
- entities.map((e) => {
- return deleteItem({ id: e.id, itemType: e.type });
- })
+ entities
+ .filter((e) => e.type !== 'channel_message')
+ .map((e) => {
+ return deleteItem({ id: e.id, itemType: e.type });
+ })
);
},
onMutate: async (entities: EntityData[]) => {
diff --git a/js/app/packages/macro-entity/src/queries/rename.ts b/js/app/packages/macro-entity/src/queries/rename.ts
index ca9129fa7a..25c921a3fc 100644
--- a/js/app/packages/macro-entity/src/queries/rename.ts
+++ b/js/app/packages/macro-entity/src/queries/rename.ts
@@ -114,7 +114,7 @@ const renameDssSetData = (
frecency_score: score,
})
);
- } else if (itemType !== 'email') {
+ } else if (itemType !== 'email' && itemType !== 'channel_message') {
txns.set(
id,
optimisticUpdateSoupEntity({
diff --git a/js/app/packages/notifications/notification-navigation.ts b/js/app/packages/notifications/notification-navigation.ts
index 2b5a228221..1dca4d9c78 100644
--- a/js/app/packages/notifications/notification-navigation.ts
+++ b/js/app/packages/notifications/notification-navigation.ts
@@ -1,5 +1,4 @@
import type { SplitManager } from '@app/component/split-layout/layoutManager';
-import { URL_PARAMS as CHANNEL_URL_PARAMS } from '@block-channel/constants';
import type { BlockAlias, BlockName } from '@core/block';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import type { NotificationType } from '@core/types';
@@ -8,6 +7,7 @@ import { getNotificationById } from '@queries/notification/user-notifications';
import { errAsync, ResultAsync } from 'neverthrow';
import { match, P } from 'ts-pattern';
import type { NotificationSource } from './notification-source';
+import { getChannelParams } from '@block-channel/utils/link';
const CHANNEL_EVENT_TYPES = [
'channel_mention',
@@ -64,13 +64,12 @@ async function openChannelNotification(
openSplitIfNotOpen(layoutManager, 'channel', channelId, newSplit);
+ if (!messageId) return;
+
const orchestrator = layoutManager.getOrchestrator();
const handle = await orchestrator.getBlockHandle(channelId, 'channel');
- handle?.goToLocationFromParams({
- [CHANNEL_URL_PARAMS.message]: messageId,
- [CHANNEL_URL_PARAMS.thread]: threadId,
- });
+ handle?.goToLocationFromParams(getChannelParams(messageId, threadId));
}
function safeFileTypeToBlockName(fileType: string | undefined | null) {
diff --git a/js/app/packages/queries/properties/entity.ts b/js/app/packages/queries/properties/entity.ts
index 2dd6a6f4a0..80451af179 100644
--- a/js/app/packages/queries/properties/entity.ts
+++ b/js/app/packages/queries/properties/entity.ts
@@ -334,7 +334,6 @@ function propertyEntityTypeToSoupTag(
() => 'document' as const
)
.with(EntityType.PROJECT, () => 'project' as const)
-
.exhaustive();
}
diff --git a/js/app/packages/queries/soup/search.ts b/js/app/packages/queries/soup/search.ts
index 47a8a36f8b..2d69313a08 100644
--- a/js/app/packages/queries/soup/search.ts
+++ b/js/app/packages/queries/soup/search.ts
@@ -78,7 +78,7 @@ export const useSearchSoupQuery = (
const searchQuery = request().query;
return data.pages.flatMap((page) => {
return page.results
- .map((result) => mapSearchResponseItem(result, searchQuery))
+ .flatMap((result) => mapSearchResponseItem(result, searchQuery))
.filter((entity): entity is WithSearch<EntityData> => !!entity);
});
},
diff --git a/js/app/packages/queries/soup/transform-utils.ts b/js/app/packages/queries/soup/transform-utils.ts
index b1f8e02c36..938d32ccaf 100644
--- a/js/app/packages/queries/soup/transform-utils.ts
+++ b/js/app/packages/queries/soup/transform-utils.ts
@@ -19,6 +19,7 @@ import type {
ProjectEntity,
EmailEntity,
ChannelEntity,
+ ChannelMessageEntity,
} from '@entity';
import type { ChannelType } from '@service-comms/generated/models';
import type {
@@ -177,10 +178,10 @@ export const useSearchResponseItemMapper = () => {
return (
result: UnifiedSearchResponseItem,
searchQuery: string
- ): WithSearch<EntityData> | undefined => {
+ ): (WithSearch<EntityData> | undefined)[] => {
switch (result.type) {
case 'document': {
- if (!result.metadata || result.metadata.deleted_at) return;
+ if (!result.metadata || result.metadata.deleted_at) return [];
const searchFileType =
result.file_type === 'docx' ? 'pdf' : result.file_type;
let search: SearchData;
@@ -201,19 +202,21 @@ export const useSearchResponseItemMapper = () => {
});
}
const properties = result.properties ?? undefined;
- return {
- type: 'document',
- subType: result.sub_type === 'task' ? { type: 'task' } : null,
- id: result.document_id,
- name: result.name || blockNameToDefaultFile(result.file_type),
- ownerId: result.owner_id,
- createdAt: result.metadata?.created_at,
- updatedAt: result.metadata?.updated_at,
- fileType: result.file_type || undefined,
- projectId: result.metadata?.project_id ?? undefined,
- properties,
- search,
- };
+ return [
+ {
+ type: 'document',
+ subType: result.sub_type === 'task' ? { type: 'task' } : null,
+ id: result.document_id,
+ name: result.name || blockNameToDefaultFile(result.file_type),
+ ownerId: result.owner_id,
+ createdAt: result.metadata?.created_at,
+ updatedAt: result.metadata?.updated_at,
+ fileType: result.file_type || undefined,
+ projectId: result.metadata?.project_id ?? undefined,
+ properties,
+ search,
+ },
+ ];
}
case 'email': {
const search = getSearchData({
@@ -229,81 +232,99 @@ export const useSearchResponseItemMapper = () => {
name: p.name ?? undefined,
}));
- return {
- type: 'email',
- id: result.thread_id,
- name,
- ownerId: result.owner_id,
- createdAt: result.created_at,
- updatedAt: result.updated_at,
- viewedAt: result.viewed_at,
- isRead: result.is_read,
- isImportant: result.is_important,
- isDraft: result.is_draft,
- done: !result.inbox_visible,
- participants,
- search,
- snippet: result.snippet ?? undefined,
- };
+ return [
+ {
+ type: 'email',
+ id: result.thread_id,
+ name,
+ ownerId: result.owner_id,
+ createdAt: result.created_at,
+ updatedAt: result.updated_at,
+ viewedAt: result.viewed_at,
+ isRead: result.is_read,
+ isImportant: result.is_important,
+ isDraft: result.is_draft,
+ done: !result.inbox_visible,
+ participants,
+ search,
+ snippet: result.snippet ?? undefined,
+ },
+ ];
}
case 'chat': {
- if (!result.metadata || result.metadata.deleted_at) return;
+ if (!result.metadata || result.metadata.deleted_at) return [];
const search = getSearchData({
results: result.chat_search_results,
});
- return {
- type: 'chat',
- id: result.chat_id,
- name: result.name,
- ownerId: result.user_id,
- createdAt: result.metadata?.created_at,
- updatedAt: result.metadata?.updated_at,
- projectId: result.metadata?.project_id ?? undefined,
- search,
- };
+ return [
+ {
+ type: 'chat',
+ id: result.chat_id,
+ name: result.name,
+ ownerId: result.user_id,
+ createdAt: result.metadata?.created_at,
+ updatedAt: result.metadata?.updated_at,
+ projectId: result.metadata?.project_id ?? undefined,
+ search,
+ },
+ ];
}
case 'channel': {
const channelWithLatest = channels().find(
(c) => c.id === result.channel_id
);
+ const channelName =
+ channelWithLatest?.name ?? blockNameToDefaultFile('channel');
+ const channelType = result.channel_type as ChannelType;
+ const ownerId = result.owner_id ?? '';
- const search = getSearchData({
- type: 'channel',
- results: result.channel_message_search_results,
- });
+ return result.channel_message_search_results
+ .filter((msg) => !!msg.message_id)
+ .map((msg): WithSearch<ChannelMessageEntity> => {
+ const search = getSearchData({
+ type: 'channel',
+ results: [msg],
+ });
- return {
- type: 'channel',
- id: result.channel_id,
- name: channelWithLatest?.name ?? blockNameToDefaultFile('channel'),
- ownerId: result.owner_id ?? '',
- createdAt: result.metadata?.created_at,
- updatedAt: result.metadata?.updated_at,
- channelType: result.channel_type as ChannelType,
- interactedAt: result.metadata?.interacted_at,
- participantIds: channelWithLatest?.participants?.map(
- (p) => p.user_id
- ),
- search,
- };
+ const content = search.contentHitData?.[0]?.content ?? '';
+
+ return {
+ type: 'channel_message',
+ id: `${result.channel_id}:${msg.message_id}`,
+ channelId: result.channel_id,
+ channelName,
+ channelType,
+ messageId: msg.message_id!,
+ threadId: msg.thread_id ?? undefined,
+ senderId: msg.sender_id!,
+ content,
+ name: channelName,
+ ownerId,
+ createdAt: msg.created_at,
+ updatedAt: msg.updated_at ?? msg.created_at,
+ search,
+ };
+ });
}
case 'project': {
- if (!result.metadata || result.metadata.deleted_at) return;
+ if (!result.metadata || result.metadata.deleted_at) return [];
const search = getSearchData({
results: result.project_search_results,
});
- return {
- type: 'project',
- id: result.id,
- name: result.name,
- ownerId: result.owner_id,
- createdAt: result.created_at,
- updatedAt: result.updated_at,
- projectId: result.metadata?.parent_project_id ?? undefined,
- search,
- };
+ return [
+ {
+ type: 'project',
+ id: result.id,
+ name: result.name,
+ ownerId: result.owner_id,
+ createdAt: result.created_at,
+ updatedAt: result.updated_at,
+ projectId: result.metadata?.parent_project_id ?? undefined,
+ search,
+ },
+ ];
}
}
};
diff --git a/js/app/packages/service-clients/service-storage/client.ts b/js/app/packages/service-clients/service-storage/client.ts
index c6c905fb73..5f0550adc8 100644
--- a/js/app/packages/service-clients/service-storage/client.ts
+++ b/js/app/packages/service-clients/service-storage/client.ts
@@ -120,7 +120,11 @@ export type Success = {
};
type SuccessResponse = { data: Success };
-export type ItemType = CloudStorageItemType | 'channel' | 'email';
+export type ItemType =
+ | CloudStorageItemType
+ | 'channel'
+ | 'email'
+ | 'channel_message';
export const DEFAULT_ITEM_TYPE: ItemType = 'document';