4.5 KiB
4.5 KiB
🔔 Système de Notifications Complet
✅ Adapters Implémentés
Le système de notifications agrège maintenant 3 sources :
-
Leantime (
leantime-adapter.ts)- Notifications de tâches, commentaires, mentions
- Polling toutes les 30 secondes
-
RocketChat (
rocketchat-adapter.ts) ⚡ NOUVEAU- Messages non lus dans Parole
- Déclenchement en temps réel quand nouveau message détecté
-
Email (
email-adapter.ts) ⚡ NOUVEAU- Emails non lus dans Courrier (INBOX uniquement)
- Déclenchement en temps réel quand nouvel email détecté
🎯 Flow Complet
Badge de Notification
Le badge rouge affiche maintenant le total agrégé :
Total = Leantime (unread) + RocketChat (unread) + Email (unread)
Déclenchement Temps Réel
1. Nouveau Message Parole
Widget Parole détecte nouveau message
└─> totalUnreadCount augmente
└─> triggerNotificationRefresh()
└─> Invalide cache notifications
└─> NotificationService.getNotificationCount()
├─> LeantimeAdapter.getNotificationCount()
├─> RocketChatAdapter.getNotificationCount() ⚡
└─> EmailAdapter.getNotificationCount() ⚡
└─> Badge mis à jour (< 1 seconde)
2. Nouvel Email Courrier
checkForNewEmails() détecte nouvel email
└─> newestEmailId > lastKnownEmailId
└─> triggerNotificationRefresh() ⚡
└─> Invalide cache notifications
└─> NotificationService.getNotificationCount()
├─> LeantimeAdapter.getNotificationCount()
├─> RocketChatAdapter.getNotificationCount()
└─> EmailAdapter.getNotificationCount() ⚡
└─> Badge mis à jour (< 1 seconde)
3. Notification Leantime
Polling toutes les 30s
└─> LeantimeAdapter.getNotificationCount()
└─> Badge mis à jour
📊 Structure des Counts
NotificationCount {
total: number, // Total de toutes les sources
unread: number, // Total non lus de toutes les sources
sources: {
leantime: {
total: number,
unread: number
},
rocketchat: {
total: number,
unread: number
},
email: {
total: number,
unread: number
}
}
}
🔧 Fichiers Modifiés/Créés
Nouveaux Fichiers
lib/services/notifications/rocketchat-adapter.ts- Adapter RocketChatlib/services/notifications/email-adapter.ts- Adapter Emailhooks/use-trigger-notification.ts- Hook pour déclencher refresh
Fichiers Modifiés
lib/services/notifications/notification-service.ts- Enregistrement des nouveaux adapterscomponents/parole.tsx- Détection et déclenchement pour RocketChathooks/use-email-state.ts- Déclenchement pour Email (déjà présent)hooks/use-notifications.ts- Écoute d'événements customapp/api/notifications/count/route.ts- Support?force=trueapp/api/rocket-chat/messages/route.ts- RetournetotalUnreadCount
🎨 Avantages
- ⚡ Temps Réel : Notifications instantanées (< 1 seconde)
- 📊 Multi-Sources : Leantime + RocketChat + Email
- 💚 Efficace : Déclenchement uniquement quand nécessaire
- 🔄 Rétrocompatible : Le polling reste en fallback
- 📈 Scalable : Facile d'ajouter d'autres adapters
🚀 Résultat Final
Le badge de notification affiche maintenant :
- ✅ Notifications Leantime (polling 30s)
- ✅ Messages non lus RocketChat (temps réel)
- ✅ Emails non lus Courrier (temps réel)
Total = Leantime + RocketChat + Email 🎉
📝 Notes Techniques
RocketChat Adapter
- Utilise les subscriptions RocketChat
- Compte les messages non lus (
unread > 0) - Supporte channels, groups, et DMs
Email Adapter
- Utilise le cache Redis de
/api/courrier/unread-counts - Focus sur INBOX (principal dossier pour notifications)
- Peut être étendu pour d'autres dossiers si besoin
Cache Strategy
- Leantime : Cache 30s (aligné avec polling)
- RocketChat : Pas de cache dédié (utilise cache messages)
- Email : Cache 2 minutes (via unread-counts API)
🔍 Debugging
Pour voir les logs :
[ROCKETCHAT_ADAPTER]- Adapter RocketChat[EMAIL_ADAPTER]- Adapter Email[Parole]- Détection dans widget Parole[useTriggerNotification]- Déclenchement refresh[NOTIFICATION_SERVICE]- Agrégation des counts