Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat(ee): add conversation context
Marc Seitz51c9cbc1bf0c
diff --git a/components/conversations/index.tsx b/components/conversations/index.tsxindex 8ba65f1d..2d0219c6 100644--- a/components/conversations/index.tsx+++ b/components/conversations/index.tsx@@ -1,7 +1,7 @@"use client";-import { ConversationListItem as ConversationListItemEE } from "@/ee/features/conversations/components/conversation-list-item";-import { ConversationMessage as ConversationMessageEE } from "@/ee/features/conversations/components/conversation-message";+import { ConversationListItem as ConversationListItemEE } from "@/ee/features/conversations/components/dashboard/conversation-list-item";+import { ConversationMessage as ConversationMessageEE } from "@/ee/features/conversations/components/shared/conversation-message";export function ConversationListItem(props: any) {return <ConversationListItemEE {...props} />;diff --git a/components/links/link-sheet/conversation-section.tsx b/components/links/link-sheet/conversation-section.tsxindex 04e1ffa2..b76ed5e7 100644--- a/components/links/link-sheet/conversation-section.tsx+++ b/components/links/link-sheet/conversation-section.tsx@@ -1,3 +1,3 @@-import ConversationSection from "@/ee/features/conversations/components/link-option-conversation-section";+import ConversationSection from "@/ee/features/conversations/components/dashboard/link-option-conversation-section";export default ConversationSection;diff --git a/components/view/conversations/sidebar.tsx b/components/view/conversations/sidebar.tsxindex f2abd629..8b877aac 100644--- a/components/view/conversations/sidebar.tsx+++ b/components/view/conversations/sidebar.tsx@@ -3,7 +3,7 @@import {ConversationSidebarProps,ConversationViewSidebar as ConversationViewSidebarEE,-} from "@/ee/features/conversations/components/conversation-view-sidebar";+} from "@/ee/features/conversations/components/viewer/conversation-view-sidebar";export function ConversationSidebar(props: ConversationSidebarProps) {return <ConversationViewSidebarEE {...props} />;diff --git a/components/view/nav.tsx b/components/view/nav.tsxindex 9c422ca3..21f570c3 100644--- a/components/view/nav.tsx+++ b/components/view/nav.tsx@@ -422,6 +422,7 @@ export default function Nav({<ConversationSidebardataroomId={dataroomId}documentId={documentId}+ pageNumber={pageNumber}viewId={viewId || ""}viewerId={viewerId}linkId={linkId!}diff --git a/ee/features/conversations/api/conversations-route.ts b/ee/features/conversations/api/conversations-route.tsindex 8b588ff8..87ef7be5 100644--- a/ee/features/conversations/api/conversations-route.ts+++ b/ee/features/conversations/api/conversations-route.ts@@ -43,7 +43,11 @@ const routeHandlers = {},},dataroom: true,- dataroomDocument: true,+ dataroomDocument: {+ include: {+ document: true,+ },+ },participants: {where: {viewerId,@@ -71,11 +75,13 @@ const routeHandlers = {// POST /api/conversations"POST /": async (req: NextApiRequest, res: NextApiResponse) => {- const { dataroomId, viewId, viewerId, ...data } =+ const { dataroomId, viewId, viewerId, documentId, pageNumber, ...data } =req.body as CreateConversationInput & {dataroomId: string;viewId: string;viewerId?: string;+ documentId?: string;+ pageNumber?: number;};// Check if conversations are allowed@@ -112,13 +118,49 @@ const routeHandlers = {return res.status(400).json({ error: "Team not found" });}+ // Map documentId to dataroomDocumentId and get version info if provided+ let enhancedData = { ...data };+ if (documentId) {+ const dataroomDocument = await prisma.dataroomDocument.findFirst({+ where: {+ dataroomId,+ documentId,+ },+ include: {+ document: {+ include: {+ versions: {+ where: { isPrimary: true },+ select: { versionNumber: true },+ },+ },+ },+ },+ });++ if (dataroomDocument) {+ enhancedData.dataroomDocumentId = dataroomDocument.id;++ // Set page number if provided+ if (pageNumber) {+ enhancedData.documentPageNumber = pageNumber;+ }++ // Set document version number from the primary version+ if (dataroomDocument.document.versions[0]?.versionNumber) {+ enhancedData.documentVersionNumber =+ dataroomDocument.document.versions[0].versionNumber;+ }+ }+ }+// Create the conversationconst conversation = await conversationService.createConversation({dataroomId,viewerId,viewId,teamId: team.id,- data,+ data: enhancedData,});// Get all delayed and queued runs for this dataroomdiff --git a/ee/features/conversations/api/team-conversations-route.ts b/ee/features/conversations/api/team-conversations-route.tsindex b645842d..18e600a8 100644--- a/ee/features/conversations/api/team-conversations-route.ts+++ b/ee/features/conversations/api/team-conversations-route.ts@@ -65,6 +65,11 @@ const routeHandlers = {createdAt: true,},},+ dataroomDocument: {+ include: {+ document: true,+ },+ },_count: {select: {messages: {@@ -117,6 +122,15 @@ const routeHandlers = {viewerEmail: viewer?.email,unreadCount: conversation._count.messages,lastMessage: conversation.messages[0] || null,+ dataroomDocumentName: conversation.dataroomDocumentId+ ? conversation.dataroomDocument.document.name+ : undefined,+ documentPageNumber: conversation.dataroomDocumentId+ ? conversation.documentPageNumber+ : undefined,+ documentVersionNumber: conversation.dataroomDocumentId+ ? conversation.documentVersionNumber+ : undefined,};});@@ -373,6 +387,11 @@ const routeHandlers = {viewer: true,},},+ dataroomDocument: {+ include: {+ document: true,+ },+ },},});diff --git a/ee/features/conversations/components/conversation-list-item.tsx b/ee/features/conversations/components/dashboard/conversation-list-item.tsxsimilarity index 82%rename from ee/features/conversations/components/conversation-list-item.tsxrename to ee/features/conversations/components/dashboard/conversation-list-item.tsxindex 1cceac18..156c09e3 100644--- a/ee/features/conversations/components/conversation-list-item.tsx+++ b/ee/features/conversations/components/dashboard/conversation-list-item.tsx@@ -8,26 +8,29 @@ export function ConversationListItem({navigateToConversation,conversation,isActive,+ showVersionNumber = false,}: {navigateToConversation: (id: string) => void;conversation: any;isActive: boolean;+ showVersionNumber?: boolean;}) {// Helper function to format document referenceconst formatDocumentReference = () => {- if (!conversation.dataroomDocument) return "Untitled conversation";-- const documentName = conversation.dataroomDocument.document.name;+ if (!conversation.dataroomDocumentName) return "Untitled conversation";++ const documentName = conversation.dataroomDocumentName;const parts = [];-+if (conversation.documentPageNumber) {parts.push(`Page ${conversation.documentPageNumber}`);}-- if (conversation.documentVersionNumber) {++ // Only show version number if showVersionNumber is true (admin/team member view)+ if (showVersionNumber && conversation.documentVersionNumber) {parts.push(`v${conversation.documentVersionNumber}`);}-+const reference = parts.length > 0 ? ` (${parts.join(", ")})` : "";return `${documentName}${reference}`;};@@ -59,7 +62,7 @@ export function ConversationListItem({</div></div><div className="text-xs font-medium">- {conversation.title || formatDocumentReference()}+ {formatDocumentReference() || conversation.title}</div></div>diff --git a/ee/features/conversations/components/conversations-not-enabled-banner.tsx b/ee/features/conversations/components/dashboard/conversations-not-enabled-banner.tsxsimilarity index 100%rename from ee/features/conversations/components/conversations-not-enabled-banner.tsxrename to ee/features/conversations/components/dashboard/conversations-not-enabled-banner.tsxdiff --git a/ee/features/conversations/components/link-option-conversation-section.tsx b/ee/features/conversations/components/dashboard/link-option-conversation-section.tsxsimilarity index 100%rename from ee/features/conversations/components/link-option-conversation-section.tsxrename to ee/features/conversations/components/dashboard/link-option-conversation-section.tsxdiff --git a/ee/features/conversations/components/conversation-document-context.tsx b/ee/features/conversations/components/shared/conversation-document-context.tsxsimilarity index 56%rename from ee/features/conversations/components/conversation-document-context.tsxrename to ee/features/conversations/components/shared/conversation-document-context.tsxindex 089324a4..0df6a421 100644--- a/ee/features/conversations/components/conversation-document-context.tsx+++ b/ee/features/conversations/components/shared/conversation-document-context.tsx@@ -1,4 +1,4 @@-import { FileTextIcon, BookOpenIcon } from "lucide-react";+import { BookOpenIcon, FileTextIcon } from "lucide-react";interface ConversationDocumentContextProps {dataroomDocument?: {@@ -7,9 +7,10 @@ interface ConversationDocumentContextProps {type?: string;};};- documentPageNumber?: number;- documentVersionNumber?: number;+ documentPageNumber?: number | null;+ documentVersionNumber?: number | null;className?: string;+ showVersionNumber?: boolean; // Controls whether to show version info}export function ConversationDocumentContext({@@ -17,38 +18,40 @@ export function ConversationDocumentContext({documentPageNumber,documentVersionNumber,className = "",+ showVersionNumber = false,}: ConversationDocumentContextProps) {if (!dataroomDocument) return null;- const hasPageOrVersion = documentPageNumber || documentVersionNumber;+ const hasPageOrVersion =+ documentPageNumber || (showVersionNumber && documentVersionNumber);return (<divclassName={`flex items-center gap-2 rounded-lg border bg-muted/50 px-3 py-2 text-sm ${className}`}>- <div className="flex items-center gap-2 flex-1 min-w-0">- <FileTextIcon className="h-4 w-4 text-muted-foreground shrink-0" />- <span className="font-medium truncate">+ <div className="flex min-w-0 flex-1 items-center gap-2">+ <FileTextIcon className="h-4 w-4 shrink-0 text-muted-foreground" />+ <span className="truncate font-medium">{dataroomDocument.document.name}</span></div>-+{hasPageOrVersion && (- <div className="flex items-center gap-2 text-xs text-muted-foreground shrink-0">+ <div className="flex shrink-0 items-center gap-2 text-xs text-muted-foreground">{documentPageNumber && (<span className="flex items-center gap-1"><BookOpenIcon className="h-3 w-3" />Page {documentPageNumber}</span>)}- {documentPageNumber && documentVersionNumber && (+ {documentPageNumber && showVersionNumber && documentVersionNumber && (<span>•</span>)}- {documentVersionNumber && (+ {showVersionNumber && documentVersionNumber && (<span>v{documentVersionNumber}</span>)}</div>)}</div>);-}\ No newline at end of file+}diff --git a/ee/features/conversations/components/conversation-message.tsx b/ee/features/conversations/components/shared/conversation-message.tsxsimilarity index 100%rename from ee/features/conversations/components/conversation-message.tsxrename to ee/features/conversations/components/shared/conversation-message.tsxdiff --git a/ee/features/conversations/components/conversation-view-sidebar.tsx b/ee/features/conversations/components/viewer/conversation-view-sidebar.tsxsimilarity index 91%rename from ee/features/conversations/components/conversation-view-sidebar.tsxrename to ee/features/conversations/components/viewer/conversation-view-sidebar.tsxindex 437e7899..656101ab 100644--- a/ee/features/conversations/components/conversation-view-sidebar.tsx+++ b/ee/features/conversations/components/viewer/conversation-view-sidebar.tsx@@ -2,8 +2,8 @@import { useState } from "react";-import { ConversationMessage } from "@/ee/features/conversations/components/conversation-message";-import { ConversationDocumentContext } from "@/ee/features/conversations/components/conversation-document-context";+import { ConversationDocumentContext } from "@/ee/features/conversations/components/shared/conversation-document-context";+import { ConversationMessage } from "@/ee/features/conversations/components/shared/conversation-message";import { format } from "date-fns";import { ArrowLeftIcon, BellIcon, BellOffIcon, Plus } from "lucide-react";import { toast } from "sonner";@@ -36,6 +36,7 @@ interface Conversation {userId: string | null;viewerId: string | null;documentPageNumber: number | null;+ documentVersionNumber: number | null;dataroomDocument?: {document: {name: string;@@ -219,7 +220,7 @@ export function ConversationViewSidebar({{/* Conversation Header */}<div className="border-b p-4"><div className="flex items-center justify-between">- <div className="flex items-center flex-1 min-w-0">+ <div className="flex min-w-0 flex-1 items-center"><Buttonvariant="ghost"size="icon"@@ -230,28 +231,8 @@ export function ConversationViewSidebar({</Button><div className="min-w-0"><h3 className="truncate font-medium">- {activeConversation.title ||- "Conversation"}+ {activeConversation.title || "Conversation"}</h3>- {activeConversation.dataroomDocument && (- <div className="flex items-center gap-1 text-xs text-muted-foreground mt-1">- <span className="truncate">- 📄 {activeConversation.dataroomDocument.document.name}- </span>- {(activeConversation.documentPageNumber ||- activeConversation.documentVersionNumber) && (- <span className="shrink-0">- {activeConversation.documentPageNumber &&- `Page ${activeConversation.documentPageNumber}`}- {activeConversation.documentPageNumber &&- activeConversation.documentVersionNumber &&- " • "}- {activeConversation.documentVersionNumber &&- `v${activeConversation.documentVersionNumber}`}- </span>- )}- </div>- )}</div></div><Button@@ -322,8 +303,13 @@ export function ConversationViewSidebar({{/* Document Context */}<ConversationDocumentContextdataroomDocument={activeConversation.dataroomDocument}- documentPageNumber={activeConversation.documentPageNumber}- documentVersionNumber={activeConversation.documentVersionNumber}+ documentPageNumber={+ activeConversation.documentPageNumber+ }+ documentVersionNumber={+ activeConversation.documentVersionNumber+ }+ showVersionNumber={false} // Viewers see simplified contextclassName="mb-2"/>{activeConversation.messages?.map((message) => (diff --git a/ee/features/conversations/lib/api/conversations/index.ts b/ee/features/conversations/lib/api/conversations/index.tsindex add95871..df86538c 100644--- a/ee/features/conversations/lib/api/conversations/index.ts+++ b/ee/features/conversations/lib/api/conversations/index.ts@@ -109,7 +109,11 @@ export const conversationService = {messages: true,views: true,dataroom: true,- dataroomDocument: true,+ dataroomDocument: {+ include: {+ document: true,+ },+ },},});},@@ -137,7 +141,11 @@ export const conversationService = {participants: true,messages: includeMessages,dataroom: true,- dataroomDocument: true,+ dataroomDocument: {+ include: {+ document: true,+ },+ },},orderBy: {updatedAt: "desc",@@ -170,7 +178,11 @@ export const conversationService = {participants: true,messages: includeMessages,dataroom: true,- dataroomDocument: true,+ dataroomDocument: {+ include: {+ document: true,+ },+ },},orderBy: {updatedAt: "desc",diff --git a/ee/features/conversations/pages/conversation-detail.tsx b/ee/features/conversations/pages/conversation-detail.tsxindex 993656db..4bbc144c 100644--- a/ee/features/conversations/pages/conversation-detail.tsx+++ b/ee/features/conversations/pages/conversation-detail.tsx@@ -2,9 +2,9 @@ import { useRouter } from "next/router";import { useState } from "react";-import { ConversationListItem } from "@/ee/features/conversations/components/conversation-list-item";-import { ConversationMessage } from "@/ee/features/conversations/components/conversation-message";-import { ConversationDocumentContext } from "@/ee/features/conversations/components/conversation-document-context";+import { ConversationListItem } from "@/ee/features/conversations/components/dashboard/conversation-list-item";+import { ConversationDocumentContext } from "@/ee/features/conversations/components/shared/conversation-document-context";+import { ConversationMessage } from "@/ee/features/conversations/components/shared/conversation-message";import { Loader2, SearchIcon, Send, Trash2 } from "lucide-react";import { useSession } from "next-auth/react";import { toast } from "sonner";@@ -51,6 +51,7 @@ interface Conversation {updatedAt: string;participants: { id: string; email: string | null }[];documentPageNumber: number | null;+ documentVersionNumber: number | null;unreadCount: number;messages: Message[];dataroomDocument?: {@@ -68,6 +69,7 @@ interface ConversationSummary {viewerId: string | null;viewerEmail?: string;documentPageNumber: number | null;+ documentVersionNumber: number | null;unreadCount: number;lastMessage?: {content: string;@@ -362,25 +364,6 @@ export default function ConversationDetailPage() {{conversation.participants[0].email ||"Anonymous Viewer"}</p>- {conversation.dataroomDocument && (- <div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">- <span className="flex items-center gap-1">- 📄 {conversation.dataroomDocument.document.name}- </span>- {(conversation.documentPageNumber ||- conversation.documentVersionNumber) && (- <span className="text-xs">- {conversation.documentPageNumber &&- `Page ${conversation.documentPageNumber}`}- {conversation.documentPageNumber &&- conversation.documentVersionNumber &&- " • "}- {conversation.documentVersionNumber &&- `v${conversation.documentVersionNumber}`}- </span>- )}- </div>- )}</div></div><Button@@ -400,7 +383,10 @@ export default function ConversationDetailPage() {<ConversationDocumentContextdataroomDocument={conversation.dataroomDocument}documentPageNumber={conversation.documentPageNumber}- documentVersionNumber={conversation.documentVersionNumber}+ documentVersionNumber={+ conversation.documentVersionNumber+ }+ showVersionNumber={true} // Admin sees full contextclassName="mb-2"/>{conversation.messages.map((message) => (diff --git a/ee/features/conversations/pages/conversation-overview.tsx b/ee/features/conversations/pages/conversation-overview.tsxindex 4bc8bd99..5233e85d 100644--- a/ee/features/conversations/pages/conversation-overview.tsx+++ b/ee/features/conversations/pages/conversation-overview.tsx@@ -2,8 +2,8 @@ import { useRouter } from "next/router";import { useEffect, useState } from "react";-import { ConversationListItem } from "@/ee/features/conversations/components/conversation-list-item";-import { ConversationsNotEnabledBanner } from "@/ee/features/conversations/components/conversations-not-enabled-banner";+import { ConversationListItem } from "@/ee/features/conversations/components/dashboard/conversation-list-item";+import { ConversationsNotEnabledBanner } from "@/ee/features/conversations/components/dashboard/conversations-not-enabled-banner";import { Loader2, MessageSquare, Search } from "lucide-react";import { toast } from "sonner";import useSWR from "swr";@@ -37,6 +37,7 @@ interface ConversationSummary {viewerId: string | null;viewerEmail?: string;documentPageNumber: number | null;+ documentVersionNumber: number | null;unreadCount: number;lastMessage?: {content: string;