feat: enable direct messaging initiation from agent profiles via agentProfileId query parameter
This commit is contained in:
@@ -6,10 +6,11 @@ import { MessagingPage } from '@/components/message';
|
||||
export default function UserMessagePage() {
|
||||
const searchParams = useSearchParams();
|
||||
const conversationId = searchParams.get('conversationId');
|
||||
const agentProfileId = searchParams.get('agentProfileId');
|
||||
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 lg:px-8 py-6">
|
||||
<MessagingPage initialConversationId={conversationId} />
|
||||
<MessagingPage initialConversationId={conversationId} initialAgentProfileId={agentProfileId} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ export default function AgentProfileView() {
|
||||
bio={profileCardData.bio || agentProfile.bio || ''}
|
||||
expertise={profileCardData.expertise.length > 0 ? profileCardData.expertise : (agentProfile.specializations || [])}
|
||||
showEditButton={false}
|
||||
messageHref="/user/message"
|
||||
messageHref={`/user/message?agentProfileId=${agentProfile.id}`}
|
||||
connectionStatus={connectionStatus}
|
||||
onConnectClick={() => setShowConnectModal(true)}
|
||||
onUnlinkClick={handleUnlink}
|
||||
|
||||
@@ -127,7 +127,7 @@ interface ConnectedAgent {
|
||||
state: string | null;
|
||||
}
|
||||
|
||||
export function MessagingPage({ initialConversationId }: { initialConversationId?: string | null }) {
|
||||
export function MessagingPage({ initialConversationId, initialAgentProfileId }: { initialConversationId?: string | null; initialAgentProfileId?: string | null }) {
|
||||
const { data: session } = useSession();
|
||||
const {
|
||||
conversations,
|
||||
@@ -318,6 +318,31 @@ export function MessagingPage({ initialConversationId }: { initialConversationId
|
||||
}
|
||||
}, [initialConversationId, conversations, isLoading, selectConversation]);
|
||||
|
||||
// Auto-select or create conversation when navigated with initialAgentProfileId
|
||||
const initialAgentHandledRef = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (
|
||||
initialAgentProfileId &&
|
||||
initialAgentHandledRef.current !== initialAgentProfileId &&
|
||||
conversations.length > 0 &&
|
||||
!isLoading
|
||||
) {
|
||||
initialAgentHandledRef.current = initialAgentProfileId;
|
||||
// Find existing conversation with this agent
|
||||
const existing = conversations.find(
|
||||
(c) => c.agentProfileId === initialAgentProfileId || c.otherParty?.id === initialAgentProfileId
|
||||
);
|
||||
if (existing) {
|
||||
selectConversation(existing.id);
|
||||
setShowMobileChat(true);
|
||||
} else {
|
||||
// Start a new conversation
|
||||
startConversation({ agentProfileId: initialAgentProfileId });
|
||||
setShowMobileChat(true);
|
||||
}
|
||||
}
|
||||
}, [initialAgentProfileId, conversations, isLoading, selectConversation, startConversation]);
|
||||
|
||||
// Convert current conversation avatar when selected
|
||||
useEffect(() => {
|
||||
const convertCurrentAvatar = async () => {
|
||||
|
||||
Reference in New Issue
Block a user