UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

38 lines 1.45 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.openInAppNotification = exports.inAppNotificationsStore = exports.closeInAppNotification = void 0; var _streamChat = require("stream-chat"); var INITIAL_STATE = { notifications: [] }; var inAppNotificationsStore = exports.inAppNotificationsStore = new _streamChat.StateStore(INITIAL_STATE); var openInAppNotification = notification => { if (!notification.id) { console.warn('Notification must have an id to be opened!'); return; } var _inAppNotificationsSt = inAppNotificationsStore.getLatestValue(), notifications = _inAppNotificationsSt.notifications; if (notifications.some(n => n.id === notification.id)) { console.warn('Notification with the same id already exists!'); return; } inAppNotificationsStore.partialNext({ notifications: [...notifications, notification] }); }; exports.openInAppNotification = openInAppNotification; var closeInAppNotification = id => { if (!id) { console.warn('Notification id is required to be closed!'); return; } var _inAppNotificationsSt2 = inAppNotificationsStore.getLatestValue(), notifications = _inAppNotificationsSt2.notifications; inAppNotificationsStore.partialNext({ notifications: notifications.filter(notification => notification.id !== id) }); }; exports.closeInAppNotification = closeInAppNotification; //# sourceMappingURL=in-app-notifications-store.js.map