Skip to content

Commit 9d7ec82

Browse files
ClearlyClaireGargron
authored andcommitted
Apply filters to poll options (mastodon#11174)
* Apply filters to poll options in WebUI Fixes mastodon#11128 * Apply filters to poll options server-side * Add poll options to searchable text
1 parent 4aa8354 commit 9d7ec82

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

app/chewy/statuses_index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class StatusesIndex < Chewy::Index
5151
field :id, type: 'long'
5252
field :account_id, type: 'long'
5353

54-
field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.media_attachments.map(&:description)).join("\n\n") } do
54+
field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.media_attachments.map(&:description)).concat(status.preloadable_poll ? status_preloadable_poll.options : []).join("\n\n") } do
5555
field :stemmed, type: 'text', analyzer: 'content'
5656
end
5757

app/javascript/mastodon/actions/importer/normalizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function normalizeStatus(status, normalOldStatus) {
5656
normalStatus.hidden = normalOldStatus.get('hidden');
5757
} else {
5858
const spoilerText = normalStatus.spoiler_text || '';
59-
const searchContent = [spoilerText, status.content].join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
59+
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');
6060
const emojiMap = makeEmojiMap(normalStatus);
6161

6262
normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;

app/lib/feed_manager.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def phrase_filtered?(status, receiver_id, context)
220220
status = status.reblog if status.reblog?
221221

222222
!combined_regex.match(Formatter.instance.plaintext(status)).nil? ||
223-
(status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?)
223+
(status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?) ||
224+
(status.preloadable_poll && !combined_regex.match(status.preloadable_poll.options.join("\n\n")).nil?)
224225
end
225226

226227
# Adds a status to an account's feed, returning true if a status was

spec/lib/feed_manager_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@
149149
status = Fabricate(:status, text: 'shiitake', account: jeff)
150150
expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
151151
end
152+
153+
it 'returns true if phrase is contained in a poll option' do
154+
alice.custom_filters.create!(phrase: 'farts', context: %w(home public), irreversible: true)
155+
alice.custom_filters.create!(phrase: 'pop tarts', context: %w(home), irreversible: true)
156+
alice.follow!(jeff)
157+
status = Fabricate(:status, text: 'what do you prefer', poll: Fabricate(:poll, options: %w(farts POP TARts)), account: jeff)
158+
expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
159+
end
152160
end
153161
end
154162

0 commit comments

Comments
 (0)