Simplify handleNotifications
This commit is contained in:
@@ -50,26 +50,18 @@ export const useConnectionListeners = (account, subscriptions, users, webPushTop
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleNotification = async (subscriptionId, notification) => {
|
const handleNotification = async (subscriptionId, notification) => {
|
||||||
if (notification.deleted && notification.sid) {
|
|
||||||
return handleDeletedNotification(subscriptionId, notification);
|
|
||||||
}
|
|
||||||
return handleNewOrUpdatedNotification(subscriptionId, notification);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleNewOrUpdatedNotification = async (subscriptionId, notification) => {
|
|
||||||
// Delete existing notification with same sid, if any
|
// Delete existing notification with same sid, if any
|
||||||
if (notification.sid) {
|
if (notification.sid) {
|
||||||
await subscriptionManager.deleteNotificationBySid(subscriptionId, notification.sid);
|
await subscriptionManager.deleteNotificationBySid(subscriptionId, notification.sid);
|
||||||
}
|
}
|
||||||
// Add notification to database
|
|
||||||
const added = await subscriptionManager.addNotification(subscriptionId, notification);
|
|
||||||
if (added) {
|
|
||||||
await subscriptionManager.notify(subscriptionId, notification);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeletedNotification = async (subscriptionId, notification) => {
|
// Add notification to database
|
||||||
await subscriptionManager.deleteNotificationBySid(subscriptionId, notification.sid);
|
if (!notification.deleted) {
|
||||||
|
const added = await subscriptionManager.addNotification(subscriptionId, notification);
|
||||||
|
if (added) {
|
||||||
|
await subscriptionManager.notify(subscriptionId, notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMessage = async (subscriptionId, message) => {
|
const handleMessage = async (subscriptionId, message) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user