UNPKG

communication-react-19

Version:

React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)

45 lines 2.46 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. /** * Take the set of active notifications, and filter to only those that are newer than previously dismissed notifications or have never been dismissed. * * @private */ export const filterLatestNotifications = (activeNotifications, trackedNotifications) => { const filteredNotifications = activeNotifications.filter((activeNotification) => { const trackedNotification = trackedNotifications[activeNotification.type]; return (!trackedNotification || !trackedNotification.lastDismissedAt || trackedNotification.lastDismissedAt < trackedNotification.mostRecentlyActive); }); return filteredNotifications; }; /** * Maintain a record of the most recently active notification for each notification type. * * @private */ export const updateTrackedNotificationsWithActiveNotifications = (existingTrackedNotifications, activeNotifications) => { var _a, _b; const trackedNotifications = {}; // Only care about active notifications. If notifications are no longer active we do not track that they have been previously dismissed. for (const activeNotification of activeNotifications) { const existingTrackedNotification = existingTrackedNotifications[activeNotification.type]; trackedNotifications[activeNotification.type] = { mostRecentlyActive: (_b = (_a = activeNotification.timestamp) !== null && _a !== void 0 ? _a : existingTrackedNotification === null || existingTrackedNotification === void 0 ? void 0 : existingTrackedNotification.mostRecentlyActive) !== null && _b !== void 0 ? _b : new Date(Date.now()), lastDismissedAt: existingTrackedNotification === null || existingTrackedNotification === void 0 ? void 0 : existingTrackedNotification.lastDismissedAt }; } return trackedNotifications; }; /** * Create a record for when the notification was most recently dismissed for tracking dismissed notifications. * * @private */ export const trackNotificationAsDismissed = (notificationType, trackedNotifications) => { const now = new Date(Date.now()); const existingNotification = trackedNotifications[notificationType]; return Object.assign(Object.assign({}, trackedNotifications), { [notificationType]: Object.assign(Object.assign({}, (existingNotification || {})), { lastDismissedAt: now }) }); }; //# sourceMappingURL=TrackErrors.js.map