157 lines
4.5 KiB
Markdown
157 lines
4.5 KiB
Markdown
# 🔔 Système de Notifications Complet
|
|
|
|
## ✅ Adapters Implémentés
|
|
|
|
Le système de notifications agrège maintenant **3 sources** :
|
|
|
|
1. **Leantime** (`leantime-adapter.ts`)
|
|
- Notifications de tâches, commentaires, mentions
|
|
- Polling toutes les 30 secondes
|
|
|
|
2. **RocketChat** (`rocketchat-adapter.ts`) ⚡ NOUVEAU
|
|
- Messages non lus dans Parole
|
|
- Déclenchement en temps réel quand nouveau message détecté
|
|
|
|
3. **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
|
|
|
|
```typescript
|
|
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 RocketChat
|
|
- `lib/services/notifications/email-adapter.ts` - Adapter Email
|
|
- `hooks/use-trigger-notification.ts` - Hook pour déclencher refresh
|
|
|
|
### Fichiers Modifiés
|
|
- `lib/services/notifications/notification-service.ts` - Enregistrement des nouveaux adapters
|
|
- `components/parole.tsx` - Détection et déclenchement pour RocketChat
|
|
- `hooks/use-email-state.ts` - Déclenchement pour Email (déjà présent)
|
|
- `hooks/use-notifications.ts` - Écoute d'événements custom
|
|
- `app/api/notifications/count/route.ts` - Support `?force=true`
|
|
- `app/api/rocket-chat/messages/route.ts` - Retourne `totalUnreadCount`
|
|
|
|
---
|
|
|
|
## 🎨 Avantages
|
|
|
|
1. **⚡ Temps Réel** : Notifications instantanées (< 1 seconde)
|
|
2. **📊 Multi-Sources** : Leantime + RocketChat + Email
|
|
3. **💚 Efficace** : Déclenchement uniquement quand nécessaire
|
|
4. **🔄 Rétrocompatible** : Le polling reste en fallback
|
|
5. **📈 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
|