mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 17:56:25 +02:00
refactor: simplify author metadata handling in NewChatPage and UserMessage components
This commit is contained in:
parent
7ed6e9c75f
commit
75fd39c249
2 changed files with 17 additions and 18 deletions
|
|
@ -218,15 +218,13 @@ export default function NewChatPage() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSharedChat = currentThread?.visibility === "SEARCH_SPACE";
|
|
||||||
|
|
||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
if (syncedMessages.length < prev.length) {
|
if (syncedMessages.length < prev.length) {
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
return syncedMessages.map((msg) => {
|
return syncedMessages.map((msg) => {
|
||||||
const member = isSharedChat && msg.author_id
|
const member = msg.author_id
|
||||||
? membersData?.find((m) => m.user_id === msg.author_id)
|
? membersData?.find((m) => m.user_id === msg.author_id)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|
@ -241,7 +239,7 @@ export default function NewChatPage() {
|
||||||
thread_id: msg.thread_id,
|
thread_id: msg.thread_id,
|
||||||
role: msg.role.toLowerCase() as "user" | "assistant" | "system",
|
role: msg.role.toLowerCase() as "user" | "assistant" | "system",
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
author_id: isSharedChat ? msg.author_id : null,
|
author_id: msg.author_id,
|
||||||
created_at: msg.created_at,
|
created_at: msg.created_at,
|
||||||
author_display_name: member?.user_display_name ?? existingAuthor?.displayName ?? null,
|
author_display_name: member?.user_display_name ?? existingAuthor?.displayName ?? null,
|
||||||
author_avatar_url: member?.user_avatar_url ?? existingAuthor?.avatarUrl ?? null,
|
author_avatar_url: member?.user_avatar_url ?? existingAuthor?.avatarUrl ?? null,
|
||||||
|
|
@ -249,7 +247,7 @@ export default function NewChatPage() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[isRunning, membersData, currentThread?.visibility]
|
[isRunning, membersData]
|
||||||
);
|
);
|
||||||
|
|
||||||
useMessagesSync(threadId, handleSyncedMessagesUpdate);
|
useMessagesSync(threadId, handleSyncedMessagesUpdate);
|
||||||
|
|
@ -485,9 +483,8 @@ export default function NewChatPage() {
|
||||||
// Add user message to state
|
// Add user message to state
|
||||||
const userMsgId = `msg-user-${Date.now()}`;
|
const userMsgId = `msg-user-${Date.now()}`;
|
||||||
|
|
||||||
// Include author metadata for shared chats
|
// Always include author metadata so the UI layer can decide visibility
|
||||||
const authorMetadata =
|
const authorMetadata = currentUser
|
||||||
currentThread?.visibility === "SEARCH_SPACE" && currentUser
|
|
||||||
? {
|
? {
|
||||||
custom: {
|
custom: {
|
||||||
author: {
|
author: {
|
||||||
|
|
@ -884,7 +881,6 @@ export default function NewChatPage() {
|
||||||
setMessageDocumentsMap,
|
setMessageDocumentsMap,
|
||||||
setAgentCreatedDocuments,
|
setAgentCreatedDocuments,
|
||||||
queryClient,
|
queryClient,
|
||||||
currentThread,
|
|
||||||
currentUser,
|
currentUser,
|
||||||
disabledTools,
|
disabledTools,
|
||||||
updateChatTabTitle,
|
updateChatTabTitle,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { useAtomValue } from "jotai";
|
||||||
import { CheckIcon, CopyIcon, FileText, Pen } from "lucide-react";
|
import { CheckIcon, CopyIcon, FileText, Pen } from "lucide-react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { type FC, useState } from "react";
|
import { type FC, useState } from "react";
|
||||||
|
import { currentThreadAtom } from "@/atoms/chat/current-thread.atom";
|
||||||
import { messageDocumentsMapAtom } from "@/atoms/chat/mentioned-documents.atom";
|
import { messageDocumentsMapAtom } from "@/atoms/chat/mentioned-documents.atom";
|
||||||
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
||||||
|
|
||||||
|
|
@ -51,6 +52,8 @@ export const UserMessage: FC = () => {
|
||||||
const mentionedDocs = messageId ? messageDocumentsMap[messageId] : undefined;
|
const mentionedDocs = messageId ? messageDocumentsMap[messageId] : undefined;
|
||||||
const metadata = useAuiState(({ message }) => message?.metadata);
|
const metadata = useAuiState(({ message }) => message?.metadata);
|
||||||
const author = metadata?.custom?.author as AuthorMetadata | undefined;
|
const author = metadata?.custom?.author as AuthorMetadata | undefined;
|
||||||
|
const isSharedChat = useAtomValue(currentThreadAtom).visibility === "SEARCH_SPACE";
|
||||||
|
const showAvatar = isSharedChat && !!author;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MessagePrimitive.Root
|
<MessagePrimitive.Root
|
||||||
|
|
@ -81,7 +84,7 @@ export const UserMessage: FC = () => {
|
||||||
<UserActionBar />
|
<UserActionBar />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{author && (
|
{showAvatar && (
|
||||||
<div className="shrink-0 mb-1.5">
|
<div className="shrink-0 mb-1.5">
|
||||||
<UserAvatar displayName={author.displayName} avatarUrl={author.avatarUrl} />
|
<UserAvatar displayName={author.displayName} avatarUrl={author.avatarUrl} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue