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.

chore(new-channels): block compatibility (#2052)

teo8fd3eec2b7b9
diff --git a/js/app/packages/block-channel/component/Block.tsx b/js/app/packages/block-channel/component/Block.tsx
index ef1f6f4e63..adfcf595db 100644
--- a/js/app/packages/block-channel/component/Block.tsx
+++ b/js/app/packages/block-channel/component/Block.tsx
@@ -4,12 +4,10 @@ import { EntityPermissionsGate } from '@core/component/EntityPermissionsGate';
import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';
import { useBlockEntityCommands } from '@app/component/next-soup/actions';
import { type JSXElement, onMount, Suspense } from 'solid-js';
-import { Channel as NewChannel } from '@channel/Channel/Channel';
import { URL_PARAMS } from '@block-channel/constants';
import type { TargetMessageInfo } from '@block-channel/component/MessageList/MessageList';
import { useChannelQuery } from '@queries/channel/channel';
import { ChannelContextProvider } from '@block-channel/hooks/channel';
-import { ENABLE_NEW_CHANNELS } from '@core/constant/featureFlags';
import { Channel } from './Channel';
export function WithTopBar(props: { children: JSXElement }) {
@@ -32,15 +30,6 @@ export default function BlockChannel(props: BlockChannelProps) {
useBlockEntityCommands();
const channelId = useBlockId();
- if (ENABLE_NEW_CHANNELS) {
- return (
- <NewChannel
- channelId={channelId}
- // targetMessageId="019b47e2-d61d-7cef-a7a3-b192c0df2f7f"
- />
- );
- }
-
const targetMessage = () => {
const messageID = props[URL_PARAMS.message];
if (!messageID) return;
diff --git a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx
new file mode 100644
index 0000000000..02a6b92638
--- /dev/null
+++ b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx
@@ -0,0 +1,65 @@
+import {
+ Channel as NewChannel,
+ type ChannelHandle,
+} from '@channel/Channel/Channel';
+import { useBlockId } from '@core/block';
+import { EntityPermissionsGate } from '@core/component/EntityPermissionsGate';
+import { createSignal, Suspense } from 'solid-js';
+import { blockHandleSignal } from '@core/signal/load';
+import { createMethodRegistration } from '@core/orchestrator';
+import { URL_PARAMS } from '@block-channel/constants';
+import { useBlockEntityCommands } from '@app/component/next-soup/actions';
+import { ChannelTopLeft } from './Top';
+import { useChannelName, useChannelType } from '@core/context/channels';
+import { useChannelParticipantsQuery } from '@queries/channel/channel-participants';
+
+function NewTop(props: { channelId: string }) {
+ const channelName = useChannelName(props.channelId);
+ const channelType = useChannelType(props.channelId);
+ const participantsQuery = useChannelParticipantsQuery(() => props.channelId);
+ const participants = () =>
+ participantsQuery.isLoading ? [] : participantsQuery.data;
+
+ return (
+ <Suspense>
+ <ChannelTopLeft
+ channelId={props.channelId}
+ channelType={channelType()!}
+ participants={participants() ?? []}
+ channelName={channelName() ?? 'New Channel'}
+ />
+ </Suspense>
+ );
+}
+
+export function NewChannelBlockAdapter() {
+ useBlockEntityCommands();
+ const channelId = useBlockId();
+ const [channelHandle, setChannelHandle] = createSignal<ChannelHandle>();
+
+ const blockHandle = blockHandleSignal.get;
+ 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;
+ const handle = channelHandle();
+
+ if (topLevelMessageId && handle) {
+ handle.goToMessage(topLevelMessageId, messageReplyId);
+ }
+ },
+ });
+
+ return (
+ <EntityPermissionsGate entityType="channel" entityId={channelId}>
+ <NewChannel channelId={channelId} onHandleReady={setChannelHandle} />
+ <NewTop channelId={channelId} />
+ </EntityPermissionsGate>
+ );
+}
diff --git a/js/app/packages/block-channel/component/Top.tsx b/js/app/packages/block-channel/component/Top.tsx
index 0b98459cb3..ef36d78329 100644
--- a/js/app/packages/block-channel/component/Top.tsx
+++ b/js/app/packages/block-channel/component/Top.tsx
@@ -65,6 +65,37 @@ type TopProps = {
channelId: string;
};
+type ChannelTopLeftProps = TopProps & {
+ lockRename?: boolean;
+};
+
+export function ChannelTopLeft(props: ChannelTopLeftProps) {
+ const blockId = useBlockId();
+ const channelName = useChannelName(
+ blockId,
+ props.channelName ?? 'New Channel'
+ );
+
+ return (
+ <SplitHeaderLeft>
+ <div class="h-full my-auto flex gap-2 justify-start items-center">
+ <div class="z-3 relative flex items-center gap-2 max-w-full h-full shrink">
+ <TopIcon
+ channelType={props.channelType}
+ participants={props.participants}
+ />
+ <SplitLabel
+ label={channelName() ?? 'New Channel'}
+ id={props.channelId}
+ itemType="channel"
+ lockRename={props.lockRename}
+ />
+ </div>
+ </div>
+ </SplitHeaderLeft>
+ );
+}
+
export function Top(props: TopProps) {
const blockId = useBlockId();
const notificationSource = useGlobalNotificationSource();
@@ -135,25 +166,16 @@ export function Top(props: TopProps) {
return (
<>
- <SplitHeaderLeft>
- <div class="h-full my-auto flex gap-2 justify-start items-center">
- <div class="z-3 relative flex items-center gap-2 max-w-full h-full shrink">
- <TopIcon
- channelType={props.channelType}
- participants={props.participants}
- />
- <SplitLabel
- label={channelName() ?? 'New Channel'}
- id={props.channelId}
- itemType="channel"
- lockRename={
- props.channelType === ChannelTypeEnum.DirectMessage ||
- !isAdminOrOwner()
- }
- />
- </div>
- </div>
- </SplitHeaderLeft>
+ <ChannelTopLeft
+ channelId={props.channelId}
+ channelType={props.channelType}
+ participants={props.participants}
+ channelName={props.channelName}
+ lockRename={
+ props.channelType === ChannelTypeEnum.DirectMessage ||
+ !isAdminOrOwner()
+ }
+ />
<SplitHeaderRight>
<BlockLiveIndicators />
diff --git a/js/app/packages/block-channel/definition.ts b/js/app/packages/block-channel/definition.ts
index 371c97fe6e..5d0b2842a7 100644
--- a/js/app/packages/block-channel/definition.ts
+++ b/js/app/packages/block-channel/definition.ts
@@ -3,11 +3,12 @@ import { ok } from '@core/util/maybeResult';
import ChannelBlock from './component/Block';
import { fetchAndCacheChannel } from '@queries/channel/channel';
import { ENABLE_NEW_CHANNELS } from '@core/constant/featureFlags';
+import { NewChannelBlockAdapter } from './component/NewChannelBlockAdapter';
export const definition = defineBlock({
name: 'channel',
description: '',
- component: ChannelBlock,
+ component: ENABLE_NEW_CHANNELS ? NewChannelBlockAdapter : ChannelBlock,
liveTrackingEnabled: true,
async load(source, _intent) {
if (source.type === 'dss') {
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index f39f2d167c..68573df01f 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -4,6 +4,7 @@ import {
useChannelMessagesQuery,
} from '@queries/channel/channel-messages';
import {
+ createEffect,
createMemo,
createSignal,
onMount,
@@ -28,10 +29,6 @@ import {
usePatchMessageMutation,
useSendMessageMutation,
} from '@queries/channel/message';
-import {
- useAddReactionMutation,
- useRemoveReactionMutation,
-} from '@queries/channel/reaction';
import type { DateValue } from '@core/util/date';
import { buildChannelMessageListMeta } from './message-list-meta';
import { ScrollToBottomOverlay } from './ScrollToBottomOverlay';
@@ -60,16 +57,25 @@ import { createMessageEditor } from './create-message-editor';
import { createMessageSelection } from './create-message-selection';
import { createChannelHotkeys } from './create-channel-hotkeys';
import type { ChannelInputProps } from '@channel/Input/ChannelInput';
-import { createTargetMessageController } from './create-target-message-controller';
-import { createMethodRegistration } from '@core/orchestrator';
-import { blockHandleSignal } from '@core/signal/load';
-import { URL_PARAMS } from '@block-channel/constants';
+import {
+ createTargetMessageController,
+ type TargetMessageController,
+} from './create-target-message-controller';
+import {
+ useAddReactionMutation,
+ useRemoveReactionMutation,
+} from '@queries/channel/reaction';
type ChannelProps = {
channelId: string;
targetMessageId?: string | undefined;
targetMessageReplyId?: string | undefined;
lastViewedAt?: DateValue | null;
+ onHandleReady?: (handle: ChannelHandle) => void;
+};
+
+export type ChannelHandle = {
+ goToMessage: TargetMessageController['goToMessage'];
};
export function Channel(props: ChannelProps) {
@@ -91,26 +97,6 @@ export function Channel(props: ChannelProps) {
navigation: threadListNavigation,
});
- // START BLOCK COMPATIBILITY
- const blockHandle = blockHandleSignal.get;
- 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 compotibility 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;
-
- if (topLevelMessageId) {
- targetMessageController.goToMessage(topLevelMessageId, messageReplyId);
- }
- },
- });
- // END BLOCK COMPATIBILITY
-
const [channelInputSnapshot, setChannelInputSnapshot] =
createSignal<InputSnapshot>();
@@ -229,6 +215,13 @@ export function Channel(props: ChannelProps) {
});
};
+ createEffect(() => {
+ if (props.onHandleReady)
+ props.onHandleReady({
+ goToMessage: targetMessageController.goToMessage,
+ });
+ });
+
return (
<Suspense>
<StaticMarkdownContext>
diff --git a/js/app/packages/core/context/channels.ts b/js/app/packages/core/context/channels.ts
index 59ca295211..4f6258b7d7 100644
--- a/js/app/packages/core/context/channels.ts
+++ b/js/app/packages/core/context/channels.ts
@@ -67,6 +67,11 @@ export function useChannelName(channelId: string, fallback?: string) {
return createMemo(() => ctx.channelsById()[channelId]?.name ?? fallback);
}
+export function useChannelType(channelId: string) {
+ const ctx = useChannelsContext();
+ return createMemo(() => ctx.channelsById()[channelId]?.channel_type);
+}
+
export function useChannelActivity(channelId: string) {
const ctx = useChannelsContext();
return createMemo(() => ctx.activityByChannelId()[channelId]);