Skip to content

Commit a9d8a27

Browse files
committed
chat: pinned threads
1 parent a1d889b commit a9d8a27

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,24 @@ export class ChatActions extends Actions<ChatState> {
574574
return true;
575575
};
576576

577+
setThreadPin = (threadKey: string, pinned: boolean): boolean => {
578+
if (this.syncdb == null) {
579+
return false;
580+
}
581+
const entry = this.getThreadRootDoc(threadKey);
582+
if (entry == null) {
583+
return false;
584+
}
585+
if (pinned) {
586+
entry.doc.pin = true;
587+
} else {
588+
delete entry.doc.pin;
589+
}
590+
this.syncdb.set(entry.doc);
591+
this.syncdb.commit();
592+
return true;
593+
};
594+
577595
markThreadRead = (
578596
threadKey: string,
579597
count: number,
@@ -1276,7 +1294,6 @@ export class ChatActions extends Actions<ChatState> {
12761294
};
12771295

12781296
setSelectedThread = (threadKey: string | null) => {
1279-
console.log("setSelectedThread", { threadKey });
12801297
this.frameTreeActions?.set_frame_data({
12811298
id: this.frameId,
12821299
selectedThreadKey: threadKey,

src/packages/frontend/chat/chatroom.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,17 @@ export function ChatPanel({
452452
threadKey: string,
453453
displayLabel: string,
454454
hasCustomName: boolean,
455+
isPinned: boolean,
455456
): MenuProps => ({
456457
items: [
457458
{
458459
key: "rename",
459460
label: "Rename chat",
460461
},
462+
{
463+
key: isPinned ? "unpin" : "pin",
464+
label: isPinned ? "Unpin chat" : "Pin chat",
465+
},
461466
{
462467
type: "divider",
463468
},
@@ -469,14 +474,27 @@ export function ChatPanel({
469474
onClick: ({ key }) => {
470475
if (key === "rename") {
471476
openRenameModal(threadKey, displayLabel, hasCustomName);
477+
} else if (key === "pin" || key === "unpin") {
478+
if (!actions?.setThreadPin) {
479+
antdMessage.error("Pinning chats is not available.");
480+
return;
481+
}
482+
const pinned = key === "pin";
483+
const success = actions.setThreadPin(threadKey, pinned);
484+
if (!success) {
485+
antdMessage.error("Unable to update chat pin state.");
486+
return;
487+
}
488+
antdMessage.success(pinned ? "Chat pinned." : "Chat unpinned.");
472489
} else if (key === "delete") {
473490
confirmDeleteThread(threadKey);
474491
}
475492
},
476493
});
477494

478495
const renderThreadRow = (thread: ThreadMeta) => {
479-
const { key, displayLabel, hasCustomName, unreadCount, isAI } = thread;
496+
const { key, displayLabel, hasCustomName, unreadCount, isAI, isPinned } =
497+
thread;
480498
const plainLabel = stripHtml(displayLabel);
481499
const isHovered = hoveredThread === key;
482500
const showMenu = isHovered || selectedThreadKey === key;
@@ -510,7 +528,7 @@ export function ChatPanel({
510528
)}
511529
{showMenu && (
512530
<Dropdown
513-
menu={threadMenuProps(key, plainLabel, hasCustomName)}
531+
menu={threadMenuProps(key, plainLabel, hasCustomName, isPinned)}
514532
trigger={["click"]}
515533
>
516534
<Button
@@ -1006,7 +1024,6 @@ export function ChatPanel({
10061024
if (!message) {
10071025
return;
10081026
}
1009-
console.log("start video chat returned", { message });
10101027
sendMessage(undefined, "\n\n" + message);
10111028
}}
10121029
>

0 commit comments

Comments
 (0)