refactor Notifications rc
This commit is contained in:
parent
d44dff8d34
commit
1dae207b6e
@ -208,7 +208,10 @@ export function useNotifications() {
|
|||||||
const handleNotificationUpdate = (event: CustomEvent) => {
|
const handleNotificationUpdate = (event: CustomEvent) => {
|
||||||
console.log('[useNotifications] Received notification update event', event.detail);
|
console.log('[useNotifications] Received notification update event', event.detail);
|
||||||
// Refresh count immediately when widget updates
|
// 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
|
// Listen for custom event from widgets
|
||||||
|
|||||||
@ -116,13 +116,15 @@ export function useRocketChatCalls() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Trigger notification
|
// Trigger notification
|
||||||
|
// For calls, we want to increment the existing count, not replace it
|
||||||
|
// So we fetch current count first, then increment
|
||||||
triggerNotification({
|
triggerNotification({
|
||||||
source: 'rocketchat',
|
source: 'rocketchat',
|
||||||
count: 1, // Increment count for call
|
count: 1, // This will be added to existing count in the registry
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
id: `call-${callEvent.roomId}-${Date.now()}`,
|
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'}`,
|
message: `Appel vidéo/audio dans ${callEvent.roomName || 'chat'}`,
|
||||||
link: `/parole?room=${callEvent.roomId}`,
|
link: `/parole?room=${callEvent.roomId}`,
|
||||||
timestamp: callEvent.timestamp,
|
timestamp: callEvent.timestamp,
|
||||||
|
|||||||
@ -62,11 +62,23 @@ export class NotificationRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update count for this source
|
// 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;
|
const previousSourceCount = currentCount.sources[source]?.unread || 0;
|
||||||
currentCount.sources[source] = {
|
const isCallIncrement = count === 1 && items && items.length > 0 && items[0].metadata?.type === 'call';
|
||||||
total: count,
|
|
||||||
unread: count,
|
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
|
// Recalculate total
|
||||||
currentCount.unread = Object.values(currentCount.sources).reduce(
|
currentCount.unread = Object.values(currentCount.sources).reduce(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user