@@ -8,7 +8,7 @@ import {
88 type FormEvent,
99 type KeyboardEvent,
1010 } from "react";
11-import { Paperclip, SendHorizontal } from "lucide-react";
11+import { Paperclip, Pencil, SendHorizontal, Trash2 } from "lucide-react";
1212 import { Button } from "@/components/ui/button";
1313 import { cn } from "cn";
1414 import { api, upload } from "../lib/api";
@@ -49,6 +49,8 @@ export default function ChatPane({
4949 username: string;
5050 }) {
5151 const [body, setBody] = useState("");
52+ const [editingId, setEditingId] = useState<number | null>(null);
53+ const [editBody, setEditBody] = useState("");
5254 const [collapsed, setCollapsed] = useState<Set<number>>(new Set());
5355 const [mention, setMention] = useState<{ query: string; start: number; index: number } | null>(
5456 null,
@@ -66,6 +68,7 @@ export default function ChatPane({
6668
6769 // Jump to the latest messages on channel switch, regardless of prior position.
6870 useLayoutEffect(() => {
71+ setEditingId(null);
6972 stickRef.current = true;
7073 scrollToBottom();
7174 }, [channel?.id, scrollToBottom]);
@@ -197,6 +200,25 @@ export default function ChatPane({
197200 setCollapsed(new Set(messages.filter((m) => hasImage(m.body)).map((m) => m.id)));
198201 }
199202
203+ function startEdit(m: Message) {
204+ setEditingId(m.id);
205+ setEditBody(m.body);
206+ }
207+
208+ async function saveEdit(id: number) {
209+ const text = editBody.trim();
210+ setEditingId(null);
211+ if (!text) return;
212+ await api(`/messages/${id}`, {
213+ method: "PATCH",
214+ body: JSON.stringify({ body: text }),
215+ }).catch(() => {});
216+ }
217+
218+ async function remove(id: number) {
219+ await api(`/messages/${id}`, { method: "DELETE" }).catch(() => {});
220+ }
221+
200222 async function send() {
201223 const text = body.trim();
202224 if (!text || !channel) return;
@@ -245,6 +267,14 @@ export default function ChatPane({
245267 return;
246268 }
247269 }
270+ if (e.key === "ArrowUp" && !body) {
271+ const last = [...messages].reverse().find((m) => m.username === username);
272+ if (last) {
273+ e.preventDefault();
274+ startEdit(last);
275+ }
276+ return;
277+ }
248278 if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
249279 e.preventDefault();
250280 send();
@@ -262,11 +292,13 @@ export default function ChatPane({
262292 {messages.map((m) => {
263293 const action = m.body.startsWith("/me ") ? m.body.slice(4) : null;
264294 const hit = !action && isMentioned(m.body, username);
295+ const own = m.username === username;
296+ const editing = editingId === m.id;
265297 return (
266298 <div
267299 key={m.id}
268300 className={cn(
269- "-mx-1.5 flex gap-1.5 rounded px-1.5 py-0.5 text-sm leading-6",
301+ "group -mx-1.5 flex items-start gap-1.5 rounded px-1.5 py-0.5 text-sm leading-6 hover:bg-sepia/5",
270302 hit && "bg-[color-mix(in_srgb,var(--gold)_14%,transparent)]",
271303 )}
272304 >
@@ -274,9 +306,29 @@ export default function ChatPane({
274306 <span className="text-sepia/40">{clock(m.createdAt)}</span>{" "}
275307 {!action && <span className="text-gold/90">{m.username}</span>}
276308 </span>
277- {action ? (
309+ {editing ? (
310+ <textarea
311+ autoFocus
312+ rows={Math.min(editBody.split("\n").length, 8)}
313+ value={editBody}
314+ onChange={(e) => setEditBody(e.target.value)}
315+ onKeyDown={(e) => {
316+ if (e.key === "Escape") {
317+ e.preventDefault();
318+ setEditingId(null);
319+ } else if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
320+ e.preventDefault();
321+ saveEdit(m.id);
322+ }
323+ }}
324+ className="max-h-[200px] min-w-0 flex-1 resize-none rounded border border-input bg-transparent px-2 py-0.5 text-sm leading-6 outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 dark:bg-input/30"
325+ />
326+ ) : action ? (
278327 <div className="min-w-0 flex-1 break-words italic text-gold/90">
279328 * {m.username} {action}
329+ {m.editedAt ? (
330+ <span className="ml-1 not-italic text-xs text-sepia/40">(edited)</span>
331+ ) : null}
280332 </div>
281333 ) : (
282334 <div className={bodyClass}>
@@ -285,6 +337,29 @@ export default function ChatPane({
285337 collapsed={collapsed.has(m.id)}
286338 onToggle={() => toggleImage(m.id)}
287339 />
340+ {m.editedAt ? <span className="text-xs text-sepia/40">(edited)</span> : null}
341+ </div>
342+ )}
343+ {own && !editing && (
344+ <div className="invisible flex shrink-0 items-center gap-0.5 group-hover:visible">
345+ <Button
346+ type="button"
347+ variant="ghost"
348+ size="icon-xs"
349+ title="edit message"
350+ onClick={() => startEdit(m)}
351+ >
352+ <Pencil />
353+ </Button>
354+ <Button
355+ type="button"
356+ variant="ghost"
357+ size="icon-xs"
358+ title="delete message"
359+ onClick={() => remove(m.id)}
360+ >
361+ <Trash2 />
362+ </Button>
288363 </div>
289364 )}
290365 </div>