diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-07-07 19:31:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-07 19:31:19 +0200 |
commit | cfeb3beb4e1c3a05392546e6e4584de537049989 (patch) | |
tree | 2af0c147474be3cca1af704393835607d4bb141f /app/javascript/mastodon/actions | |
parent | cd509d2146439490bcb63081739db1d5fd485d56 (diff) |
Fix filters not affecting notifications in web UI (#7977)
* Hook up filtering to statuses in notifications column * Filter notifications for sound, desktop notifications
Diffstat (limited to 'app/javascript/mastodon/actions')
-rw-r--r-- | app/javascript/mastodon/actions/notifications.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/app/javascript/mastodon/actions/notifications.js b/app/javascript/mastodon/actions/notifications.js index 3f95f6667..ad6430b82 100644 --- a/app/javascript/mastodon/actions/notifications.js +++ b/app/javascript/mastodon/actions/notifications.js @@ -9,6 +9,7 @@ import { } from './importer'; import { defineMessages } from 'react-intl'; import { unescapeHTML } from '../utils/html'; +import { getFilters, regexFromFilters } from '../selectors'; export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE'; export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP'; @@ -38,6 +39,16 @@ export function updateNotifications(notification, intlMessages, intlLocale) { 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); + const filters = getFilters(getState(), { contextType: 'notifications' }); + + let filtered = false; + + if (notification.type === 'mention') { + const regex = regexFromFilters(filters); + const searchIndex = notification.status.spoiler_text + '\n' + unescapeHTML(notification.status.content); + + filtered = regex && regex.test(searchIndex); + } if (showInColumn) { dispatch(importFetchedAccount(notification.account)); @@ -49,11 +60,11 @@ export function updateNotifications(notification, intlMessages, intlLocale) { dispatch({ type: NOTIFICATIONS_UPDATE, notification, - meta: playSound ? { sound: 'boop' } : undefined, + meta: (playSound && !filtered) ? { sound: 'boop' } : undefined, }); fetchRelatedRelationships(dispatch, [notification]); - } else if (playSound) { + } else if (playSound && !filtered) { dispatch({ type: NOTIFICATIONS_UPDATE_NOOP, meta: { sound: 'boop' }, @@ -61,7 +72,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) { } // Desktop notifications - if (typeof window.Notification !== 'undefined' && showAlert) { + if (typeof window.Notification !== 'undefined' && showAlert && !filtered) { const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username }); const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : unescapeHTML(notification.status ? notification.status.content : ''); |