]> cat aescling's git repositories - mastodon.git/commit
Revamp post filtering system (#18058)
authorClaire <claire.github-309c@sitedethib.com>
Tue, 28 Jun 2022 07:42:13 +0000 (09:42 +0200)
committeraescling <aescling+gitlab@cat.family>
Mon, 5 Sep 2022 04:27:52 +0000 (00:27 -0400)
commitc12afe894ac93e76cb4e17e1916aeac7c1fbfaf6
tree4519a5276e4f058aeb26937713f3d571391128b0
parent8b8a309a84731aba0215de995f52a7519f2e5000
Revamp post filtering system (#18058)

* Add model for custom filter keywords

* Use CustomFilterKeyword internally

Does not change the API

* Fix /filters/edit and /filters/new

* Add migration tests

* Remove whole_word column from custom_filters (covered by custom_filter_keywords)

* Redesign /filters

Instead of a list, present a card that displays more information and handles
multiple keywords per filter.

* Redesign /filters/new and /filters/edit to add and remove keywords

This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.

* Add /api/v2/filters to edit filter with multiple keywords

Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
  `keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`

API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
  `keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
  `keywords_attributes` can also be passed to edit, delete or add keywords in
   one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
   filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword

* Change from `irreversible` boolean to `action` enum

* Remove irrelevent `irreversible_must_be_within_context` check

* Fix /filters/new and /filters/edit with update for filter_action

* Fix Rubocop/Codeclimate complaining about task names

* Refactor FeedManager#phrase_filtered?

This moves regexp building and filter caching to the `CustomFilter` class.

This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.

* Perform server-side filtering and output result in REST API

* Fix numerous filters_changed events being sent when editing multiple keywords at once

* Add some tests

* Use the new API in the WebUI

- use client-side logic for filters we have fetched rules for.
  This is so that filter changes can be retroactively applied without
  reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
  (e.g. network error, or initial timeline loading)

* Minor optimizations and refactoring

* Perform server-side filtering on the streaming server

* Change the wording of filter action labels

* Fix issues pointed out by linter

* Change design of “Show anyway” link in accordence to review comments

* Drop “irreversible” filtering behavior

* Move /api/v2/filter_keywords to /api/v1/filters/keywords

* Rename `filter_results` attribute to `filtered`

* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer

* Fix systemChannelId value in streaming server

* Simplify code by removing client-side filtering code

The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
59 files changed:
Gemfile
Gemfile.lock
app/controllers/api/v1/filters/keywords_controller.rb [new file with mode: 0644]
app/controllers/api/v1/filters_controller.rb
app/controllers/api/v2/filters_controller.rb [new file with mode: 0644]
app/controllers/filters_controller.rb
app/javascript/mastodon/actions/filters.js [deleted file]
app/javascript/mastodon/actions/importer/index.js
app/javascript/mastodon/actions/importer/normalizer.js
app/javascript/mastodon/actions/notifications.js
app/javascript/mastodon/actions/streaming.js
app/javascript/mastodon/components/status.js
app/javascript/mastodon/components/status_action_bar.js
app/javascript/mastodon/features/ui/index.js
app/javascript/mastodon/reducers/filters.js
app/javascript/mastodon/selectors/index.js
app/javascript/packs/public.js
app/javascript/styles/mastodon/admin.scss
app/javascript/styles/mastodon/components.scss
app/javascript/styles/mastodon/forms.scss
app/lib/feed_manager.rb
app/models/concerns/account_interactions.rb
app/models/custom_filter.rb
app/models/custom_filter_keyword.rb [new file with mode: 0644]
app/presenters/filter_result_presenter.rb [new file with mode: 0644]
app/presenters/status_relationships_presenter.rb
app/serializers/rest/filter_keyword_serializer.rb [new file with mode: 0644]
app/serializers/rest/filter_result_serializer.rb [new file with mode: 0644]
app/serializers/rest/filter_serializer.rb
app/serializers/rest/status_serializer.rb
app/serializers/rest/v1/filter_serializer.rb [new file with mode: 0644]
app/views/filters/_fields.html.haml [deleted file]
app/views/filters/_filter.html.haml [new file with mode: 0644]
app/views/filters/_filter_fields.html.haml [new file with mode: 0644]
app/views/filters/_keyword_fields.html.haml [new file with mode: 0644]
app/views/filters/edit.html.haml
app/views/filters/index.html.haml
app/views/filters/new.html.haml
config/locales/en.yml
config/locales/simple_form.en.yml
config/routes.rb
db/migrate/20220613110628_create_custom_filter_keywords.rb [new file with mode: 0644]
db/migrate/20220613110711_migrate_custom_filters.rb [new file with mode: 0644]
db/migrate/20220613110834_add_action_to_custom_filters.rb [new file with mode: 0644]
db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb [new file with mode: 0644]
db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb [new file with mode: 0644]
db/schema.rb
lib/tasks/tests.rake
package.json
spec/controllers/api/v1/filters/keywords_controller_spec.rb [new file with mode: 0644]
spec/controllers/api/v1/filters_controller_spec.rb
spec/controllers/api/v1/statuses_controller_spec.rb
spec/controllers/api/v2/filters_controller_spec.rb [new file with mode: 0644]
spec/fabricators/custom_filter_keyword_fabricator.rb [new file with mode: 0644]
spec/lib/feed_manager_spec.rb
spec/models/custom_filter_keyword_spec.rb [new file with mode: 0644]
spec/presenters/status_relationships_presenter_spec.rb
streaming/index.js
yarn.lock