aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShpuld Shpludson <shp@cock.li>2017-11-12 23:28:41 +0000
committerShpuld Shpludson <shp@cock.li>2017-11-12 23:28:41 +0000
commit0584272cf13566d953d32d42efa1c931d72c3311 (patch)
tree6c2db4971b819bc395a3a3e4316c815a0343f4eb /src
parentc7f5f3f59512ea7eb389d9c1543dabe6cfdda55e (diff)
parent4cf580ee31d8257a20b3a615fd7b444a2b5417a0 (diff)
Merge branch 'web-notifs' into 'develop'
Web Notifications See merge request pleroma/pleroma-fe!149
Diffstat (limited to 'src')
-rw-r--r--src/modules/statuses.js19
-rw-r--r--src/modules/users.js4
2 files changed, 23 insertions, 0 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index 5f2f8152..884ba0ef 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -239,6 +239,25 @@ 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') {
+ 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
+
+ // 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.
+ setTimeout(notification.close.bind(notification), 5000)
+ }
}
}
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))