Let authors edit and delete their own chat messages
The editMessage/deleteMessage IPC and their audit events existed but had no UI. Add an inline editor and delete control on a member's own, non-deleted messages; show an edited marker and render deleted messages as a muted placeholder. Thread the handlers from ChatPage through the timeline.
This commit is contained in:
1 parent
7c5978d5df
commit
b65e059da6
4 files changed
+86
-7
No files matched your search
@@ -207,6 +207,23 @@ export function ChatPage({ snapshot, actions }: PageProps) {
|
|||||||
decidedByEmployeeId: employee.id,
|
decidedByEmployeeId: employee.id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const editChatMessage = (messageId: string, bodyMd: string) =>
|
||||||
|
void actions.run(() => window.agentCompany.editMessage({
|
||||||
|
orgId,
|
||||||
|
messageId,
|
||||||
|
actorType: "employee",
|
||||||
|
actorId: employee.id,
|
||||||
|
bodyMd,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const deleteChatMessage = (messageId: string) =>
|
||||||
|
void actions.run(() => window.agentCompany.deleteMessage({
|
||||||
|
orgId,
|
||||||
|
messageId,
|
||||||
|
actorType: "employee",
|
||||||
|
actorId: employee.id,
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="split-main">
|
<div className="split-main">
|
||||||
<ChatSidebar
|
<ChatSidebar
|
||||||
@@ -236,10 +253,13 @@ export function ChatPage({ snapshot, actions }: PageProps) {
|
|||||||
files={files}
|
files={files}
|
||||||
context={{ employees, agents }}
|
context={{ employees, agents }}
|
||||||
attachmentFileId={attachmentFileId}
|
attachmentFileId={attachmentFileId}
|
||||||
|
currentEmployeeId={employee.id}
|
||||||
onAttachmentChange={setAttachmentFileId}
|
onAttachmentChange={setAttachmentFileId}
|
||||||
onOpenThread={setOpenThreadId}
|
onOpenThread={setOpenThreadId}
|
||||||
onApprove={(approvalId) => decideApproval(approvalId, "approved")}
|
onApprove={(approvalId) => decideApproval(approvalId, "approved")}
|
||||||
onDecline={(approvalId) => decideApproval(approvalId, "declined")}
|
onDecline={(approvalId) => decideApproval(approvalId, "declined")}
|
||||||
|
onEditMessage={editChatMessage}
|
||||||
|
onDeleteMessage={deleteChatMessage}
|
||||||
onSubmit={sendInChannel}
|
onSubmit={sendInChannel}
|
||||||
composerRef={composerRef}
|
composerRef={composerRef}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -27,10 +27,13 @@ export function ChatConversation({
|
|||||||
files,
|
files,
|
||||||
context,
|
context,
|
||||||
attachmentFileId,
|
attachmentFileId,
|
||||||
|
currentEmployeeId,
|
||||||
onAttachmentChange,
|
onAttachmentChange,
|
||||||
onOpenThread,
|
onOpenThread,
|
||||||
onApprove,
|
onApprove,
|
||||||
onDecline,
|
onDecline,
|
||||||
|
onEditMessage,
|
||||||
|
onDeleteMessage,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
composerRef,
|
composerRef,
|
||||||
}: {
|
}: {
|
||||||
@@ -46,10 +49,13 @@ export function ChatConversation({
|
|||||||
files: FileObjectRecord[];
|
files: FileObjectRecord[];
|
||||||
context: MessageContext;
|
context: MessageContext;
|
||||||
attachmentFileId: string;
|
attachmentFileId: string;
|
||||||
|
currentEmployeeId: string;
|
||||||
onAttachmentChange: (next: string) => void;
|
onAttachmentChange: (next: string) => void;
|
||||||
onOpenThread: (threadId: string) => void;
|
onOpenThread: (threadId: string) => void;
|
||||||
onApprove: (approvalId: string) => void;
|
onApprove: (approvalId: string) => void;
|
||||||
onDecline: (approvalId: string) => void;
|
onDecline: (approvalId: string) => void;
|
||||||
|
onEditMessage: (messageId: string, bodyMd: string) => void;
|
||||||
|
onDeleteMessage: (messageId: string) => void;
|
||||||
onSubmit: (event: FormEvent<HTMLFormElement>) => void;
|
onSubmit: (event: FormEvent<HTMLFormElement>) => void;
|
||||||
composerRef: MutableRefObject<HTMLTextAreaElement | null>;
|
composerRef: MutableRefObject<HTMLTextAreaElement | null>;
|
||||||
}) {
|
}) {
|
||||||
@@ -73,9 +79,12 @@ export function ChatConversation({
|
|||||||
slashInvocations={slashInvocations}
|
slashInvocations={slashInvocations}
|
||||||
files={files}
|
files={files}
|
||||||
context={context}
|
context={context}
|
||||||
|
currentEmployeeId={currentEmployeeId}
|
||||||
onOpenThread={onOpenThread}
|
onOpenThread={onOpenThread}
|
||||||
onApprove={onApprove}
|
onApprove={onApprove}
|
||||||
onDecline={onDecline}
|
onDecline={onDecline}
|
||||||
|
onEditMessage={onEditMessage}
|
||||||
|
onDeleteMessage={onDeleteMessage}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ReactNode } from "react";
|
import { useState, type FormEvent, type ReactNode } from "react";
|
||||||
import { Avatar, Icon, IconButton } from "../../shared/ui";
|
import { Avatar, Button, Icon, IconButton } from "../../shared/ui";
|
||||||
import type {
|
import type {
|
||||||
ChatAttachmentRecord,
|
ChatAttachmentRecord,
|
||||||
ChatMentionRecord,
|
ChatMentionRecord,
|
||||||
@@ -20,6 +20,9 @@ export function ChatMessageRow({
|
|||||||
onOpenThread,
|
onOpenThread,
|
||||||
context,
|
context,
|
||||||
compact = false,
|
compact = false,
|
||||||
|
canModify = false,
|
||||||
|
onEdit,
|
||||||
|
onDelete,
|
||||||
}: {
|
}: {
|
||||||
message: ChatMessageRecord;
|
message: ChatMessageRecord;
|
||||||
attachments: ChatAttachmentRecord[];
|
attachments: ChatAttachmentRecord[];
|
||||||
@@ -30,12 +33,24 @@ export function ChatMessageRow({
|
|||||||
onOpenThread: (() => void) | null;
|
onOpenThread: (() => void) | null;
|
||||||
context: MessageContext;
|
context: MessageContext;
|
||||||
compact?: boolean;
|
compact?: boolean;
|
||||||
|
canModify?: boolean;
|
||||||
|
onEdit?: (bodyMd: string) => void;
|
||||||
|
onDelete?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const [editing, setEditing] = useState(false);
|
||||||
const name = senderName(message, context);
|
const name = senderName(message, context);
|
||||||
const bot = message.senderType === "agent";
|
const bot = message.senderType === "agent";
|
||||||
const messageFiles = messageAttachments(message.id, attachments, files);
|
const deleted = Boolean(message.deletedAt);
|
||||||
|
const messageFiles = deleted ? [] : messageAttachments(message.id, attachments, files);
|
||||||
const messageMentions = mentions.filter((mention) => mention.messageId === message.id);
|
const messageMentions = mentions.filter((mention) => mention.messageId === message.id);
|
||||||
const slashInvocation = slashInvocations.find((invocation) => invocation.messageId === message.id) ?? null;
|
const slashInvocation = deleted ? null : slashInvocations.find((invocation) => invocation.messageId === message.id) ?? null;
|
||||||
|
const submitEdit = (event: FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const next = new FormData(event.currentTarget).get("body");
|
||||||
|
const value = typeof next === "string" ? next.trim() : "";
|
||||||
|
if (value && onEdit) onEdit(value);
|
||||||
|
setEditing(false);
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "flex", gap: compact ? 10 : 12, marginBottom: compact ? 12 : 18 }}>
|
<div style={{ display: "flex", gap: compact ? 10 : 12, marginBottom: compact ? 12 : 18 }}>
|
||||||
<Avatar name={name} size={compact ? "sm" : ""} bot={bot} />
|
<Avatar name={name} size={compact ? "sm" : ""} bot={bot} />
|
||||||
@@ -43,15 +58,41 @@ export function ChatMessageRow({
|
|||||||
<div className="row" style={{ alignItems: "baseline", gap: 8, marginBottom: 2 }}>
|
<div className="row" style={{ alignItems: "baseline", gap: 8, marginBottom: 2 }}>
|
||||||
<span style={{ fontSize: 13, fontWeight: 540 }}>{name}</span>
|
<span style={{ fontSize: 13, fontWeight: 540 }}>{name}</span>
|
||||||
<span className="mono" style={{ fontSize: 11, color: "var(--text-3)" }}>{formatTime(message.createdAt)}</span>
|
<span className="mono" style={{ fontSize: 11, color: "var(--text-3)" }}>{formatTime(message.createdAt)}</span>
|
||||||
|
{message.editedAt && !deleted && <span style={{ fontSize: 11, color: "var(--text-3)" }}>(edited)</span>}
|
||||||
|
{canModify && !editing && (
|
||||||
|
<span style={{ marginLeft: "auto", display: "flex", gap: 2 }}>
|
||||||
|
<IconButton icon="more" label="Edit message" size={13} onClick={() => setEditing(true)} />
|
||||||
|
<IconButton icon="x" label="Delete message" size={13} onClick={onDelete} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{slashInvocation && (
|
{slashInvocation && (
|
||||||
<div className="pill mono" style={{ marginBottom: 6, width: "fit-content" }}>
|
<div className="pill mono" style={{ marginBottom: 6, width: "fit-content" }}>
|
||||||
/{slashInvocation.command}
|
/{slashInvocation.command}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div style={{ fontSize: 13, color: "var(--text-1)", lineHeight: 1.5, whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
|
{deleted ? (
|
||||||
{renderBody(message.bodyMd, messageMentions, context)}
|
<div style={{ fontSize: 13, color: "var(--text-3)", fontStyle: "italic" }}>Message deleted</div>
|
||||||
</div>
|
) : editing ? (
|
||||||
|
<form onSubmit={submitEdit}>
|
||||||
|
<textarea
|
||||||
|
name="body"
|
||||||
|
defaultValue={message.bodyMd}
|
||||||
|
autoFocus
|
||||||
|
aria-label="Edit message"
|
||||||
|
className="input"
|
||||||
|
style={{ minHeight: 60, marginBottom: 6 }}
|
||||||
|
/>
|
||||||
|
<div className="row" style={{ gap: 6 }}>
|
||||||
|
<Button tone="primary" size="small" type="submit">Save</Button>
|
||||||
|
<Button tone="ghost" size="small" onClick={() => setEditing(false)}>Cancel</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<div style={{ fontSize: 13, color: "var(--text-1)", lineHeight: 1.5, whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
|
||||||
|
{renderBody(message.bodyMd, messageMentions, context)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{messageFiles.length > 0 && (
|
{messageFiles.length > 0 && (
|
||||||
<div style={{ display: "flex", flexDirection: "column", gap: 8, marginTop: 8 }}>
|
<div style={{ display: "flex", flexDirection: "column", gap: 8, marginTop: 8 }}>
|
||||||
{messageFiles.map((file) => {
|
{messageFiles.map((file) => {
|
||||||
|
|||||||
@@ -22,9 +22,12 @@ export function ChatTimeline({
|
|||||||
slashInvocations,
|
slashInvocations,
|
||||||
files,
|
files,
|
||||||
context,
|
context,
|
||||||
|
currentEmployeeId,
|
||||||
onOpenThread,
|
onOpenThread,
|
||||||
onApprove,
|
onApprove,
|
||||||
onDecline,
|
onDecline,
|
||||||
|
onEditMessage,
|
||||||
|
onDeleteMessage,
|
||||||
}: {
|
}: {
|
||||||
rootMessages: ChatMessageRecord[];
|
rootMessages: ChatMessageRecord[];
|
||||||
messagesInSpace: ChatMessageRecord[];
|
messagesInSpace: ChatMessageRecord[];
|
||||||
@@ -35,9 +38,12 @@ export function ChatTimeline({
|
|||||||
slashInvocations: ChatSlashInvocationRecord[];
|
slashInvocations: ChatSlashInvocationRecord[];
|
||||||
files: FileObjectRecord[];
|
files: FileObjectRecord[];
|
||||||
context: MessageContext;
|
context: MessageContext;
|
||||||
|
currentEmployeeId: string;
|
||||||
onOpenThread: (threadId: string) => void;
|
onOpenThread: (threadId: string) => void;
|
||||||
onApprove: (approvalId: string) => void;
|
onApprove: (approvalId: string) => void;
|
||||||
onDecline: (approvalId: string) => void;
|
onDecline: (approvalId: string) => void;
|
||||||
|
onEditMessage: (messageId: string, bodyMd: string) => void;
|
||||||
|
onDeleteMessage: (messageId: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const elements: ReactNode[] = [];
|
const elements: ReactNode[] = [];
|
||||||
let lastDay = "";
|
let lastDay = "";
|
||||||
@@ -62,6 +68,9 @@ export function ChatTimeline({
|
|||||||
replyCount={replyCount}
|
replyCount={replyCount}
|
||||||
onOpenThread={thread ? () => onOpenThread(thread.id) : null}
|
onOpenThread={thread ? () => onOpenThread(thread.id) : null}
|
||||||
context={context}
|
context={context}
|
||||||
|
canModify={message.senderType === "employee" && message.senderId === currentEmployeeId && !message.deletedAt}
|
||||||
|
onEdit={(bodyMd) => onEditMessage(message.id, bodyMd)}
|
||||||
|
onDelete={() => onDeleteMessage(message.id)}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user