Chat interno 1-a-1 entre usuarios de la plataforma (addon skeen_chat + pagina Chat con badge de no leidos)

This commit is contained in:
2026-08-28 08:23:56 +00:00
parent d47c054ffc
commit 681c0a9173
14 changed files with 607 additions and 2 deletions

27
frontend/src/lib/chat.ts Normal file
View File

@@ -0,0 +1,27 @@
import { useEffect, useState } from 'react';
import { odooApi } from '../services/odoo';
import { useAuth } from './auth';
/** Conteo global de mensajes de chat no leídos, con polling. */
export const useChatUnread = (intervalMs = 15000): number => {
const { user } = useAuth();
const [unread, setUnread] = useState(0);
useEffect(() => {
if (!user) {
setUnread(0);
return;
}
let alive = true;
const fetchCount = () => {
odooApi.getChatUnreadCount()
.then((res) => { if (alive && res.status === 'success') setUnread(res.unread); })
.catch(() => {});
};
fetchCount();
const id = setInterval(fetchCount, intervalMs);
return () => { alive = false; clearInterval(id); };
}, [user, intervalMs]);
return unread;
};