mirror of
https://github.com/block/buzz.git
synced 2026-11-25 18:52:52 +00:00
986 lines
36 KiB
TypeScript
986 lines
36 KiB
TypeScript
import * as React from "react";
|
|
import { Bot, Hash, LogIn, Plus, Sparkles, UserPlus } from "lucide-react";
|
|
|
|
import { useMediaUpload } from "@/features/messages/lib/useMediaUpload";
|
|
import { MessageComposer } from "@/features/messages/ui/MessageComposer";
|
|
import { DropZoneOverlay } from "@/features/messages/ui/ComposerAttachments";
|
|
import {
|
|
MessageThreadPanel,
|
|
MessageThreadPanelSkeleton,
|
|
} from "@/features/messages/ui/MessageThreadPanel";
|
|
import { MessageTimeline } from "@/features/messages/ui/MessageTimeline";
|
|
import type { ImetaMedia } from "@/features/messages/lib/imetaMediaMarkdown";
|
|
import { buildDirectMessageIntro } from "@/features/channels/lib/dmParticipantDisplay";
|
|
import {
|
|
buildVideoReviewCommentsByRootId,
|
|
buildVideoReviewContextForMessage,
|
|
} from "@/features/messages/lib/videoReviewContext";
|
|
import { useComposerHeightPadding } from "@/features/messages/ui/useComposerHeightPadding";
|
|
import { TypingIndicatorRow } from "@/features/messages/ui/TypingIndicatorRow";
|
|
import type { TypingIndicatorEntry } from "@/features/messages/useChannelTyping";
|
|
import { UserProfilePanel } from "@/features/profile/ui/UserProfilePanel";
|
|
import { ChannelFindBar } from "@/features/search/ui/ChannelFindBar";
|
|
import { AgentSessionThreadPanel } from "@/features/channels/ui/AgentSessionThreadPanel";
|
|
import { ChannelManagementSheet } from "@/features/channels/ui/ChannelManagementSheet";
|
|
import { RightAuxiliaryPane } from "@/features/channels/ui/RightAuxiliaryPane";
|
|
import {
|
|
BotActivityComposerAction,
|
|
type BotActivityAgent,
|
|
} from "@/features/channels/ui/BotActivityBar";
|
|
import {
|
|
containsWelcomePersonaMention,
|
|
WelcomeComposerBanner,
|
|
WELCOME_COMPOSER_BANNER_DISMISS_DURATION_SECONDS,
|
|
WELCOME_COMPOSER_BANNER_HIDE_BUFFER_MS,
|
|
WELCOME_COMPOSER_BANNER_SUCCESS_SETTLE_MS,
|
|
WELCOME_PERSONA_ROTATION_MS,
|
|
type WelcomeComposerBannerState,
|
|
} from "@/features/channels/ui/WelcomeComposerBanner";
|
|
import {
|
|
getChannelIntroDescription,
|
|
getChannelIntroKind,
|
|
isWelcomeSetupSystemMessage,
|
|
mentionsKnownAgent,
|
|
} from "@/features/channels/ui/ChannelPane.helpers";
|
|
import type { ChannelAgentSessionAgent } from "@/features/channels/ui/useChannelAgentSessions";
|
|
import { Button } from "@/shared/ui/button";
|
|
import type { useChannelFind } from "@/features/search/useChannelFind";
|
|
import type { MainTimelineEntry } from "@/features/messages/lib/threadPanel";
|
|
import type { TimelineMessage } from "@/features/messages/types";
|
|
import type { UserProfileLookup } from "@/features/profile/lib/identity";
|
|
import { isWelcomeChannel } from "@/features/onboarding/welcome";
|
|
import { KIND_SYSTEM_MESSAGE } from "@/shared/constants/kinds";
|
|
import type { Channel } from "@/shared/api/types";
|
|
import { useIsThreadPanelOverlay } from "@/shared/hooks/use-mobile";
|
|
import { channelChrome } from "@/shared/layout/chromeLayout";
|
|
import { cn } from "@/shared/lib/cn";
|
|
|
|
type ChannelPaneProps = {
|
|
activeChannel: Channel | null;
|
|
activityAgents?: BotActivityAgent[];
|
|
agentPubkeys?: ReadonlySet<string>;
|
|
agentSessionAgents: ChannelAgentSessionAgent[];
|
|
botTypingEntries: TypingIndicatorEntry[];
|
|
channelFind: ReturnType<typeof useChannelFind>;
|
|
channelManagementOpen?: boolean;
|
|
currentPubkey?: string;
|
|
editTarget?: {
|
|
author: string;
|
|
body: string;
|
|
id: string;
|
|
imetaMedia?: ImetaMedia[];
|
|
} | null;
|
|
fetchOlder?: () => Promise<void>;
|
|
header?: React.ReactNode;
|
|
hasOlderMessages?: boolean;
|
|
isFetchingOlder?: boolean;
|
|
isJoining?: boolean;
|
|
isSinglePanelView?: boolean;
|
|
isSending: boolean;
|
|
isTimelineLoading: boolean;
|
|
messages: TimelineMessage[];
|
|
/** Event id of the oldest unread top-level message at channel open, or null. */
|
|
firstUnreadMessageId?: string | null;
|
|
/** Count of unread top-level messages at channel open. */
|
|
unreadCount?: number;
|
|
canResetThreadPanelWidth: boolean;
|
|
onCancelEdit?: () => void;
|
|
onCancelThreadReply: () => void;
|
|
onCloseAgentSession: () => void;
|
|
onCloseChannelManagement?: () => void;
|
|
onChannelManagementDeleted?: () => void;
|
|
onCloseProfilePanel: () => void;
|
|
onAddAgent?: () => void;
|
|
onCreateChannel?: () => void;
|
|
onCloseThread: () => void;
|
|
onDelete?: (message: TimelineMessage) => void;
|
|
onEdit?: (message: TimelineMessage) => void;
|
|
onEditSave?: (content: string, mediaTags?: string[][]) => Promise<void>;
|
|
onMarkUnread?: (message: TimelineMessage) => void;
|
|
onExpandThreadReplies: (message: TimelineMessage) => void;
|
|
onJoinChannel?: () => Promise<void>;
|
|
onOpenAgentSession: (pubkey: string) => void;
|
|
onOpenDm?: (pubkeys: string[]) => void;
|
|
onOpenMembers?: () => void;
|
|
onOpenProfilePanel: (pubkey: string) => void;
|
|
onOpenThread: (message: TimelineMessage) => void;
|
|
onResetThreadPanelWidth: () => void;
|
|
onSelectThreadReplyTarget: (message: TimelineMessage) => void;
|
|
onSendMessage: (
|
|
content: string,
|
|
mentionPubkeys: string[],
|
|
mediaTags?: string[][],
|
|
) => Promise<void>;
|
|
onSendVideoReviewComment?: (
|
|
message: TimelineMessage,
|
|
content: string,
|
|
mentionPubkeys: string[],
|
|
mediaTags?: string[][],
|
|
parentEventId?: string,
|
|
) => Promise<void>;
|
|
onSendThreadReply: (
|
|
content: string,
|
|
mentionPubkeys: string[],
|
|
mediaTags?: string[][],
|
|
) => Promise<void>;
|
|
onTargetReached?: (messageId: string) => void;
|
|
onToggleReaction?: (
|
|
message: TimelineMessage,
|
|
emoji: string,
|
|
remove: boolean,
|
|
) => Promise<void>;
|
|
onThreadScrollTargetResolved: () => void;
|
|
onThreadPanelResizeStart: (
|
|
event: React.PointerEvent<HTMLButtonElement>,
|
|
) => void;
|
|
/** Map from lowercase pubkey → persona display name for bot members. */
|
|
personaLookup?: Map<string, string>;
|
|
profiles?: UserProfileLookup;
|
|
openThreadHeadId: string | null;
|
|
openAgentSessionPubkey: string | null;
|
|
profilePanelPubkey?: string | null;
|
|
threadHeadMessage: TimelineMessage | null;
|
|
threadMessages: MainTimelineEntry[];
|
|
threadPanelWidthPx: number;
|
|
threadTypingPubkeys: string[];
|
|
threadReplyTargetMessage: TimelineMessage | null;
|
|
threadScrollTargetId: string | null;
|
|
/** Per-thread unread counts keyed by thread root id. */
|
|
threadUnreadCounts?: ReadonlyMap<string, number>;
|
|
/** Subtree unread counts for in-panel summary rows, keyed by reply id. */
|
|
threadReplyUnreadCounts?: ReadonlyMap<string, number>;
|
|
/** Event id of the first unread reply in the open thread panel. */
|
|
threadFirstUnreadReplyId?: string | null;
|
|
targetMessageId: string | null;
|
|
typingPubkeys: string[];
|
|
isFollowingThread?: boolean;
|
|
onFollowThread?: () => void;
|
|
onUnfollowThread?: () => void;
|
|
followThreadById?: (rootId: string) => void;
|
|
unfollowThreadById?: (rootId: string) => void;
|
|
isFollowingThreadById?: (rootId: string) => boolean;
|
|
};
|
|
|
|
export const ChannelPane = React.memo(function ChannelPane({
|
|
activeChannel,
|
|
agentPubkeys,
|
|
agentSessionAgents,
|
|
activityAgents = agentSessionAgents,
|
|
botTypingEntries,
|
|
channelFind,
|
|
channelManagementOpen = false,
|
|
currentPubkey,
|
|
editTarget = null,
|
|
fetchOlder,
|
|
header,
|
|
hasOlderMessages,
|
|
isFetchingOlder,
|
|
followThreadById,
|
|
isFollowingThread,
|
|
isFollowingThreadById,
|
|
isJoining = false,
|
|
isSinglePanelView = false,
|
|
isSending,
|
|
isTimelineLoading,
|
|
messages,
|
|
firstUnreadMessageId = null,
|
|
unreadCount = 0,
|
|
canResetThreadPanelWidth,
|
|
onCancelEdit,
|
|
onCancelThreadReply,
|
|
onCloseAgentSession,
|
|
onCloseChannelManagement,
|
|
onChannelManagementDeleted,
|
|
onCloseProfilePanel,
|
|
onAddAgent,
|
|
onCreateChannel,
|
|
onCloseThread,
|
|
onDelete,
|
|
onEdit,
|
|
onEditSave,
|
|
onFollowThread,
|
|
onMarkUnread,
|
|
onExpandThreadReplies,
|
|
onJoinChannel,
|
|
onOpenAgentSession,
|
|
onOpenDm,
|
|
onOpenMembers,
|
|
onOpenProfilePanel,
|
|
onOpenThread,
|
|
onResetThreadPanelWidth,
|
|
onSelectThreadReplyTarget,
|
|
onSendMessage,
|
|
onSendVideoReviewComment,
|
|
onSendThreadReply,
|
|
onThreadScrollTargetResolved,
|
|
onThreadPanelResizeStart,
|
|
onTargetReached,
|
|
onToggleReaction,
|
|
onUnfollowThread,
|
|
unfollowThreadById,
|
|
personaLookup,
|
|
profiles,
|
|
openThreadHeadId,
|
|
openAgentSessionPubkey,
|
|
profilePanelPubkey,
|
|
targetMessageId,
|
|
threadHeadMessage,
|
|
threadMessages,
|
|
threadPanelWidthPx,
|
|
threadScrollTargetId,
|
|
threadTypingPubkeys,
|
|
threadReplyTargetMessage,
|
|
threadUnreadCounts,
|
|
threadReplyUnreadCounts,
|
|
threadFirstUnreadReplyId,
|
|
typingPubkeys,
|
|
}: ChannelPaneProps) {
|
|
const timelineScrollRef = React.useRef<HTMLDivElement>(null);
|
|
const composerWrapperRef = React.useRef<HTMLDivElement>(null);
|
|
const completedWelcomeBannerChannelIdsRef = React.useRef(new Set<string>());
|
|
const welcomeComposerDismissTimerRef = React.useRef<number | null>(null);
|
|
const welcomeComposerHideTimerRef = React.useRef<number | null>(null);
|
|
const [welcomeComposerBannerState, setWelcomeComposerBannerState] =
|
|
React.useState<WelcomeComposerBannerState>("prompt");
|
|
const mainComposerMedia = useMediaUpload();
|
|
const isNonMemberView =
|
|
activeChannel !== null &&
|
|
!activeChannel.isMember &&
|
|
activeChannel.visibility === "open" &&
|
|
!activeChannel.archivedAt;
|
|
const hasMainComposerOverlay = !isNonMemberView;
|
|
const activeChannelId = activeChannel?.id ?? null;
|
|
const isActiveWelcomeChannel =
|
|
activeChannel !== null && isWelcomeChannel(activeChannel);
|
|
useComposerHeightPadding(
|
|
timelineScrollRef,
|
|
composerWrapperRef,
|
|
`${isSinglePanelView}:${hasMainComposerOverlay}`,
|
|
);
|
|
|
|
const clearWelcomeComposerDismissTimer = React.useCallback(() => {
|
|
if (welcomeComposerDismissTimerRef.current !== null) {
|
|
window.clearTimeout(welcomeComposerDismissTimerRef.current);
|
|
welcomeComposerDismissTimerRef.current = null;
|
|
}
|
|
|
|
if (welcomeComposerHideTimerRef.current !== null) {
|
|
window.clearTimeout(welcomeComposerHideTimerRef.current);
|
|
welcomeComposerHideTimerRef.current = null;
|
|
}
|
|
}, []);
|
|
|
|
React.useEffect(
|
|
() => () => clearWelcomeComposerDismissTimer(),
|
|
[clearWelcomeComposerDismissTimer],
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
clearWelcomeComposerDismissTimer();
|
|
|
|
if (
|
|
activeChannelId &&
|
|
isActiveWelcomeChannel &&
|
|
completedWelcomeBannerChannelIdsRef.current.has(activeChannelId)
|
|
) {
|
|
setWelcomeComposerBannerState("hidden");
|
|
return;
|
|
}
|
|
|
|
setWelcomeComposerBannerState("prompt");
|
|
}, [
|
|
activeChannelId,
|
|
clearWelcomeComposerDismissTimer,
|
|
isActiveWelcomeChannel,
|
|
]);
|
|
|
|
// Scope the edit target to the correct composer: if the message being edited
|
|
// lives inside the open thread (thread head or a reply), show the editing UI
|
|
// only in the thread panel; otherwise show it in the main channel composer.
|
|
const isEditInThread =
|
|
editTarget != null &&
|
|
threadHeadMessage != null &&
|
|
(editTarget.id === threadHeadMessage.id ||
|
|
threadMessages.some((entry) => entry.message.id === editTarget.id));
|
|
const mainEditTarget = editTarget && !isEditInThread ? editTarget : null;
|
|
const threadEditTarget = editTarget && isEditInThread ? editTarget : null;
|
|
|
|
// ↑-to-edit resolvers. Find the most recent message authored by the current
|
|
// user in the relevant scope and enter edit mode via `onEdit`. Editability
|
|
// mirrors the action bar's gate (`message.pubkey === currentPubkey`); we
|
|
// also skip optimistic `pending` messages, which have no persisted event id
|
|
// to target. Both scopes are passed in chronological (oldest→newest) order,
|
|
// so we select by newest `createdAt` and break ties toward the later array
|
|
// position (`>=`) — `createdAt` is second-granularity, so a reply sent in
|
|
// the same second as the message before it must still win. Returns true when
|
|
// a target was found so MessageComposer can swallow the ArrowUp.
|
|
const findLastOwnEditable = React.useCallback(
|
|
(candidates: TimelineMessage[]): TimelineMessage | null => {
|
|
if (!onEdit || !currentPubkey) return null;
|
|
let best: TimelineMessage | null = null;
|
|
for (const message of candidates) {
|
|
if (
|
|
message.kind === KIND_SYSTEM_MESSAGE ||
|
|
message.pubkey !== currentPubkey ||
|
|
message.pending
|
|
) {
|
|
continue;
|
|
}
|
|
if (!best || message.createdAt >= best.createdAt) {
|
|
best = message;
|
|
}
|
|
}
|
|
return best;
|
|
},
|
|
[onEdit, currentPubkey],
|
|
);
|
|
|
|
const handleEditLastOwnMainMessage = React.useCallback((): boolean => {
|
|
const target = findLastOwnEditable(messages);
|
|
if (!target || !onEdit) return false;
|
|
onEdit(target);
|
|
return true;
|
|
}, [findLastOwnEditable, messages, onEdit]);
|
|
|
|
const handleEditLastOwnThreadMessage = React.useCallback((): boolean => {
|
|
if (!onEdit) return false;
|
|
// Thread scope = the open thread head plus its replies, in chronological
|
|
// order. The head is oldest, so append it first.
|
|
const scope: TimelineMessage[] = [];
|
|
if (threadHeadMessage) scope.push(threadHeadMessage);
|
|
for (const entry of threadMessages) scope.push(entry.message);
|
|
const target = findLastOwnEditable(scope);
|
|
if (!target) return false;
|
|
onEdit(target);
|
|
return true;
|
|
}, [findLastOwnEditable, onEdit, threadHeadMessage, threadMessages]);
|
|
|
|
const isComposerDisabled =
|
|
!activeChannel?.isMember ||
|
|
activeChannel.archivedAt !== null ||
|
|
activeChannel.channelType === "forum" ||
|
|
isSending;
|
|
const knownAgentPubkeys = React.useMemo(() => {
|
|
const pubkeys = new Set<string>();
|
|
|
|
for (const pubkey of agentPubkeys ?? []) {
|
|
pubkeys.add(pubkey.toLowerCase());
|
|
}
|
|
for (const agent of agentSessionAgents) {
|
|
pubkeys.add(agent.pubkey.toLowerCase());
|
|
}
|
|
for (const agent of activityAgents) {
|
|
pubkeys.add(agent.pubkey.toLowerCase());
|
|
}
|
|
|
|
return pubkeys;
|
|
}, [activityAgents, agentPubkeys, agentSessionAgents]);
|
|
const completeWelcomeComposerBanner = React.useCallback(() => {
|
|
if (!activeChannelId || !isActiveWelcomeChannel) {
|
|
return;
|
|
}
|
|
|
|
clearWelcomeComposerDismissTimer();
|
|
completedWelcomeBannerChannelIdsRef.current.add(activeChannelId);
|
|
setWelcomeComposerBannerState("complete");
|
|
welcomeComposerDismissTimerRef.current = window.setTimeout(() => {
|
|
setWelcomeComposerBannerState("dismissing");
|
|
welcomeComposerDismissTimerRef.current = null;
|
|
welcomeComposerHideTimerRef.current = window.setTimeout(
|
|
() => {
|
|
setWelcomeComposerBannerState("hidden");
|
|
welcomeComposerHideTimerRef.current = null;
|
|
},
|
|
WELCOME_COMPOSER_BANNER_DISMISS_DURATION_SECONDS * 1000 +
|
|
WELCOME_COMPOSER_BANNER_HIDE_BUFFER_MS,
|
|
);
|
|
}, WELCOME_PERSONA_ROTATION_MS + WELCOME_COMPOSER_BANNER_SUCCESS_SETTLE_MS);
|
|
}, [
|
|
activeChannelId,
|
|
clearWelcomeComposerDismissTimer,
|
|
isActiveWelcomeChannel,
|
|
]);
|
|
const handleSendMessage = React.useCallback(
|
|
async (
|
|
content: string,
|
|
mentionPubkeys: string[],
|
|
mediaTags?: string[][],
|
|
) => {
|
|
const shouldCompleteWelcomeBanner =
|
|
isActiveWelcomeChannel &&
|
|
(containsWelcomePersonaMention(content) ||
|
|
mentionsKnownAgent(mentionPubkeys, knownAgentPubkeys));
|
|
|
|
await onSendMessage(content, mentionPubkeys, mediaTags);
|
|
|
|
if (shouldCompleteWelcomeBanner) {
|
|
completeWelcomeComposerBanner();
|
|
}
|
|
},
|
|
[
|
|
completeWelcomeComposerBanner,
|
|
isActiveWelcomeChannel,
|
|
knownAgentPubkeys,
|
|
onSendMessage,
|
|
],
|
|
);
|
|
const canDropInMainColumn =
|
|
hasMainComposerOverlay && !isComposerDisabled && !isSinglePanelView;
|
|
const hasTypingActivity = typingPubkeys.length > 0;
|
|
const composerBotTypingPubkeys = React.useMemo(() => {
|
|
const pubkeys: string[] = [];
|
|
for (const entry of botTypingEntries) {
|
|
if (entry.threadHeadId !== null) {
|
|
continue;
|
|
}
|
|
|
|
if (
|
|
!pubkeys.some(
|
|
(pubkey) => pubkey.toLowerCase() === entry.pubkey.toLowerCase(),
|
|
)
|
|
) {
|
|
pubkeys.push(entry.pubkey);
|
|
}
|
|
}
|
|
return pubkeys;
|
|
}, [botTypingEntries]);
|
|
const hasComposerBotActivity = composerBotTypingPubkeys.length > 0;
|
|
const threadComposerBotTypingPubkeys = React.useMemo(() => {
|
|
if (!openThreadHeadId) {
|
|
return [];
|
|
}
|
|
|
|
const pubkeys: string[] = [];
|
|
for (const entry of botTypingEntries) {
|
|
if (entry.threadHeadId !== openThreadHeadId) {
|
|
continue;
|
|
}
|
|
|
|
if (
|
|
!pubkeys.some(
|
|
(pubkey) => pubkey.toLowerCase() === entry.pubkey.toLowerCase(),
|
|
)
|
|
) {
|
|
pubkeys.push(entry.pubkey);
|
|
}
|
|
}
|
|
return pubkeys;
|
|
}, [botTypingEntries, openThreadHeadId]);
|
|
const hasThreadComposerBotActivity =
|
|
threadComposerBotTypingPubkeys.length > 0;
|
|
const directMessageIntro = React.useMemo(
|
|
() =>
|
|
buildDirectMessageIntro({
|
|
channel: activeChannel,
|
|
currentPubkey,
|
|
profiles,
|
|
}),
|
|
[activeChannel, currentPubkey, profiles],
|
|
);
|
|
|
|
const channelIntro = React.useMemo(() => {
|
|
if (!activeChannel || activeChannel.channelType === "dm") {
|
|
return null;
|
|
}
|
|
|
|
const actions = [];
|
|
if (isWelcomeChannel(activeChannel)) {
|
|
if (onCreateChannel) {
|
|
actions.push({
|
|
icon: <Plus aria-hidden className="h-6 w-6" />,
|
|
label: "Create a channel",
|
|
onClick: onCreateChannel,
|
|
testId: "welcome-intro-action-create-channel",
|
|
});
|
|
}
|
|
|
|
if (onAddAgent) {
|
|
actions.push({
|
|
icon: <Bot aria-hidden className="h-6 w-6" />,
|
|
label: "Create a custom agent",
|
|
onClick: onAddAgent,
|
|
testId: "welcome-intro-action-create-agent",
|
|
});
|
|
}
|
|
|
|
return {
|
|
actions,
|
|
channelKindLabel: "private welcome channel",
|
|
channelName: activeChannel.name,
|
|
description: null,
|
|
icon: <Sparkles aria-hidden className="h-7 w-7" />,
|
|
};
|
|
}
|
|
|
|
if (!activeChannel.archivedAt && activeChannel.isMember) {
|
|
if (onAddAgent) {
|
|
actions.push({
|
|
description: "Add an agent here.",
|
|
icon: <Bot aria-hidden className="h-6 w-6" />,
|
|
label: "Create agent",
|
|
onClick: onAddAgent,
|
|
testId: "channel-intro-action-create-agent",
|
|
});
|
|
}
|
|
|
|
if (onOpenMembers) {
|
|
actions.push({
|
|
description: "Invite members.",
|
|
icon: <UserPlus aria-hidden className="h-6 w-6" />,
|
|
label: "Add people",
|
|
onClick: onOpenMembers,
|
|
testId: "channel-intro-action-add-people",
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
actions,
|
|
channelKindLabel: getChannelIntroKind(activeChannel),
|
|
channelName: activeChannel.name,
|
|
description: getChannelIntroDescription(activeChannel),
|
|
};
|
|
}, [activeChannel, onAddAgent, onCreateChannel, onOpenMembers]);
|
|
|
|
const visibleMessages = React.useMemo(() => {
|
|
if (!isWelcomeChannel(activeChannel)) {
|
|
return messages;
|
|
}
|
|
|
|
return messages.filter((message) => !isWelcomeSetupSystemMessage(message));
|
|
}, [activeChannel, messages]);
|
|
const videoReviewCommentsByRootId = React.useMemo(
|
|
() => buildVideoReviewCommentsByRootId(messages),
|
|
[messages],
|
|
);
|
|
const activeVideoReviewCommentSender = activeChannel?.archivedAt
|
|
? undefined
|
|
: onSendVideoReviewComment;
|
|
const threadHeadVideoReviewContext = React.useMemo(() => {
|
|
if (!threadHeadMessage) {
|
|
return undefined;
|
|
}
|
|
|
|
return buildVideoReviewContextForMessage({
|
|
channelId: activeChannel?.id ?? null,
|
|
channelName: activeChannel?.name,
|
|
channelType: activeChannel?.channelType ?? null,
|
|
comments: videoReviewCommentsByRootId.get(threadHeadMessage.id) ?? [],
|
|
isSendingVideoReviewComment: isSending,
|
|
message: threadHeadMessage,
|
|
onSendVideoReviewComment: activeVideoReviewCommentSender,
|
|
onToggleReaction,
|
|
profiles,
|
|
});
|
|
}, [
|
|
activeChannel,
|
|
activeVideoReviewCommentSender,
|
|
isSending,
|
|
onToggleReaction,
|
|
profiles,
|
|
threadHeadMessage,
|
|
videoReviewCommentsByRootId,
|
|
]);
|
|
|
|
const isOverlay = useIsThreadPanelOverlay();
|
|
const useSplitAuxiliaryPane = !isSinglePanelView && !isOverlay;
|
|
|
|
const selectedAgent = React.useMemo(
|
|
() =>
|
|
openAgentSessionPubkey
|
|
? (agentSessionAgents.find(
|
|
(agent) => agent.pubkey === openAgentSessionPubkey,
|
|
) ?? null)
|
|
: null,
|
|
[agentSessionAgents, openAgentSessionPubkey],
|
|
);
|
|
return (
|
|
<div className="flex min-h-0 min-w-0 flex-1 flex-row overflow-hidden">
|
|
{!isSinglePanelView ? (
|
|
<section
|
|
aria-label="Channel messages and composer"
|
|
className="relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden"
|
|
data-testid="channel-drop-zone"
|
|
onDragEnter={
|
|
canDropInMainColumn ? mainComposerMedia.handleDragEnter : undefined
|
|
}
|
|
onDragLeave={
|
|
canDropInMainColumn ? mainComposerMedia.handleDragLeave : undefined
|
|
}
|
|
onDragOver={
|
|
canDropInMainColumn ? mainComposerMedia.handleDragOver : undefined
|
|
}
|
|
onDrop={
|
|
canDropInMainColumn
|
|
? (event) => {
|
|
void mainComposerMedia.handleDrop(event);
|
|
}
|
|
: undefined
|
|
}
|
|
>
|
|
{header}
|
|
{channelFind.isOpen ? (
|
|
<div className={cn("absolute inset-x-0 z-40", channelChrome.top)}>
|
|
<ChannelFindBar
|
|
matchCount={channelFind.matchCount}
|
|
matchIndex={channelFind.activeIndex}
|
|
onClose={channelFind.close}
|
|
onNext={channelFind.goToNext}
|
|
onPrevious={channelFind.goToPrevious}
|
|
onQueryChange={channelFind.setQuery}
|
|
query={channelFind.query}
|
|
/>
|
|
</div>
|
|
) : null}
|
|
<MessageTimeline
|
|
agentPubkeys={agentPubkeys}
|
|
channelId={activeChannel?.id}
|
|
channelIntro={channelIntro}
|
|
directMessageIntro={directMessageIntro}
|
|
scrollContainerRef={timelineScrollRef}
|
|
currentPubkey={currentPubkey}
|
|
fetchOlder={fetchOlder}
|
|
followThreadById={followThreadById}
|
|
hasComposerOverlay={hasMainComposerOverlay}
|
|
hasOlderMessages={hasOlderMessages}
|
|
isFetchingOlder={isFetchingOlder}
|
|
isFollowingThreadById={isFollowingThreadById}
|
|
personaLookup={personaLookup}
|
|
profiles={profiles}
|
|
unfollowThreadById={unfollowThreadById}
|
|
emptyDescription={
|
|
activeChannel?.channelType === "forum"
|
|
? "Select a stream or DM to load real message history in this first integration pass."
|
|
: "Messages and sub-replies will appear here once the relay has history for this channel."
|
|
}
|
|
emptyTitle={
|
|
activeChannel
|
|
? activeChannel.channelType === "forum"
|
|
? "Forum channels are next"
|
|
: "No messages yet"
|
|
: "No channel selected"
|
|
}
|
|
isLoading={isTimelineLoading}
|
|
messages={visibleMessages}
|
|
firstUnreadMessageId={firstUnreadMessageId}
|
|
unreadCount={unreadCount}
|
|
onDelete={onDelete}
|
|
onEdit={onEdit}
|
|
onMarkUnread={onMarkUnread}
|
|
onReply={activeChannel?.archivedAt ? undefined : onOpenThread}
|
|
channelName={activeChannel?.name}
|
|
channelType={activeChannel?.channelType ?? null}
|
|
isSendingVideoReviewComment={isSending}
|
|
onSendVideoReviewComment={
|
|
activeChannel?.archivedAt ? undefined : onSendVideoReviewComment
|
|
}
|
|
onTargetReached={onTargetReached}
|
|
onToggleReaction={onToggleReaction}
|
|
searchActiveMessageId={channelFind.activeMatch?.messageId ?? null}
|
|
searchMatchingMessageIds={channelFind.matchingMessageIds}
|
|
searchQuery={channelFind.query}
|
|
targetMessageId={targetMessageId}
|
|
threadUnreadCounts={threadUnreadCounts}
|
|
/>
|
|
{isNonMemberView ? (
|
|
<div
|
|
data-testid="join-banner"
|
|
className="flex items-center gap-3 border-t border-border/80 bg-card/50 px-5 py-3"
|
|
>
|
|
<div className="flex min-w-0 flex-1 items-center gap-2 text-sm text-muted-foreground">
|
|
<Hash className="h-4 w-4 shrink-0" />
|
|
<span className="truncate">
|
|
Viewing{" "}
|
|
<span className="font-medium text-foreground">
|
|
#{activeChannel?.name}
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<Button
|
|
disabled={isJoining}
|
|
onClick={() => {
|
|
void onJoinChannel?.();
|
|
}}
|
|
size="sm"
|
|
variant="default"
|
|
>
|
|
<LogIn className="mr-1.5 h-4 w-4" />
|
|
{isJoining ? "Joining..." : "Join to participate"}
|
|
</Button>
|
|
</div>
|
|
) : (
|
|
<div
|
|
className="pointer-events-none absolute inset-x-0 bottom-0 z-10"
|
|
ref={composerWrapperRef}
|
|
>
|
|
<div className="pointer-events-auto">
|
|
{isActiveWelcomeChannel ? (
|
|
<WelcomeComposerBanner state={welcomeComposerBannerState} />
|
|
) : null}
|
|
<MessageComposer
|
|
channelId={activeChannel?.id ?? null}
|
|
channelName={activeChannel?.name ?? "channel"}
|
|
channelType={activeChannel?.channelType ?? null}
|
|
containerClassName="px-5"
|
|
disabled={isComposerDisabled}
|
|
editTarget={mainEditTarget}
|
|
isSending={isSending}
|
|
mediaController={mainComposerMedia}
|
|
onCancelEdit={onCancelEdit}
|
|
onEditLastOwnMessage={handleEditLastOwnMainMessage}
|
|
onEditSave={onEditSave}
|
|
onSend={handleSendMessage}
|
|
profiles={profiles}
|
|
placeholder={
|
|
activeChannel?.archivedAt
|
|
? "Archived channels are read-only."
|
|
: activeChannel?.channelType === "forum"
|
|
? "Forum posting is not wired in this pass."
|
|
: activeChannel
|
|
? activeChannel.channelType === "dm" &&
|
|
directMessageIntro
|
|
? `Message ${directMessageIntro.displayName}`
|
|
: `Message #${activeChannel.name}`
|
|
: "Select a channel"
|
|
}
|
|
showTopBorder={false}
|
|
/>
|
|
<div className="h-7 overflow-visible bg-background px-5 pb-1 pt-0">
|
|
<div className="flex h-full w-full items-center gap-2 overflow-visible">
|
|
{hasComposerBotActivity ? (
|
|
<div className="shrink-0 overflow-visible">
|
|
<BotActivityComposerAction
|
|
agents={activityAgents}
|
|
channelId={activeChannel?.id ?? null}
|
|
onOpenAgentSession={onOpenAgentSession}
|
|
openAgentSessionPubkey={openAgentSessionPubkey}
|
|
profiles={profiles}
|
|
typingBotPubkeys={composerBotTypingPubkeys}
|
|
variant="inline"
|
|
/>
|
|
</div>
|
|
) : null}
|
|
{hasTypingActivity ? (
|
|
<TypingIndicatorRow
|
|
channel={activeChannel}
|
|
className="min-w-0 flex-1 px-0 py-0"
|
|
currentPubkey={currentPubkey}
|
|
profiles={profiles}
|
|
typingPubkeys={typingPubkeys}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{canDropInMainColumn && mainComposerMedia.isDragOver ? (
|
|
<DropZoneOverlay className="z-30 rounded-none" />
|
|
) : null}
|
|
</section>
|
|
) : null}
|
|
|
|
{channelManagementOpen && activeChannel
|
|
? (() => {
|
|
const panel = (
|
|
<ChannelManagementSheet
|
|
channel={activeChannel}
|
|
currentPubkey={currentPubkey}
|
|
layout={
|
|
useSplitAuxiliaryPane || isSinglePanelView
|
|
? "split"
|
|
: "overlay"
|
|
}
|
|
onOpenChange={(nextOpen) => {
|
|
if (!nextOpen) {
|
|
onCloseChannelManagement?.();
|
|
}
|
|
}}
|
|
onDeleted={onChannelManagementDeleted}
|
|
open={true}
|
|
/>
|
|
);
|
|
return useSplitAuxiliaryPane ? (
|
|
<RightAuxiliaryPane
|
|
canResetWidth={canResetThreadPanelWidth}
|
|
onResetWidth={onResetThreadPanelWidth}
|
|
onResizeStart={onThreadPanelResizeStart}
|
|
testId="channel-management-auxiliary-pane"
|
|
widthPx={threadPanelWidthPx}
|
|
>
|
|
{panel}
|
|
</RightAuxiliaryPane>
|
|
) : (
|
|
panel
|
|
);
|
|
})()
|
|
: threadHeadMessage
|
|
? (() => {
|
|
const panel = (
|
|
<MessageThreadPanel
|
|
agentPubkeys={agentPubkeys}
|
|
channel={activeChannel}
|
|
channelId={activeChannel?.id ?? null}
|
|
channelName={activeChannel?.name ?? "channel"}
|
|
currentPubkey={currentPubkey}
|
|
disabled={isComposerDisabled}
|
|
editTarget={threadEditTarget}
|
|
firstUnreadReplyId={threadFirstUnreadReplyId}
|
|
isFollowingThread={isFollowingThread}
|
|
isSending={isSending}
|
|
isSinglePanelView={
|
|
useSplitAuxiliaryPane ? false : isSinglePanelView
|
|
}
|
|
layout={useSplitAuxiliaryPane ? "split" : "standalone"}
|
|
onCancelEdit={onCancelEdit}
|
|
onCancelReply={onCancelThreadReply}
|
|
onClose={onCloseThread}
|
|
onDelete={onDelete}
|
|
onEdit={onEdit}
|
|
onEditLastOwnMessage={handleEditLastOwnThreadMessage}
|
|
onEditSave={onEditSave}
|
|
onFollowThread={onFollowThread}
|
|
onMarkUnread={onMarkUnread}
|
|
onExpandReplies={onExpandThreadReplies}
|
|
onSelectReplyTarget={onSelectThreadReplyTarget}
|
|
onSend={onSendThreadReply}
|
|
onScrollTargetResolved={onThreadScrollTargetResolved}
|
|
onToggleReaction={onToggleReaction}
|
|
onUnfollowThread={onUnfollowThread}
|
|
profiles={profiles}
|
|
replyTargetMessage={threadReplyTargetMessage}
|
|
scrollTargetId={threadScrollTargetId}
|
|
threadHead={threadHeadMessage}
|
|
threadHeadVideoReviewContext={threadHeadVideoReviewContext}
|
|
widthPx={threadPanelWidthPx}
|
|
threadReplies={threadMessages}
|
|
threadReplyUnreadCounts={threadReplyUnreadCounts}
|
|
threadTypingPubkeys={threadTypingPubkeys}
|
|
toolbarExtraActions={
|
|
hasThreadComposerBotActivity ? (
|
|
<BotActivityComposerAction
|
|
agents={activityAgents}
|
|
channelId={activeChannel?.id ?? null}
|
|
onOpenAgentSession={onOpenAgentSession}
|
|
openAgentSessionPubkey={openAgentSessionPubkey}
|
|
profiles={profiles}
|
|
typingBotPubkeys={threadComposerBotTypingPubkeys}
|
|
variant="inline"
|
|
/>
|
|
) : null
|
|
}
|
|
/>
|
|
);
|
|
return useSplitAuxiliaryPane ? (
|
|
<RightAuxiliaryPane
|
|
canResetWidth={canResetThreadPanelWidth}
|
|
onResetWidth={onResetThreadPanelWidth}
|
|
onResizeStart={onThreadPanelResizeStart}
|
|
testId="message-thread-panel"
|
|
widthPx={threadPanelWidthPx}
|
|
>
|
|
{panel}
|
|
</RightAuxiliaryPane>
|
|
) : (
|
|
panel
|
|
);
|
|
})()
|
|
: openThreadHeadId && activeChannel
|
|
? (() => {
|
|
const panel = (
|
|
<MessageThreadPanelSkeleton
|
|
isSinglePanelView={
|
|
useSplitAuxiliaryPane ? false : isSinglePanelView
|
|
}
|
|
layout={useSplitAuxiliaryPane ? "split" : "standalone"}
|
|
onClose={onCloseThread}
|
|
widthPx={threadPanelWidthPx}
|
|
/>
|
|
);
|
|
return useSplitAuxiliaryPane ? (
|
|
<RightAuxiliaryPane
|
|
canResetWidth={canResetThreadPanelWidth}
|
|
onResetWidth={onResetThreadPanelWidth}
|
|
onResizeStart={onThreadPanelResizeStart}
|
|
testId="message-thread-panel"
|
|
widthPx={threadPanelWidthPx}
|
|
>
|
|
{panel}
|
|
</RightAuxiliaryPane>
|
|
) : (
|
|
panel
|
|
);
|
|
})()
|
|
: activeChannel && selectedAgent
|
|
? (() => {
|
|
const panel = (
|
|
<AgentSessionThreadPanel
|
|
agent={selectedAgent}
|
|
canInterruptTurn={selectedAgent.canInterruptTurn}
|
|
channel={activeChannel}
|
|
isWorking={botTypingEntries.some(
|
|
(entry) =>
|
|
entry.pubkey.toLowerCase() ===
|
|
selectedAgent.pubkey.toLowerCase(),
|
|
)}
|
|
isSinglePanelView={
|
|
useSplitAuxiliaryPane ? false : isSinglePanelView
|
|
}
|
|
layout={useSplitAuxiliaryPane ? "split" : "standalone"}
|
|
profiles={profiles}
|
|
onBackToProfile={() =>
|
|
onOpenProfilePanel(selectedAgent.pubkey)
|
|
}
|
|
onClose={onCloseAgentSession}
|
|
widthPx={threadPanelWidthPx}
|
|
/>
|
|
);
|
|
return useSplitAuxiliaryPane ? (
|
|
<RightAuxiliaryPane
|
|
canResetWidth={canResetThreadPanelWidth}
|
|
onResetWidth={onResetThreadPanelWidth}
|
|
onResizeStart={onThreadPanelResizeStart}
|
|
testId="agent-session-thread-panel"
|
|
widthPx={threadPanelWidthPx}
|
|
>
|
|
{panel}
|
|
</RightAuxiliaryPane>
|
|
) : (
|
|
panel
|
|
);
|
|
})()
|
|
: profilePanelPubkey
|
|
? (() => {
|
|
const panel = (
|
|
<UserProfilePanel
|
|
currentPubkey={currentPubkey}
|
|
isSinglePanelView={
|
|
useSplitAuxiliaryPane ? false : isSinglePanelView
|
|
}
|
|
layout={useSplitAuxiliaryPane ? "split" : "standalone"}
|
|
onClose={onCloseProfilePanel}
|
|
onOpenDm={onOpenDm}
|
|
pubkey={profilePanelPubkey}
|
|
splitPaneClamp
|
|
widthPx={threadPanelWidthPx}
|
|
/>
|
|
);
|
|
return useSplitAuxiliaryPane ? (
|
|
<RightAuxiliaryPane
|
|
canResetWidth={canResetThreadPanelWidth}
|
|
onResetWidth={onResetThreadPanelWidth}
|
|
onResizeStart={onThreadPanelResizeStart}
|
|
testId="user-profile-panel"
|
|
widthPx={threadPanelWidthPx}
|
|
>
|
|
{panel}
|
|
</RightAuxiliaryPane>
|
|
) : (
|
|
panel
|
|
);
|
|
})()
|
|
: null}
|
|
</div>
|
|
);
|
|
});
|