feat: add ability to share chats (#594)
This commit is contained in:
parent
64d1aad2bb
commit
4d901ba066
20 changed files with 877 additions and 66 deletions
|
|
@ -7,7 +7,9 @@ import { customModel } from '@/lib/ai';
|
|||
import {
|
||||
deleteMessagesByChatIdAfterTimestamp,
|
||||
getMessageById,
|
||||
updateChatVisiblityById,
|
||||
} from '@/lib/db/queries';
|
||||
import { VisibilityType } from '@/components/visibility-selector';
|
||||
|
||||
export async function saveModelId(model: string) {
|
||||
const cookieStore = await cookies();
|
||||
|
|
@ -40,3 +42,13 @@ export async function deleteTrailingMessages({ id }: { id: string }) {
|
|||
timestamp: message.createdAt,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateChatVisibility({
|
||||
chatId,
|
||||
visibility,
|
||||
}: {
|
||||
chatId: string;
|
||||
visibility: VisibilityType;
|
||||
}) {
|
||||
await updateChatVisiblityById({ chatId, visibility });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
|||
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user) {
|
||||
return notFound();
|
||||
}
|
||||
if (chat.visibility === 'private') {
|
||||
if (!session || !session.user) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
if (session.user.id !== chat.userId) {
|
||||
return notFound();
|
||||
if (session.user.id !== chat.userId) {
|
||||
return notFound();
|
||||
}
|
||||
}
|
||||
|
||||
const messagesFromDb = await getMessagesByChatId({
|
||||
|
|
@ -41,6 +43,8 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
|||
id={chat.id}
|
||||
initialMessages={convertToUIMessages(messagesFromDb)}
|
||||
selectedModelId={selectedModelId}
|
||||
selectedVisibilityType={chat.visibility}
|
||||
isReadonly={session?.user?.id !== chat.userId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ export default async function Page() {
|
|||
id={id}
|
||||
initialMessages={[]}
|
||||
selectedModelId={selectedModelId}
|
||||
selectedVisibilityType="private"
|
||||
isReadonly={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue