1164 lines
47 KiB
TypeScript
1164 lines
47 KiB
TypeScript
import { useEffect, useRef, useState } from "react";
|
|
import { Link } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Description as DialogDescription, Title as DialogTitle } from "@radix-ui/react-dialog";
|
|
import {
|
|
FeatherArrowDown,
|
|
FeatherArrowLeft,
|
|
FeatherAtSign,
|
|
FeatherCheckSquare,
|
|
FeatherEdit3,
|
|
FeatherFile,
|
|
FeatherImage,
|
|
FeatherLink,
|
|
FeatherMessageSquare,
|
|
FeatherPaperclip,
|
|
FeatherPin,
|
|
FeatherRefreshCw,
|
|
FeatherSend,
|
|
FeatherSettings,
|
|
FeatherSquare,
|
|
FeatherTrash2,
|
|
FeatherX,
|
|
} from "@subframe/core";
|
|
import {
|
|
chatMessageIdentityKey,
|
|
type ChatAttachmentVM,
|
|
type ChatChannelDetailVM,
|
|
type ChatMentionAutocompleteVM,
|
|
type ChatMentionSuggestionVM,
|
|
type ChatMessageVM,
|
|
} from "@hivegrid/view-models";
|
|
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import type { ChatPendingAttachment } from "~/modules/chat/client/useChatAttachmentUploads";
|
|
import { useChatMessageViewport } from "~/modules/chat/client/useChatMessageViewport";
|
|
import { renderSanitizedChatMarkdown } from "~/utils/html-sanitizer";
|
|
import { Alert } from "~/ui/components/Alert";
|
|
import { Avatar } from "~/ui/components/Avatar";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { ButtonGroup } from "~/ui/components/ButtonGroup";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { LoadingIndicatorSkeleton } from "~/ui/components/LoadingIndicatorSkeleton";
|
|
import { Progress } from "~/ui/components/Progress";
|
|
import { TextArea } from "~/ui/components/TextArea";
|
|
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
|
import { ChatMentionAutocomplete } from "./ChatMentionAutocomplete";
|
|
|
|
export type ChatChannelDetailActions = {
|
|
readonly onBack: () => void;
|
|
readonly onDraftChange: (draft: string, storageKey: string, caret: number) => void;
|
|
readonly onSend: (bodyMarkdown: string) => boolean | void | Promise<boolean | void>;
|
|
readonly onRetryMessage: (clientMessageId: string) => void | Promise<void>;
|
|
readonly onDiscardMessage: (clientMessageId: string) => void;
|
|
readonly onMessageVisibilityChange: (messageId: string, createdAtIso: string, visible: boolean) => void;
|
|
readonly onRetryConnection: () => void | Promise<void>;
|
|
readonly onLoadOlder: (cursor: string) => void | Promise<void>;
|
|
readonly onOpenSettings: () => void;
|
|
readonly onOpenPinned?: () => void;
|
|
readonly onOpenThread?: (messageId: string, href: string | null) => void;
|
|
readonly onToggleReaction?: (messageId: string, emoji: string, active: boolean) => void;
|
|
readonly onTogglePin?: (messageId: string, pinned: boolean) => void;
|
|
readonly onRetryFeature?: (messageId: string) => void;
|
|
readonly onEditMessage?: (messageId: string, body: string) => void;
|
|
readonly onDeleteMessage?: (messageId: string) => void;
|
|
readonly onMentionActiveIndexChange?: (index: number) => void;
|
|
readonly onMentionSelect?: (suggestion: ChatMentionSuggestionVM) => number | null;
|
|
readonly onMentionKeyDown?: (key: "ArrowDown" | "ArrowUp" | "Enter" | "Escape") => boolean;
|
|
readonly onAddFiles?: (files: FileList) => void;
|
|
readonly onAddPhotos?: (files: FileList) => void;
|
|
readonly onStartRecording?: () => void | Promise<void>;
|
|
readonly onStopRecording?: () => void;
|
|
readonly onCancelRecording?: () => void;
|
|
readonly onRetryAttachment?: (clientId: string) => void;
|
|
readonly onRemoveAttachment?: (clientId: string) => void;
|
|
readonly onMarkAsTask?: (messageId: string) => void;
|
|
};
|
|
|
|
export type ChatChannelDetailPageProps = {
|
|
readonly vm: ChatChannelDetailVM;
|
|
readonly actions: ChatChannelDetailActions;
|
|
readonly draft: string;
|
|
readonly sending?: boolean;
|
|
readonly actionErrorKey?: string | null;
|
|
readonly actionSuccessKey?: string | null;
|
|
readonly featureErrorKeys?: Readonly<Record<string, string>>;
|
|
readonly pendingAttachments?: readonly ChatPendingAttachment[];
|
|
readonly isStartingRecording?: boolean;
|
|
readonly isRecording?: boolean;
|
|
readonly recordingDurationSeconds?: number;
|
|
readonly markingTaskMessageId?: string | null;
|
|
readonly focusedMessageId?: string | null;
|
|
readonly scrollStorageKey?: string;
|
|
readonly mentionAutocomplete?: {
|
|
readonly vm: ChatMentionAutocompleteVM | null;
|
|
readonly open: boolean;
|
|
readonly loading: boolean;
|
|
readonly activeIndex: number;
|
|
readonly listboxId: string;
|
|
};
|
|
};
|
|
|
|
function DetailShell({
|
|
title,
|
|
subtitle,
|
|
avatar,
|
|
onBack,
|
|
onOpenSettings,
|
|
onOpenPinned,
|
|
showSettings = false,
|
|
showPinned = false,
|
|
children,
|
|
}: {
|
|
readonly title: React.ReactNode;
|
|
readonly subtitle?: React.ReactNode;
|
|
readonly avatar?: { readonly imageUrl: string | null; readonly fallbackLabel: string };
|
|
readonly onBack: () => void;
|
|
readonly onOpenSettings?: () => void;
|
|
readonly showSettings?: boolean;
|
|
readonly onOpenPinned?: () => void;
|
|
readonly showPinned?: boolean;
|
|
readonly children: React.ReactNode;
|
|
}): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<PageShell uiId="ui.chat.channelDetail" className="mobile:[&_button]:min-h-11 mobile:[&_button]:min-w-11">
|
|
<PageHeader
|
|
icon={
|
|
avatar ? (
|
|
<Avatar size="small" image={avatar.imageUrl ?? undefined}>
|
|
{avatar.fallbackLabel}
|
|
</Avatar>
|
|
) : (
|
|
<FeatherMessageSquare className={PAGE_HEADER_ICON_CLASS} />
|
|
)
|
|
}
|
|
title={title}
|
|
subtitle={subtitle}
|
|
actions={
|
|
<ButtonGroup>
|
|
{showPinned && onOpenPinned ? (
|
|
<Button variant="tertiary" icon={<FeatherPin />} onClick={onOpenPinned}>
|
|
{t("chat.pinned.open")}
|
|
</Button>
|
|
) : null}
|
|
{showSettings && onOpenSettings ? (
|
|
<Button variant="tertiary" icon={<FeatherSettings />} onClick={onOpenSettings}>
|
|
{t("chat.channelSettings.title")}
|
|
</Button>
|
|
) : null}
|
|
<Button variant="tertiary" icon={<FeatherArrowLeft />} onClick={onBack}>
|
|
{t("shared.back")}
|
|
</Button>
|
|
</ButtonGroup>
|
|
}
|
|
/>
|
|
<PageBody>{children}</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
function MessageVisibilityMarker({
|
|
enabled,
|
|
messageId,
|
|
createdAtIso,
|
|
onVisibilityChange,
|
|
children,
|
|
}: {
|
|
readonly enabled: boolean;
|
|
readonly messageId: string;
|
|
readonly createdAtIso: string;
|
|
readonly onVisibilityChange: (messageId: string, createdAtIso: string, visible: boolean) => void;
|
|
readonly children: React.ReactNode;
|
|
}): React.JSX.Element {
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
const onVisibilityChangeRef = useRef(onVisibilityChange);
|
|
|
|
useEffect(() => {
|
|
onVisibilityChangeRef.current = onVisibilityChange;
|
|
}, [onVisibilityChange]);
|
|
|
|
useEffect(() => {
|
|
const element = ref.current;
|
|
if (!enabled || !element || typeof IntersectionObserver === "undefined") return;
|
|
|
|
let visible = false;
|
|
const observer = new IntersectionObserver(
|
|
(entries) => {
|
|
const entry = entries.find((candidate) => candidate.target === element);
|
|
if (!entry) return;
|
|
|
|
const nextVisible = entry.isIntersecting && entry.intersectionRatio >= requiredMessageVisibilityRatio(entry.boundingClientRect.height);
|
|
if (nextVisible === visible) return;
|
|
|
|
visible = nextVisible;
|
|
onVisibilityChangeRef.current(messageId, createdAtIso, visible);
|
|
},
|
|
{ threshold: requiredMessageVisibilityRatio(element.getBoundingClientRect().height) }
|
|
);
|
|
observer.observe(element);
|
|
return () => {
|
|
observer.disconnect();
|
|
if (visible) onVisibilityChangeRef.current(messageId, createdAtIso, false);
|
|
};
|
|
}, [createdAtIso, enabled, messageId]);
|
|
|
|
return <div ref={ref}>{children}</div>;
|
|
}
|
|
|
|
function requiredMessageVisibilityRatio(elementHeight: number): number {
|
|
if (!Number.isFinite(elementHeight) || elementHeight <= 0) return 0.6;
|
|
return Math.min(0.6, 240 / elementHeight);
|
|
}
|
|
|
|
function attachmentIcon(attachment: Pick<ChatAttachmentVM, "kind">): React.JSX.Element {
|
|
if (attachment.kind === "image") return <FeatherImage />;
|
|
if (attachment.kind === "voice") return <FeatherMessageSquare />;
|
|
return <FeatherFile />;
|
|
}
|
|
|
|
function MessageAttachments({ message }: { readonly message: ChatMessageVM }): React.JSX.Element | null {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const isLocalEcho = message.source === "local_echo";
|
|
if (message.attachments.length === 0) return null;
|
|
|
|
return (
|
|
<ButtonGroup align="stack">
|
|
{message.attachments.map((attachment) => {
|
|
if (attachment.scanStatus === "blocked") {
|
|
return <Alert key={attachment.id} variant="error" title={t("chat.attachments.blocked")} notDismissible />;
|
|
}
|
|
if (attachment.scanStatus === "pending") {
|
|
return <Alert key={attachment.id} variant="neutral" title={attachment.fileName} description={t("chat.attachments.pending")} notDismissible />;
|
|
}
|
|
return (
|
|
<Card key={attachment.id} size="small" contentOverflow="wrap">
|
|
{!isLocalEcho && attachment.kind === "image" && attachment.previewHref ? (
|
|
<a href={attachment.downloadHref} target="_blank" rel="noreferrer">
|
|
<img
|
|
src={attachment.previewHref}
|
|
alt={attachment.altText ?? attachment.fileName}
|
|
className="max-h-64 w-full rounded-md object-contain"
|
|
loading="lazy"
|
|
/>
|
|
</a>
|
|
) : null}
|
|
{!isLocalEcho && attachment.kind === "voice" ? (
|
|
// Voice Notes intentionally have no transcript in AK-P15b v1.
|
|
// eslint-disable-next-line jsx-a11y/media-has-caption
|
|
<audio controls preload="metadata" src={attachment.downloadHref} className="w-full">
|
|
<a href={attachment.downloadHref}>{attachment.fileName}</a>
|
|
</audio>
|
|
) : null}
|
|
<ButtonGroup>
|
|
<BadgeFeedback farbe="ghost-neutral">{attachmentIcon(attachment)}</BadgeFeedback>
|
|
<ButtonGroup align="stack" className="min-w-0">
|
|
<span>{attachment.fileName}</span>
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{formatters.number(attachment.sizeBytes, { style: "unit", unit: "byte", unitDisplay: "narrow" })}
|
|
</BadgeFeedback>
|
|
</ButtonGroup>
|
|
{!isLocalEcho && attachment.kind !== "voice" ? (
|
|
<a href={attachment.downloadHref} target="_blank" rel="noreferrer">
|
|
<Button variant="tertiary" size="small">
|
|
{t("shared.open")}
|
|
</Button>
|
|
</a>
|
|
) : null}
|
|
</ButtonGroup>
|
|
</Card>
|
|
);
|
|
})}
|
|
</ButtonGroup>
|
|
);
|
|
}
|
|
|
|
function MessageLinks({ message }: { readonly message: ChatMessageVM }): React.JSX.Element | null {
|
|
if (message.linkPreviews.length === 0) return null;
|
|
return (
|
|
<ButtonGroup align="stack">
|
|
{message.linkPreviews.map((preview) => {
|
|
const canonicalHost = new URL(preview.url).hostname.toLowerCase();
|
|
return (
|
|
<a key={preview.url} href={preview.url} target="_blank" rel="noreferrer">
|
|
<Card size="small" variant="neutral">
|
|
<ButtonGroup>
|
|
<BadgeFeedback farbe="ghost-neutral">
|
|
<FeatherLink />
|
|
</BadgeFeedback>
|
|
<ButtonGroup align="stack">
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{canonicalHost}
|
|
</BadgeFeedback>
|
|
<span>{preview.title ?? preview.url}</span>
|
|
{preview.description ? <span>{preview.description}</span> : null}
|
|
</ButtonGroup>
|
|
</ButtonGroup>
|
|
</Card>
|
|
</a>
|
|
);
|
|
})}
|
|
</ButtonGroup>
|
|
);
|
|
}
|
|
|
|
function DeliveryState({ message, actions }: { readonly message: ChatMessageVM; readonly actions: ChatChannelDetailActions }): React.JSX.Element | null {
|
|
const { t } = useTranslation();
|
|
|
|
if (!message.author?.isCurrentUser || !message.readAggregate) return null;
|
|
|
|
if (message.deliveryState === "failed") {
|
|
return (
|
|
<ButtonGroup align="end" role="alert">
|
|
<BadgeFeedback farbe="subtle-negative" size="small">
|
|
{t(message.failureReasonKey ?? "chat.message.sendFailed")}
|
|
</BadgeFeedback>
|
|
{message.retryable ? (
|
|
<Button variant="tertiary" size="small" icon={<FeatherRefreshCw />} onClick={() => void actions.onRetryMessage(message.clientMessageId)}>
|
|
{t("shared.retry")}
|
|
</Button>
|
|
) : null}
|
|
<Button variant="ghost" size="small" onClick={() => actions.onDiscardMessage(message.clientMessageId)}>
|
|
{t("shared.remove")}
|
|
</Button>
|
|
</ButtonGroup>
|
|
);
|
|
}
|
|
|
|
if (message.deliveryState === "sending") {
|
|
return (
|
|
<BadgeFeedback farbe="subtle-neutral" size="small" role="status">
|
|
{t(message.deliveryStateKey)}
|
|
</BadgeFeedback>
|
|
);
|
|
}
|
|
|
|
if (message.readAggregate.recipientCount > 0) {
|
|
return (
|
|
<BadgeFeedback
|
|
farbe="ghost-neutral"
|
|
size="small"
|
|
data-ui-id="ui.chat.channelDetail.readReceipt"
|
|
data-read-count={message.readAggregate.readCount}
|
|
data-recipient-count={message.readAggregate.recipientCount}
|
|
>
|
|
{t(message.readAggregate.labelKey, {
|
|
readCount: message.readAggregate.readCount,
|
|
recipientCount: message.readAggregate.recipientCount,
|
|
})}
|
|
</BadgeFeedback>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{t(message.deliveryStateKey)}
|
|
</BadgeFeedback>
|
|
);
|
|
}
|
|
|
|
function SystemMessageCard({ message, actions }: { readonly message: ChatMessageVM; readonly actions: ChatChannelDetailActions }): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const systemEvent = message.systemEvent;
|
|
const eventLabel = t(systemEvent?.labelKey ?? "chat.systemEvent.generic", systemEvent?.values ?? {});
|
|
const eventBadge = (
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{eventLabel}
|
|
</BadgeFeedback>
|
|
);
|
|
|
|
return (
|
|
<MessageVisibilityMarker
|
|
enabled={message.source !== "local_echo" && message.deliveryState === "sent"}
|
|
messageId={message.id}
|
|
createdAtIso={message.createdAtIso}
|
|
onVisibilityChange={actions.onMessageVisibilityChange}
|
|
>
|
|
<ButtonGroup
|
|
align="center"
|
|
role="note"
|
|
data-message-id={message.id}
|
|
data-system-event-kind={systemEvent?.kind ?? "unknown"}
|
|
data-ui-id="ui.chat.channelDetail.systemMessage"
|
|
>
|
|
{systemEvent?.href ? <Link to={systemEvent.href}>{eventBadge}</Link> : eventBadge}
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{formatters.date(message.createdAtIso, { hour: "2-digit", minute: "2-digit" })}
|
|
</BadgeFeedback>
|
|
</ButtonGroup>
|
|
</MessageVisibilityMarker>
|
|
);
|
|
}
|
|
|
|
function MessageCard({
|
|
message,
|
|
actions,
|
|
featureErrorKey,
|
|
markingTaskMessageId,
|
|
focused,
|
|
}: {
|
|
readonly message: ChatMessageVM;
|
|
readonly actions: ChatChannelDetailActions;
|
|
readonly featureErrorKey?: string;
|
|
readonly markingTaskMessageId?: string | null;
|
|
readonly focused: boolean;
|
|
}): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const [editOpen, setEditOpen] = useState(false);
|
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
const [editDraft, setEditDraft] = useState(message.bodyMarkdown ?? "");
|
|
if (message.bodyFormat === "system" || message.author === null) {
|
|
return <SystemMessageCard message={message} actions={actions} />;
|
|
}
|
|
const isOwn = message.author.isCurrentUser;
|
|
const renderedBody = message.bodyMarkdown ? replaceMentionTokensWithLabels(message.bodyMarkdown, message.mentions) : null;
|
|
|
|
return (
|
|
<MessageVisibilityMarker
|
|
enabled={message.source !== "local_echo" && message.deliveryState === "sent" && message.deletedAtIso === null}
|
|
messageId={message.id}
|
|
createdAtIso={message.createdAtIso}
|
|
onVisibilityChange={actions.onMessageVisibilityChange}
|
|
>
|
|
<>
|
|
<ButtonGroup
|
|
id={`message-${message.id}`}
|
|
align={isOwn ? "end" : "start"}
|
|
data-message-id={message.id}
|
|
data-focused={focused ? "true" : undefined}
|
|
tabIndex={-1}
|
|
className={focused ? "ring-brand-primary scroll-mt-24 rounded-lg ring-2" : "scroll-mt-24"}
|
|
>
|
|
{!isOwn ? (
|
|
<Avatar size="small" image={message.author.avatar.imageUrl ?? undefined}>
|
|
{message.author.avatar.fallbackLabel}
|
|
</Avatar>
|
|
) : null}
|
|
<Card
|
|
variant={message.deliveryState === "failed" ? "negative" : isOwn ? "information" : "default"}
|
|
contentOverflow="wrap"
|
|
data-delivery-state={message.deliveryState}
|
|
data-transport-source={message.source}
|
|
>
|
|
<ButtonGroup>
|
|
<span>{message.author.displayName}</span>
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{formatters.date(message.createdAtIso, { hour: "2-digit", minute: "2-digit" })}
|
|
</BadgeFeedback>
|
|
{message.editedAtIso ? (
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{t("chat.message.edited")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
{message.pin ? (
|
|
<BadgeFeedback farbe="ghost-neutral" size="small" aria-label={t("chat.message.pinned")}>
|
|
<FeatherPin aria-hidden="true" />
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</ButtonGroup>
|
|
|
|
{message.tombstoneKey ? (
|
|
<Alert variant="neutral" textSize="small" title={t(message.tombstoneKey)} notDismissible />
|
|
) : renderedBody ? (
|
|
<div data-ui-id="ui.chat.channelDetail.messageBody" dangerouslySetInnerHTML={{ __html: renderSanitizedChatMarkdown(renderedBody) }} />
|
|
) : null}
|
|
|
|
{message.mentions.length > 0 ? (
|
|
<ButtonGroup>
|
|
{message.mentions.map((mention) => {
|
|
const badge = (
|
|
<BadgeFeedback farbe="subtle-information" size="small">
|
|
<FeatherAtSign aria-hidden="true" /> {mention.label}
|
|
</BadgeFeedback>
|
|
);
|
|
return mention.href ? (
|
|
<Link key={`${mention.kind}:${mention.id}`} to={mention.href} aria-label={mention.label}>
|
|
{badge}
|
|
</Link>
|
|
) : (
|
|
<span key={`${mention.kind}:${mention.id}`}>{badge}</span>
|
|
);
|
|
})}
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
<MessageAttachments message={message} />
|
|
<MessageLinks message={message} />
|
|
|
|
{featureErrorKey ? (
|
|
<ButtonGroup align="stack" data-ui-id="ui.chat.channelDetail.featureError">
|
|
<Alert variant="error" title={t(featureErrorKey)} notDismissible />
|
|
{actions.onRetryFeature ? (
|
|
<Button variant="tertiary" size="small" icon={<FeatherRefreshCw />} onClick={() => actions.onRetryFeature?.(message.id)}>
|
|
{t("shared.retry")}
|
|
</Button>
|
|
) : null}
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
{message.reactions.length > 0 || message.thread ? (
|
|
<ButtonGroup>
|
|
{message.reactions.map((reaction) => (
|
|
<Button
|
|
key={reaction.emoji}
|
|
variant={reaction.reactedByViewer ? "secondary" : "tertiary"}
|
|
size="small"
|
|
disabled={!message.actions.canReact}
|
|
onClick={() => actions.onToggleReaction?.(message.id, reaction.emoji, !reaction.reactedByViewer)}
|
|
>
|
|
{reaction.emoji} {reaction.count}
|
|
</Button>
|
|
))}
|
|
{message.thread ? (
|
|
<Link to={message.thread.href}>
|
|
<BadgeFeedback farbe="subtle-information" size="small">
|
|
{t("chat.message.threadReplies", { count: message.thread.replyCount })}
|
|
</BadgeFeedback>
|
|
</Link>
|
|
) : null}
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
{message.actions.canReact ||
|
|
message.actions.canReply ||
|
|
message.actions.canPin ||
|
|
message.actions.canMarkAsTask ||
|
|
message.actions.canEdit ||
|
|
message.actions.canDelete ? (
|
|
<ButtonGroup>
|
|
{message.actions.canReact ? (
|
|
<Button
|
|
variant="ghost"
|
|
size="small"
|
|
onClick={() => {
|
|
const current = message.reactions.find((reaction) => reaction.emoji === "👍");
|
|
actions.onToggleReaction?.(message.id, "👍", !(current?.reactedByViewer ?? false));
|
|
}}
|
|
>
|
|
👍 {t("chat.reaction.quick")}
|
|
</Button>
|
|
) : null}
|
|
{message.actions.canReply ? (
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherMessageSquare />}
|
|
onClick={() => actions.onOpenThread?.(message.id, message.thread?.href ?? null)}
|
|
>
|
|
{t("chat.thread.reply")}
|
|
</Button>
|
|
) : null}
|
|
{message.actions.canPin ? (
|
|
<Button variant="tertiary" size="small" icon={<FeatherPin />} onClick={() => actions.onTogglePin?.(message.id, message.pin === null)}>
|
|
{t(message.pin ? "chat.pinned.unpin" : "chat.pinned.pin")}
|
|
</Button>
|
|
) : null}
|
|
{message.actions.canMarkAsTask ? (
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherCheckSquare />}
|
|
loading={message.id === markingTaskMessageId}
|
|
disabled={markingTaskMessageId !== null && markingTaskMessageId !== undefined && message.id !== markingTaskMessageId}
|
|
onClick={() => actions.onMarkAsTask?.(message.id)}
|
|
>
|
|
{t("chat.task.mark")}
|
|
</Button>
|
|
) : null}
|
|
{message.actions.canEdit && actions.onEditMessage ? (
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherEdit3 />}
|
|
onClick={() => {
|
|
setEditDraft(message.bodyMarkdown ?? "");
|
|
setEditOpen(true);
|
|
}}
|
|
>
|
|
{t("chat.message.edit")}
|
|
</Button>
|
|
) : null}
|
|
{message.actions.canDelete && actions.onDeleteMessage ? (
|
|
<Button variant="tertiary" size="small" icon={<FeatherTrash2 />} onClick={() => setDeleteOpen(true)}>
|
|
{t("chat.message.delete")}
|
|
</Button>
|
|
) : null}
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
<DeliveryState message={message} actions={actions} />
|
|
</Card>
|
|
</ButtonGroup>
|
|
<Dialog open={editOpen} onOpenChange={(open: boolean) => setEditOpen(open)}>
|
|
<Dialog.Content className="w-[520px] max-w-[90vw] p-4">
|
|
<ButtonGroup align="stack">
|
|
<DialogTitle className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("chat.message.editTitle")}</DialogTitle>
|
|
<TextArea label={t("chat.message.editTitle")} showLabel={false}>
|
|
<TextArea.Input value={editDraft} placeholder={t("chat.message.editPlaceholder")} onChange={(event) => setEditDraft(event.target.value)} />
|
|
</TextArea>
|
|
<ButtonGroup>
|
|
<Button variant="tertiary" onClick={() => setEditOpen(false)}>
|
|
{t("chat.message.cancel")}
|
|
</Button>
|
|
<Button
|
|
variant="primary"
|
|
disabled={editDraft.trim().length === 0 || editDraft === message.bodyMarkdown}
|
|
onClick={() => {
|
|
actions.onEditMessage?.(message.id, editDraft);
|
|
setEditOpen(false);
|
|
}}
|
|
>
|
|
{t("chat.message.save")}
|
|
</Button>
|
|
</ButtonGroup>
|
|
</ButtonGroup>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
<Dialog open={deleteOpen} onOpenChange={(open: boolean) => setDeleteOpen(open)}>
|
|
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
|
<ButtonGroup align="stack">
|
|
<DialogTitle className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("chat.message.deleteConfirmTitle")}</DialogTitle>
|
|
<DialogDescription className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("chat.message.deleteConfirmBody")}
|
|
</DialogDescription>
|
|
<ButtonGroup>
|
|
<Button variant="tertiary" onClick={() => setDeleteOpen(false)}>
|
|
{t("chat.message.cancel")}
|
|
</Button>
|
|
<Button
|
|
variant="destructive"
|
|
onClick={() => {
|
|
actions.onDeleteMessage?.(message.id);
|
|
setDeleteOpen(false);
|
|
}}
|
|
>
|
|
{t("chat.message.delete")}
|
|
</Button>
|
|
</ButtonGroup>
|
|
</ButtonGroup>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</>
|
|
</MessageVisibilityMarker>
|
|
);
|
|
}
|
|
|
|
function messageViewportKey(message: ChatMessageVM): string {
|
|
return chatMessageIdentityKey(message);
|
|
}
|
|
|
|
function replaceMentionTokensWithLabels(markdown: string, mentions: ChatMessageVM["mentions"]): string {
|
|
const labels = new Map(mentions.map((mention) => [`${mention.kind}\u0000${mention.id}`, mention.label]));
|
|
return markdown.replace(/<@(user|project|contact|company):([A-Za-z0-9._-]{1,500})>/gu, (_token, kind: string, id: string) => {
|
|
const label = labels.get(`${kind}\u0000${id}`) ?? "@";
|
|
return `@${label.replace(/([\\`*_{}\[\]()<>#+\-.!|])/gu, "\\$1")}`;
|
|
});
|
|
}
|
|
|
|
function messageAnnouncementPreview(message: ChatMessageVM, fallback: string): string {
|
|
if (!message.bodyMarkdown) return fallback;
|
|
const plainText = message.bodyMarkdown
|
|
.replace(/<[^>]*>/g, " ")
|
|
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
|
|
.replace(/[`*_~>#]/g, " ")
|
|
.replace(/^\s*[-+]\s+/gm, "")
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
return plainText.slice(0, 160) || fallback;
|
|
}
|
|
|
|
function useAnnouncementKey(latestKey: string | null): string | null {
|
|
const [announcementKey, setAnnouncementKey] = useState<string | null>(null);
|
|
useEffect(() => {
|
|
setAnnouncementKey(null);
|
|
if (!latestKey) return;
|
|
const handle = setTimeout(() => setAnnouncementKey(latestKey), 0);
|
|
return () => clearTimeout(handle);
|
|
}, [latestKey]);
|
|
return announcementKey;
|
|
}
|
|
|
|
function ConnectionState({
|
|
vm,
|
|
onRetry,
|
|
}: {
|
|
readonly vm: NonNullable<ChatChannelDetailVM["data"]>["connection"];
|
|
readonly onRetry: () => void | Promise<void>;
|
|
}): React.JSX.Element | null {
|
|
const { t } = useTranslation();
|
|
const liveStatus = (
|
|
<span
|
|
className="sr-only"
|
|
role={vm.state === "blocked" ? "alert" : "status"}
|
|
aria-live={vm.state === "blocked" ? "assertive" : "polite"}
|
|
aria-atomic="true"
|
|
data-ui-id="ui.chat.channelDetail.connectionStatus"
|
|
>
|
|
{t(vm.stateLabelKey)}
|
|
</span>
|
|
);
|
|
if (vm.state === "online") return liveStatus;
|
|
|
|
const variant = vm.state === "blocked" ? "error" : vm.state === "connecting" ? "neutral" : "warning";
|
|
return (
|
|
<>
|
|
{liveStatus}
|
|
<Alert
|
|
variant={variant}
|
|
title={t(vm.stateLabelKey)}
|
|
description={vm.state === "reconnecting" ? t("chat.connection.reconnectAttempt", { count: vm.reconnectAttempt }) : undefined}
|
|
actions={
|
|
vm.canRetry ? (
|
|
<Button variant="tertiary" size="small" onClick={() => void onRetry()}>
|
|
{t("shared.retry")}
|
|
</Button>
|
|
) : undefined
|
|
}
|
|
notDismissible={!vm.canRetry}
|
|
data-connection-state={vm.state}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function PendingAttachmentQueue({
|
|
attachments,
|
|
actions,
|
|
}: {
|
|
readonly attachments: readonly ChatPendingAttachment[];
|
|
readonly actions: ChatChannelDetailActions;
|
|
}): React.JSX.Element | null {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
if (attachments.length === 0) return null;
|
|
|
|
return (
|
|
<ButtonGroup align="stack" role="status" aria-live="polite" data-ui-id="ui.chat.channelDetail.pendingAttachments">
|
|
{attachments.map((attachment) => (
|
|
<Card key={attachment.clientId} size="small" contentOverflow="wrap">
|
|
<ButtonGroup className="mobile:flex-wrap min-w-0">
|
|
<BadgeFeedback farbe="ghost-neutral">{attachmentIcon(attachment)}</BadgeFeedback>
|
|
<ButtonGroup align="stack" className="min-w-0 grow">
|
|
<span className="max-w-full truncate">{attachment.fileName}</span>
|
|
<BadgeFeedback farbe="ghost-neutral" size="small">
|
|
{formatters.number(attachment.sizeBytes, { style: "unit", unit: "byte", unitDisplay: "narrow" })}
|
|
</BadgeFeedback>
|
|
</ButtonGroup>
|
|
{attachment.status === "error" ? (
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
className="mobile:min-h-11"
|
|
icon={<FeatherRefreshCw />}
|
|
onClick={() => actions.onRetryAttachment?.(attachment.clientId)}
|
|
>
|
|
{t("chat.attachments.retry")}
|
|
</Button>
|
|
) : null}
|
|
<Button
|
|
variant="ghost"
|
|
size="small"
|
|
className="mobile:min-h-11 mobile:min-w-11"
|
|
icon={<FeatherX />}
|
|
aria-label={t("chat.attachments.remove")}
|
|
onClick={() => actions.onRemoveAttachment?.(attachment.clientId)}
|
|
/>
|
|
</ButtonGroup>
|
|
{attachment.status === "uploading" || attachment.status === "processing" ? (
|
|
<Progress
|
|
value={attachment.progress}
|
|
state="uploading"
|
|
className="w-full"
|
|
label={attachment.fileName}
|
|
statusText={
|
|
attachment.status === "processing" ? t("chat.attachments.processing") : t("chat.attachments.uploadProgress", { progress: attachment.progress })
|
|
}
|
|
/>
|
|
) : attachment.status === "error" ? (
|
|
<Alert variant="error" title={t(attachment.errorKey ?? "chat.attachments.uploadFailed")} notDismissible />
|
|
) : (
|
|
<BadgeFeedback farbe="subtle-positive" size="small">
|
|
{t("chat.attachments.ready")}
|
|
</BadgeFeedback>
|
|
)}
|
|
</Card>
|
|
))}
|
|
</ButtonGroup>
|
|
);
|
|
}
|
|
|
|
export function ChatChannelDetailPage({
|
|
vm,
|
|
actions,
|
|
draft,
|
|
sending = false,
|
|
actionErrorKey = null,
|
|
actionSuccessKey = null,
|
|
featureErrorKeys = {},
|
|
pendingAttachments = [],
|
|
isStartingRecording = false,
|
|
isRecording = false,
|
|
recordingDurationSeconds = 0,
|
|
markingTaskMessageId = null,
|
|
focusedMessageId = null,
|
|
scrollStorageKey,
|
|
mentionAutocomplete,
|
|
}: ChatChannelDetailPageProps): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const composerInputRef = useRef<HTMLTextAreaElement>(null);
|
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
const photoInputRef = useRef<HTMLInputElement>(null);
|
|
const viewport = useChatMessageViewport({
|
|
messages:
|
|
vm.data?.messages.map((message) => ({
|
|
key: messageViewportKey(message),
|
|
isCurrentUser: message.author?.isCurrentUser ?? false,
|
|
})) ?? [],
|
|
storageKey: scrollStorageKey,
|
|
});
|
|
const announcementKey = useAnnouncementKey(viewport.latestRemoteAnnouncementKey);
|
|
|
|
useEffect(() => {
|
|
if (!focusedMessageId || vm.status !== "ready" || !vm.data.messages.some((message) => message.id === focusedMessageId)) return;
|
|
const handle = window.setTimeout(() => {
|
|
const target = document.getElementById(`message-${focusedMessageId}`);
|
|
target?.scrollIntoView({ block: "center" });
|
|
target?.focus({ preventScroll: true });
|
|
}, 0);
|
|
return () => window.clearTimeout(handle);
|
|
}, [focusedMessageId, vm]);
|
|
|
|
if (vm.status === "idle" || vm.status === "loading") {
|
|
return (
|
|
<DetailShell title={t("chat.titleFallback")} onBack={actions.onBack}>
|
|
<LoadingIndicatorSkeleton variant="list" role="status" aria-label={t("shared.loading")} data-ui-id="ui.chat.channelDetail.loading" />
|
|
</DetailShell>
|
|
);
|
|
}
|
|
|
|
if (vm.status === "error") {
|
|
return (
|
|
<DetailShell title={t("chat.titleFallback")} onBack={actions.onBack}>
|
|
<EmptyState
|
|
outlined
|
|
variant="error"
|
|
title={t("shared.error")}
|
|
body={t(vm.error.messageKey)}
|
|
action={
|
|
<Button variant="tertiary" onClick={() => void actions.onRetryConnection()}>
|
|
{t("shared.retry")}
|
|
</Button>
|
|
}
|
|
data-ui-id="ui.chat.channelDetail.error"
|
|
/>
|
|
</DetailShell>
|
|
);
|
|
}
|
|
|
|
if (vm.status === "empty" || !vm.data) {
|
|
return (
|
|
<DetailShell title={t("chat.titleFallback")} onBack={actions.onBack}>
|
|
<EmptyState outlined title={t("chat.channel.empty.headline")} body={t("chat.channel.empty.body")} />
|
|
</DetailShell>
|
|
);
|
|
}
|
|
|
|
const { composer, connection, header, history, messageGroups, presence, typingLabels } = vm.data;
|
|
const onlineCount = presence.filter((entry) => entry.status === "online").length;
|
|
const awayCount = presence.length - onlineCount;
|
|
const visibleTypingLabels = typingLabels.slice(0, 2);
|
|
const remainingTypingCount = Math.max(0, typingLabels.length - visibleTypingLabels.length);
|
|
const remoteAnnouncementMessage = announcementKey ? vm.data.messages.find((message) => messageViewportKey(message) === announcementKey) : null;
|
|
const hasReadyAttachment = pendingAttachments.some((attachment) => attachment.status === "ready" && attachment.fileId !== null);
|
|
const hasBlockingAttachment = pendingAttachments.some((attachment) => attachment.status !== "ready");
|
|
|
|
function changeDraft(value: string, caret: number): void {
|
|
actions.onDraftChange(value, composer.draftStorageKey, caret);
|
|
}
|
|
|
|
function selectMention(suggestion: ChatMentionSuggestionVM): void {
|
|
const nextCaret = actions.onMentionSelect?.(suggestion) ?? null;
|
|
if (nextCaret === null) return;
|
|
requestAnimationFrame(() => {
|
|
composerInputRef.current?.focus();
|
|
composerInputRef.current?.setSelectionRange(nextCaret, nextCaret);
|
|
});
|
|
}
|
|
|
|
async function sendDraft(): Promise<void> {
|
|
const body = draft.trim();
|
|
if ((!body && !hasReadyAttachment) || hasBlockingAttachment || !composer.canSend || sending) return;
|
|
try {
|
|
await actions.onSend(body);
|
|
} catch {
|
|
// The controlled draft remains visible. The route surfaces transport errors.
|
|
} finally {
|
|
composerInputRef.current?.focus();
|
|
}
|
|
}
|
|
|
|
return (
|
|
<DetailShell
|
|
title={header.title}
|
|
subtitle={header.subtitle ?? t(`chat.channel.kind.${header.kind}`)}
|
|
avatar={header.avatar}
|
|
onBack={actions.onBack}
|
|
onOpenSettings={actions.onOpenSettings}
|
|
onOpenPinned={actions.onOpenPinned}
|
|
showSettings={header.settingsHref !== null}
|
|
showPinned={header.pinnedHref !== null}
|
|
>
|
|
{header.dmAuditBannerKey ? (
|
|
<Alert variant="warning" title={t(header.dmAuditBannerKey)} notDismissible data-ui-id="ui.chat.channelDetail.auditBanner" />
|
|
) : null}
|
|
|
|
<ConnectionState vm={connection} onRetry={actions.onRetryConnection} />
|
|
{actionErrorKey ? <Alert variant="error" title={t(actionErrorKey)} notDismissible /> : null}
|
|
{actionSuccessKey ? <Alert variant="success" title={t(actionSuccessKey)} notDismissible /> : null}
|
|
|
|
{presence.length > 0 ? (
|
|
<ButtonGroup role="group" aria-label={t("chat.channel.presenceAria")} data-ui-id="ui.chat.channelDetail.presence">
|
|
{onlineCount > 0 ? (
|
|
<BadgeFeedback farbe="subtle-positive" size="small">
|
|
{t("chat.channel.presenceOnline", { count: onlineCount })}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
{awayCount > 0 ? (
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t("chat.channel.presenceAway", { count: awayCount })}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
<div ref={viewport.logRootRef} role="log" aria-label={t("chat.channel.messagesAria")} aria-live="off" data-ui-id="ui.chat.channelDetail.messages">
|
|
<ButtonGroup align="stack">
|
|
{history.hasOlder && history.olderCursor ? (
|
|
<ButtonGroup align="center">
|
|
<Button variant="tertiary" onClick={() => void actions.onLoadOlder(history.olderCursor!)}>
|
|
{t(vm.data.loadOlderLabelKey)}
|
|
</Button>
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
{messageGroups.length === 0 ? (
|
|
<EmptyState outlined title={t(vm.data.emptyHeadlineKey)} body={t(vm.data.emptyBodyKey)} />
|
|
) : (
|
|
messageGroups.map((group) => (
|
|
<section key={group.dateIso} aria-label={formatters.date(group.dateIso)}>
|
|
<ButtonGroup align="center" aria-hidden="true">
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{formatters.date(group.dateIso, { dateStyle: "medium" })}
|
|
</BadgeFeedback>
|
|
</ButtonGroup>
|
|
<ButtonGroup align="stack">
|
|
{group.messages.map((message) => (
|
|
<MessageCard
|
|
key={chatMessageIdentityKey(message)}
|
|
message={message}
|
|
actions={actions}
|
|
featureErrorKey={featureErrorKeys[message.id]}
|
|
markingTaskMessageId={markingTaskMessageId}
|
|
focused={message.id === focusedMessageId}
|
|
/>
|
|
))}
|
|
</ButtonGroup>
|
|
</section>
|
|
))
|
|
)}
|
|
</ButtonGroup>
|
|
</div>
|
|
|
|
{remoteAnnouncementMessage ? (
|
|
<span key={announcementKey} className="sr-only" role="status" aria-live="polite" aria-atomic="true">
|
|
{remoteAnnouncementMessage.systemEvent
|
|
? t("chat.channel.newSystemMessageAnnouncement", {
|
|
message: t(remoteAnnouncementMessage.systemEvent.labelKey, remoteAnnouncementMessage.systemEvent.values),
|
|
})
|
|
: t("chat.channel.newMessageAnnouncement", {
|
|
author: remoteAnnouncementMessage.author?.displayName ?? t("chat.participant.unknown"),
|
|
preview: messageAnnouncementPreview(
|
|
remoteAnnouncementMessage,
|
|
remoteAnnouncementMessage.tombstoneKey ? t(remoteAnnouncementMessage.tombstoneKey) : t("chat.attachments.sentFallback")
|
|
),
|
|
})}
|
|
</span>
|
|
) : null}
|
|
|
|
{viewport.newMessageCount > 0 ? (
|
|
<ButtonGroup align="stack" data-ui-id="ui.chat.channelDetail.newMessages">
|
|
<span className="sr-only" role="status" aria-live="polite">
|
|
{t(vm.data.newMessagesLabelKey, { count: viewport.newMessageCount })}
|
|
</span>
|
|
<Button variant="tertiary" icon={<FeatherArrowDown />} onClick={viewport.jumpToLatest}>
|
|
{t(vm.data.newMessagesLabelKey, { count: viewport.newMessageCount })}
|
|
</Button>
|
|
</ButtonGroup>
|
|
) : null}
|
|
|
|
{typingLabels.length > 0 ? (
|
|
<Alert
|
|
variant="information"
|
|
textSize="small"
|
|
title={
|
|
remainingTypingCount > 0
|
|
? t("chat.channel.typingOverflow", { names: visibleTypingLabels.join(", "), count: remainingTypingCount })
|
|
: t("chat.channel.typing", { count: visibleTypingLabels.length, names: visibleTypingLabels.join(", ") })
|
|
}
|
|
notDismissible
|
|
data-ui-id="ui.chat.channelDetail.typing"
|
|
/>
|
|
) : null}
|
|
|
|
<section
|
|
className="mobile:sticky mobile:bottom-0 mobile:z-10 mobile:-mx-4 mobile:bg-surface-neutral-primary mobile:px-4 mobile:pb-[max(1rem,env(safe-area-inset-bottom))] mobile:pt-2"
|
|
data-ui-id="ui.chat.channelDetail.composerDock"
|
|
>
|
|
<Card data-ui-id="ui.chat.channelDetail.composer">
|
|
{!composer.enabled && composer.disabledReasonKey ? <Alert variant="neutral" title={t(composer.disabledReasonKey)} notDismissible /> : null}
|
|
<PendingAttachmentQueue attachments={pendingAttachments} actions={actions} />
|
|
<TextArea error={draft.length > composer.maxBodyLength} errorText={t("chat.composer.tooLong", { max: composer.maxBodyLength })}>
|
|
<TextArea.Input
|
|
ref={composerInputRef}
|
|
value={draft}
|
|
maxLength={composer.maxBodyLength}
|
|
disabled={!composer.enabled || sending}
|
|
placeholder={t(composer.placeholderKey)}
|
|
aria-label={t(composer.placeholderKey)}
|
|
onChange={(event) => changeDraft(event.target.value, event.target.selectionStart ?? event.target.value.length)}
|
|
onKeyDown={(event) => {
|
|
if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
|
|
if (
|
|
actions.onMentionKeyDown &&
|
|
["ArrowDown", "ArrowUp", "Enter", "Escape"].includes(event.key) &&
|
|
actions.onMentionKeyDown(event.key as "ArrowDown" | "ArrowUp" | "Enter" | "Escape")
|
|
) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
event.preventDefault();
|
|
void sendDraft();
|
|
}
|
|
}}
|
|
role="combobox"
|
|
aria-autocomplete="list"
|
|
aria-expanded={mentionAutocomplete?.open ?? false}
|
|
aria-controls={mentionAutocomplete?.open ? mentionAutocomplete.listboxId : undefined}
|
|
aria-activedescendant={
|
|
mentionAutocomplete?.open && !mentionAutocomplete.loading && (mentionAutocomplete.vm?.total ?? 0) > 0
|
|
? `${mentionAutocomplete.listboxId}-option-${mentionAutocomplete.activeIndex}`
|
|
: undefined
|
|
}
|
|
/>
|
|
</TextArea>
|
|
{mentionAutocomplete ? (
|
|
<ChatMentionAutocomplete
|
|
{...mentionAutocomplete}
|
|
actions={{
|
|
onSelect: selectMention,
|
|
onActiveIndexChange: actions.onMentionActiveIndexChange ?? (() => undefined),
|
|
}}
|
|
/>
|
|
) : null}
|
|
<ButtonGroup align="space-between" className="mobile:flex-wrap">
|
|
<ButtonGroup className="mobile:flex-wrap">
|
|
{composer.canAttachFiles ? (
|
|
<>
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
multiple
|
|
className="hidden"
|
|
onChange={(event) => {
|
|
if (event.currentTarget.files) actions.onAddFiles?.(event.currentTarget.files);
|
|
event.currentTarget.value = "";
|
|
}}
|
|
data-ui-id="ui.chat.channelDetail.fileInput"
|
|
/>
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
className="mobile:min-h-11"
|
|
icon={<FeatherPaperclip />}
|
|
disabled={!composer.enabled || sending}
|
|
onClick={() => fileInputRef.current?.click()}
|
|
>
|
|
{t("chat.attachments.addFile")}
|
|
</Button>
|
|
<input
|
|
ref={photoInputRef}
|
|
type="file"
|
|
accept="image/*"
|
|
capture="environment"
|
|
className="hidden"
|
|
onChange={(event) => {
|
|
if (event.currentTarget.files) actions.onAddPhotos?.(event.currentTarget.files);
|
|
event.currentTarget.value = "";
|
|
}}
|
|
data-ui-id="ui.chat.channelDetail.photoInput"
|
|
/>
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
className="mobile:min-h-11"
|
|
icon={<FeatherImage />}
|
|
disabled={!composer.enabled || sending}
|
|
onClick={() => photoInputRef.current?.click()}
|
|
>
|
|
{t("chat.attachments.takePhoto")}
|
|
</Button>
|
|
</>
|
|
) : null}
|
|
{composer.canRecordVoice ? (
|
|
<ButtonGroup>
|
|
<Button
|
|
variant={isRecording ? "warning" : "tertiary"}
|
|
size="small"
|
|
className="mobile:min-h-11"
|
|
icon={isRecording ? <FeatherSquare /> : <FeatherMessageSquare />}
|
|
loading={isStartingRecording}
|
|
disabled={!composer.enabled || sending || isStartingRecording}
|
|
onClick={() => (isRecording ? actions.onStopRecording?.() : void actions.onStartRecording?.())}
|
|
>
|
|
{isRecording
|
|
? t("chat.attachments.recordingDuration", { duration: formatRecordingDuration(recordingDurationSeconds) })
|
|
: t("chat.attachments.startRecording")}
|
|
</Button>
|
|
{isRecording ? (
|
|
<Button variant="ghost" size="small" className="mobile:min-h-11" icon={<FeatherX />} onClick={() => actions.onCancelRecording?.()}>
|
|
{t("chat.attachments.cancelRecording")}
|
|
</Button>
|
|
) : null}
|
|
</ButtonGroup>
|
|
) : null}
|
|
</ButtonGroup>
|
|
<Button
|
|
className="mobile:min-h-11"
|
|
icon={<FeatherSend />}
|
|
loading={sending}
|
|
disabled={!composer.canSend || (!draft.trim() && !hasReadyAttachment) || hasBlockingAttachment || sending}
|
|
onClick={() => void sendDraft()}
|
|
>
|
|
{t("shared.send")}
|
|
</Button>
|
|
</ButtonGroup>
|
|
</Card>
|
|
</section>
|
|
</DetailShell>
|
|
);
|
|
}
|
|
|
|
function formatRecordingDuration(durationSeconds: number): string {
|
|
const safeSeconds = Math.max(0, Math.floor(durationSeconds));
|
|
return `${Math.floor(safeSeconds / 60)}:${String(safeSeconds % 60).padStart(2, "0")}`;
|
|
}
|