diff --git a/src/pages/GroupConversationPage.tsx b/src/pages/GroupConversationPage.tsx index 78cbee7..04fb38b 100644 --- a/src/pages/GroupConversationPage.tsx +++ b/src/pages/GroupConversationPage.tsx @@ -11,7 +11,8 @@ import { useTranslation } from '@/contexts/language'; import { useToast } from '@/hooks/useToast'; import { useNostrLogin } from '@nostrify/react/login'; import { hasNip44 as checkNip44 } from '@/lib/signerCapabilities'; -import { useGroupConversation, useSendDirectMessage } from '@/hooks/useDirectMessages'; +import { useGroupConversation, useSendDirectMessage, getGroupId } from '@/hooks/useDirectMessages'; +import { useDMRead } from '@/hooks/useDMRead'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { formatDistanceToNow } from '@/lib/dateFnsI18n'; @@ -54,11 +55,20 @@ export default function GroupConversationPage() { useSeoMeta({ title: t('socialUi.groupConversation.seoTitle') }); const { data: messages, isLoading, refetch, isRefetching } = useGroupConversation(allParticipants); + const { markRead } = useDMRead(); + const groupId = useMemo(() => getGroupId(allParticipants), [allParticipants]); useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); + // Opening a group marks it read up to its newest message, same as 1:1 DMs. + useEffect(() => { + if (!messages || messages.length === 0) return; + const newest = messages.reduce((max, message) => Math.max(max, message.createdAt), 0); + markRead(groupId, newest); + }, [groupId, markRead, messages]); + if (!participantsParam || otherPubkeys.length === 0) { return ( <>