]> cat aescling's git repositories - mastodon.git/commitdiff
Only display web push notifications after API call (fixes #7902) (#8396)
authorThibG <thib@sitedethib.com>
Thu, 23 Aug 2018 19:44:27 +0000 (21:44 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 23 Aug 2018 19:44:27 +0000 (21:44 +0200)
* Only display web push notifications after API call (fixes #7902)

* Decode then truncate instead of truncating then decoding in webpush serializer

app/javascript/mastodon/service_worker/web_push_notifications.js
app/serializers/web/notification_serializer.rb

index 3318bbadccf0b71d1c7bce6e79b963df93ab29af..d61d916b199a8e68242405964095e9f2c68ebbef 100644 (file)
@@ -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' },
+      });
     })
   );
 };
index 43ba4d92a26c2d86ad7429c080875cafa635fce2..ee83ec8b26e7e46376ca490be9f131a0af5b5f41 100644 (file)
@@ -33,7 +33,7 @@ class Web::NotificationSerializer < ActiveModel::Serializer
   end
 
   def body
-    str = truncate(strip_tags(object.target_status&.spoiler_text&.presence || object.target_status&.text || object.from_account.note), length: 140)
-    HTMLEntities.new.decode(str.to_str) # Do not encode entities, since this value will not be used in HTML
+    str = strip_tags(object.target_status&.spoiler_text&.presence || object.target_status&.text || object.from_account.note)
+    truncate(HTMLEntities.new.decode(str.to_str), length: 140) # Do not encode entities, since this value will not be used in HTML
   end
 end