} 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';
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));
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' },
}
// 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 : '');
}
};
+export const getFilters = (state, { contextType }) => state.get('filters', ImmutableList()).filter(filter => contextType && filter.get('context').includes(toServerSideType(contextType)) && (filter.get('expires_at') === null || Date.parse(filter.get('expires_at')) > (new Date())));
+
const escapeRegExp = string =>
string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
-const regexFromFilters = filters => {
+export const regexFromFilters = filters => {
if (filters.size === 0) {
return null;
}
(state, { id }) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]),
(state, { id }) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]),
(state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]),
- (state, { contextType }) => state.get('filters', ImmutableList()).filter(filter => contextType && filter.get('context').includes(toServerSideType(contextType)) && (filter.get('expires_at') === null || Date.parse(filter.get('expires_at')) > (new Date()))),
+ getFilters,
],
(statusBase, statusReblog, accountBase, accountReblog, filters) => {