about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-05-27 04:55:19 +0200
committerYamagishi Kazutoshi <ykzts@desire.sh>2018-05-27 11:55:19 +0900
commit182bdbc5f4f0194cdd7b771246304c2dfc6f19e0 (patch)
treed468c5651d5d013530cbe944a5d4332bb913c935 /app
parent422f92f3f8a60048bb2a5df4b04a1d16fc6fe5b1 (diff)
Don't use Object.assign with Notification, only display actions for mentions (#7632)
Fix #7627
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/service_worker/web_push_notifications.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/app/javascript/mastodon/service_worker/web_push_notifications.js b/app/javascript/mastodon/service_worker/web_push_notifications.js
index f922f7dd0..3318bbadc 100644
--- a/app/javascript/mastodon/service_worker/web_push_notifications.js
+++ b/app/javascript/mastodon/service_worker/web_push_notifications.js
@@ -25,7 +25,7 @@ const notify = options =>
 
       return self.registration.showNotification(group.title, group);
     } else if (notifications.length === 1 && notifications[0].tag === GROUP_TAG) { // Already grouped, proceed with appending the notification to the group
-      const group = { ...notifications[0] };
+      const group = cloneNotification(notifications[0]);
 
       group.title = formatMessage('notifications.group', options.data.preferred_locale, { count: group.data.count + 1 });
       group.body  = `${options.title}\n${group.body}`;
@@ -57,6 +57,18 @@ const fetchFromApi = (path, method, accessToken) => {
   }).then(res => res.json());
 };
 
+const cloneNotification = notification => {
+  const clone = {};
+  let k;
+
+  // Object.assign() does not work with notifications
+  for(k in notification) {
+    clone[k] = notification[k];
+  }
+
+  return clone;
+};
+
 const formatMessage = (messageId, locale, values = {}) =>
   (new IntlMessageFormat(locales[locale][messageId], locale)).format(values);
 
@@ -95,7 +107,7 @@ const handlePush = (event) => {
         options.body    = notification.status.spoiler_text;
         options.image   = undefined;
         options.actions = [actionExpand(preferred_locale)];
-      } else if (notification.status) {
+      } else if (notification.type === 'mention') {
         options.actions = [actionReblog(preferred_locale), actionFavourite(preferred_locale)];
       }
 
@@ -130,7 +142,7 @@ const findBestClient = clients => {
 };
 
 const expandNotification = notification => {
-  const newNotification = { ...notification };
+  const newNotification = cloneNotification(notification);
 
   newNotification.body    = newNotification.data.hiddenBody;
   newNotification.image   = newNotification.data.hiddenImage;
@@ -140,7 +152,7 @@ const expandNotification = notification => {
 };
 
 const removeActionFromNotification = (notification, action) => {
-  const newNotification = { ...notification };
+  const newNotification = cloneNotification(notification);
 
   newNotification.actions = newNotification.actions.filter(item => item.action !== action);