Skip to content

Commit

Permalink
Fix notification filters not applying to poll options (mastodon#12269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Gargron committed Nov 4, 2019
1 parent 1018097 commit 1a12943
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/javascript/mastodon/actions/importer/normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => {
return obj;
}, {});

export function searchTextFromRawStatus (status) {
const spoilerText = status.spoiler_text || '';
const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
return domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
}

export function normalizeAccount(account) {
account = { ...account };

Expand Down
3 changes: 2 additions & 1 deletion app/javascript/mastodon/actions/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { unescapeHTML } from '../utils/html';
import { getFiltersRegex } from '../selectors';
import { usePendingItems as preferPendingItems } from 'mastodon/initial_state';
import compareId from 'mastodon/compare_id';
import { searchTextFromRawStatus } from 'mastodon/actions/importer/normalizer';

export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE';
export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP';
Expand Down Expand Up @@ -60,7 +61,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
if (notification.type === 'mention') {
const dropRegex = filters[0];
const regex = filters[1];
const searchIndex = notification.status.spoiler_text + '\n' + unescapeHTML(notification.status.content);
const searchIndex = searchTextFromRawStatus(notification.status);

if (dropRegex && dropRegex.test(searchIndex)) {
return;
Expand Down

0 comments on commit 1a12943

Please sign in to comment.