diff --git a/artifacts/teaboy-os/src/pages/chat.tsx b/artifacts/teaboy-os/src/pages/chat.tsx index f8bbbcda..279a2537 100644 --- a/artifacts/teaboy-os/src/pages/chat.tsx +++ b/artifacts/teaboy-os/src/pages/chat.tsx @@ -1,6 +1,6 @@ import { useState, useEffect, useRef, useMemo } from "react"; import { useTranslation } from "react-i18next"; -import { useLocation } from "wouter"; +import { useLocation, useSearch } from "wouter"; import { useListConversations, getListConversationsQueryKey, @@ -135,6 +135,7 @@ type ConvMode = "direct" | "group"; export default function ChatPage() { const { t, i18n } = useTranslation(); const [, setLocation] = useLocation(); + const search = useSearch(); const { user } = useAuth(); const lang = i18n.language; const isRtl = lang === "ar"; @@ -231,6 +232,17 @@ export default function ChatPage() { }; }, [user, selectedConvId, queryClient]); + // Open conversation specified via ?c= query param (e.g. from notifications) + useEffect(() => { + const params = new URLSearchParams(search); + const convParam = params.get("c"); + if (!convParam) return; + const convId = Number(convParam); + if (!Number.isFinite(convId) || convId <= 0) return; + setSelectedConvId(convId); + setLocation("/chat", { replace: true }); + }, [search, setLocation]); + // Mark conversation as read when selected useEffect(() => { if (selectedConvId) { diff --git a/artifacts/teaboy-os/src/pages/notifications.tsx b/artifacts/teaboy-os/src/pages/notifications.tsx index 188075eb..e679bdff 100644 --- a/artifacts/teaboy-os/src/pages/notifications.tsx +++ b/artifacts/teaboy-os/src/pages/notifications.tsx @@ -49,6 +49,20 @@ export default function NotificationsPage() { ); }; + const handleNotificationClick = (n: { + id: number; + isRead: boolean; + relatedType?: string | null; + relatedId?: number | null; + }) => { + if (!n.isRead) { + handleMarkOne(n.id); + } + if (n.relatedType === "conversation" && n.relatedId != null) { + setLocation(`/chat?c=${n.relatedId}`); + } + }; + const unreadCount = notifications?.filter((n) => !n.isRead).length ?? 0; return ( @@ -103,7 +117,7 @@ export default function NotificationsPage() { return (
!n.isRead && handleMarkOne(n.id)} + onClick={() => handleNotificationClick(n)} className={`glass-panel rounded-2xl p-4 cursor-pointer transition-opacity ${n.isRead ? "opacity-60" : ""}`} >