about summary refs log tree commit diff
path: root/app/javascript/mastodon/actions/notifications.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-04-13 01:20:04 +0200
committerGitHub <noreply@github.com>2018-04-13 01:20:04 +0200
commit9e45b051cfea667f9ca3d3c72d13022259315090 (patch)
tree92ebf53b1b2eb389a52d332059360bf248e31ebe /app/javascript/mastodon/actions/notifications.js
parent14d86eb0d076cbadc5944d817ddb731d95312ccf (diff)
When notification type filtered, ignore live updates for it (#7101)
Fix #5625
Diffstat (limited to 'app/javascript/mastodon/actions/notifications.js')
-rw-r--r--app/javascript/mastodon/actions/notifications.js37
1 files changed, 24 insertions, 13 deletions
diff --git a/app/javascript/mastodon/actions/notifications.js b/app/javascript/mastodon/actions/notifications.js
index da77afbe0..7aa070f56 100644
--- a/app/javascript/mastodon/actions/notifications.js
+++ b/app/javascript/mastodon/actions/notifications.js
@@ -9,7 +9,8 @@ import {
 } from './importer';
 import { defineMessages } from 'react-intl';
 
-export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE';
+export const NOTIFICATIONS_UPDATE      = 'NOTIFICATIONS_UPDATE';
+export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP';
 
 export const NOTIFICATIONS_EXPAND_REQUEST = 'NOTIFICATIONS_EXPAND_REQUEST';
 export const NOTIFICATIONS_EXPAND_SUCCESS = 'NOTIFICATIONS_EXPAND_SUCCESS';
@@ -39,21 +40,30 @@ const unescapeHTML = (html) => {
 
 export function updateNotifications(notification, intlMessages, intlLocale) {
   return (dispatch, getState) => {
-    const showAlert = getState().getIn(['settings', 'notifications', 'alerts', notification.type], true);
-    const playSound = getState().getIn(['settings', 'notifications', 'sounds', notification.type], true);
+    const showInColumn = getState().getIn(['settings', 'notifications', 'shows', notification.type], true);
+    const showAlert    = getState().getIn(['settings', 'notifications', 'alerts', notification.type], true);
+    const playSound    = getState().getIn(['settings', 'notifications', 'sounds', notification.type], true);
 
-    dispatch(importFetchedAccount(notification.account));
-    if (notification.status) {
-      dispatch(importFetchedStatus(notification.status));
-    }
+    if (showInColumn) {
+      dispatch(importFetchedAccount(notification.account));
 
-    dispatch({
-      type: NOTIFICATIONS_UPDATE,
-      notification,
-      meta: playSound ? { sound: 'boop' } : undefined,
-    });
+      if (notification.status) {
+        dispatch(importFetchedStatus(notification.status));
+      }
+
+      dispatch({
+        type: NOTIFICATIONS_UPDATE,
+        notification,
+        meta: playSound ? { sound: 'boop' } : undefined,
+      });
 
-    fetchRelatedRelationships(dispatch, [notification]);
+      fetchRelatedRelationships(dispatch, [notification]);
+    } else if (playSound) {
+      dispatch({
+        type: NOTIFICATIONS_UPDATE_NOOP,
+        meta: { sound: 'boop' },
+      });
+    }
 
     // Desktop notifications
     if (typeof window.Notification !== 'undefined' && showAlert) {
@@ -61,6 +71,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
       const body  = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : unescapeHTML(notification.status ? notification.status.content : '');
 
       const notify = new Notification(title, { body, icon: notification.account.avatar, tag: notification.id });
+
       notify.addEventListener('click', () => {
         window.focus();
         notify.close();