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 1/2] 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 5f2f8152..0f45ba1b 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)
+      }
     }
   }
 

From 4cf580ee31d8257a20b3a615fd7b444a2b5417a0 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Mon, 13 Nov 2017 00:11:55 +0300
Subject: [PATCH 2/2] moved notification asking from page load to login event.
 Added image in notifications support (doesn't work for native KDE
 notifications for me tho)

---
 src/modules/statuses.js | 15 +++++++++++----
 src/modules/users.js    |  4 ++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 0f45ba1b..884ba0ef 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -241,11 +241,18 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
       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
+        const title = action.user.name
+        const result = {}
+        result.icon = action.user.profile_image_url
+        result.body = action.text // there's a problem that it doesn't put a space before links tho
 
-        let notification = new window.Notification(title, {body, icon})
+        // Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
+        if (action.attachments.length > 0 && !action.nsfw &&
+            action.attachments[0].mimetype.startsWith('image/')) {
+          result.image = action.attachments[0].url
+        }
+
+        let notification = new window.Notification(title, result)
 
         // Chrome is known for not closing notifications automatically
         // according to MDN, anyway.
diff --git a/src/modules/users.js b/src/modules/users.js
index f29cbf98..c8b6f0de 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -102,6 +102,10 @@ const users = {
                     store.commit('addNewUsers', mutedUsers)
                   })
 
+                  if ('Notification' in window && window.Notification.permission === 'default') {
+                    window.Notification.requestPermission()
+                  }
+
                   // Fetch our friends
                   store.rootState.api.backendInteractor.fetchFriends()
                     .then((friends) => commit('addNewUsers', friends))