Fix read receipts: join chat group when activeChat changes

This commit is contained in:
Халимов Рустам
2026-04-20 23:14:31 +03:00
parent 71b3d2b491
commit c166f1d186
@@ -65,6 +65,8 @@ export default function ChatPage() {
const [activeTab, setActiveTab] = useState('chats'); const [activeTab, setActiveTab] = useState('chats');
const { t } = useLang(); const { t } = useLang();
const activeChat = useChatStore((state) => state.activeChat);
useEffect(() => { useEffect(() => {
groupCallOpenRef.current = groupCallOpen; groupCallOpenRef.current = groupCallOpen;
groupCallChatIdRef.current = groupCallChatId; groupCallChatIdRef.current = groupCallChatId;
@@ -335,6 +337,16 @@ export default function ChatPage() {
}; };
}, [user?.id]); }, [user?.id]);
// Join chat group when activeChat changes
useEffect(() => {
if (activeChat) {
const socket = getSocket();
if (socket) {
socket.emit('join_chat', activeChat);
}
}
}, [activeChat]);
const handleStartCall = (targetUser: UserBasic, type: 'voice' | 'video') => { const handleStartCall = (targetUser: UserBasic, type: 'voice' | 'video') => {
setCallTarget(targetUser); setCallTarget(targetUser);
setCallType(type); setCallType(type);
@@ -371,8 +383,6 @@ export default function ChatPage() {
setGroupCallOpen(false); setGroupCallOpen(false);
}; };
const activeChat = useChatStore((state) => state.activeChat);
return ( return (
<motion.div <motion.div
initial={{ opacity: 0 }} initial={{ opacity: 0 }}