about summary refs log tree commit diff
path: root/app/javascript/mastodon/service_worker
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-08-23 21:44:27 +0200
committerEugen Rochko <eugen@zeonfederated.com>2018-08-23 21:44:27 +0200
commit7786e1357bbe456243679c91f88679cdd260fa8f (patch)
tree5bb13cc75a41978fb4209c7ddd748454d1d67887 /app/javascript/mastodon/service_worker
parentf9b23a5d6247445ea5b70b431c934a4bb99213bc (diff)
Only display web push notifications after API call (fixes #7902) (#8396)
* Only display web push notifications after API call (fixes #7902)

* Decode then truncate instead of truncating then decoding in webpush serializer
Diffstat (limited to 'app/javascript/mastodon/service_worker')
-rw-r--r--app/javascript/mastodon/service_worker/web_push_notifications.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/app/javascript/mastodon/service_worker/web_push_notifications.js b/app/javascript/mastodon/service_worker/web_push_notifications.js
index 3318bbadc..d61d916b1 100644
--- a/app/javascript/mastodon/service_worker/web_push_notifications.js
+++ b/app/javascript/mastodon/service_worker/web_push_notifications.js
@@ -80,15 +80,7 @@ const handlePush = (event) => {
 
   // Placeholder until more information can be loaded
   event.waitUntil(
-    notify({
-      title,
-      body,
-      icon,
-      tag: notification_id,
-      timestamp: new Date(),
-      badge: '/badge.png',
-      data: { access_token, preferred_locale, url: '/web/notifications' },
-    }).then(() => fetchFromApi(`/api/v1/notifications/${notification_id}`, 'get', access_token)).then(notification => {
+    fetchFromApi(`/api/v1/notifications/${notification_id}`, 'get', access_token).then(notification => {
       const options = {};
 
       options.title     = formatMessage(`notification.${notification.type}`, preferred_locale, { name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username });
@@ -112,6 +104,16 @@ const handlePush = (event) => {
       }
 
       return notify(options);
+    }).catch(() => {
+      return notify({
+        title,
+        body,
+        icon,
+        tag: notification_id,
+        timestamp: new Date(),
+        badge: '/badge.png',
+        data: { access_token, preferred_locale, url: '/web/notifications' },
+      });
     })
   );
 };