Browse Source

Simplify handleNotifications

binwiederhier 1 month ago
parent
commit
7cffbfcd6d
1 changed files with 6 additions and 14 deletions
  1. 6 14
      web/src/components/hooks.js

+ 6 - 14
web/src/components/hooks.js

@@ -50,28 +50,20 @@ export const useConnectionListeners = (account, subscriptions, users, webPushTop
       };
 
       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
         if (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);
+        if (!notification.deleted) {
+          const added = await subscriptionManager.addNotification(subscriptionId, notification);
+          if (added) {
+            await subscriptionManager.notify(subscriptionId, notification);
+          }
         }
       };
 
-      const handleDeletedNotification = async (subscriptionId, notification) => {
-        await subscriptionManager.deleteNotificationBySid(subscriptionId, notification.sid);
-      };
-
       const handleMessage = async (subscriptionId, message) => {
         const subscription = await subscriptionManager.get(subscriptionId);