refactor Notifications rc

This commit is contained in:
alma 2026-01-16 01:39:42 +01:00
parent d44dff8d34
commit 1dae207b6e
3 changed files with 24 additions and 7 deletions

View File

@ -208,7 +208,10 @@ export function useNotifications() {
const handleNotificationUpdate = (event: CustomEvent) => {
console.log('[useNotifications] Received notification update event', event.detail);
// Refresh count immediately when widget updates
fetchNotificationCount(false); // Use cache, widget already updated it
// Use a small delay to ensure the registry has been updated
setTimeout(() => {
fetchNotificationCount(false); // Use cache, widget already updated it
}, 100);
};
// Listen for custom event from widgets

View File

@ -116,13 +116,15 @@ export function useRocketChatCalls() {
});
// Trigger notification
// For calls, we want to increment the existing count, not replace it
// So we fetch current count first, then increment
triggerNotification({
source: 'rocketchat',
count: 1, // Increment count for call
count: 1, // This will be added to existing count in the registry
items: [
{
id: `call-${callEvent.roomId}-${Date.now()}`,
title: `Appel entrant de ${callEvent.from.name || callEvent.from.username}`,
title: `📞 Appel entrant de ${callEvent.from.name || callEvent.from.username}`,
message: `Appel vidéo/audio dans ${callEvent.roomName || 'chat'}`,
link: `/parole?room=${callEvent.roomId}`,
timestamp: callEvent.timestamp,

View File

@ -62,11 +62,23 @@ export class NotificationRegistry {
}
// Update count for this source
// If count is 1 and it's a call, increment. Otherwise, set the count.
const previousSourceCount = currentCount.sources[source]?.unread || 0;
currentCount.sources[source] = {
total: count,
unread: count,
};
const isCallIncrement = count === 1 && items && items.length > 0 && items[0].metadata?.type === 'call';
if (isCallIncrement) {
// For calls, increment the existing count
currentCount.sources[source] = {
total: previousSourceCount + count,
unread: previousSourceCount + count,
};
} else {
// For regular updates, set the count (widgets send their total)
currentCount.sources[source] = {
total: count,
unread: count,
};
}
// Recalculate total
currentCount.unread = Object.values(currentCount.sources).reduce(