From 3dc375f442cf81d4eae872515188d72bb744350b Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Wed, 30 Aug 2017 00:25:27 +0300
Subject: [PATCH] initial implementation for desktop notifications

---
 src/modules/statuses.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 5f2f8152b..0f45ba1b8 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -239,6 +239,18 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
     // Only add a new notification if we don't have one for the same action
     if (!find(state.notifications, (oldNotification) => oldNotification.action.id === action.id)) {
       state.notifications.push({type, status, action, seen: false})
+
+      if ('Notification' in window && window.Notification.permission === 'granted') {
+        let title = action.user.name
+        let icon = action.user.profile_image_url
+        let body = action.text
+
+        let notification = new window.Notification(title, {body, icon})
+
+        // Chrome is known for not closing notifications automatically
+        // according to MDN, anyway.
+        setTimeout(notification.close.bind(notification), 5000)
+      }
     }
   }
 
-- 
GitLab