Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Implement Filter API v2 #2936

Merged
merged 16 commits into from
May 31, 2024

Conversation

VyrCossont
Copy link
Contributor

@VyrCossont VyrCossont commented May 27, 2024

Description

This pull request implements the Mastodon v2 filter API. v2 allows filters to be grouped and named, but the most important addition is the ability to filter individual statuses, which is not possible with v1. Want to hide an inflammatory, irrelevant, or unfunny post that your friends keep boosting? Now you can.

This is a follow-up to #2793, which implemented server-side filtering but only exposed it through the v1 API.

It also fixes several tests and minor bugs in the v1 filter API.

Impact

Phanpy only supports v2 filters, so this should make Phanpy more useful as a GtS frontend. (Tusky seems to be able to fall back to v1 if v2 isn't available, Feditext doesn't support v2 yet feditext/feditext#57, and Semaphore is EOL and only supports v1.)

Open questions

This version implements the keywords_attributes param for creating and updating filter keywords in the same API call as creating or updating a filter, and extends this to filter statuses with statuses_attributes parameters.

However, this functionality doesn't seem to be very well thought out. (More detail in https://princess.industries/@vyr/statuses/01HXDEFGK0W8R4M4X7TKB2RKNJ which is an unlisted post on a GtS instance so open that link in your Fedi client.) It duplicates separate calls for creating and updating filter keywords, I've had to make a lot of assumptions implementing it because it's based on a poorly documented Rails feature which doesn't map naturally to form parameters, and I haven't found a client that uses it to test against. Tusky actually has a comment suggesting that they avoided it on purpose:

This is terrible, but the all-in-one update filter api Just Doesn't Work

So maybe it'd be smarter to omit keywords_attributes and statuses_attributes, on the basis that they can't be incompatible with the Mastodon implementation if we don't ship them at all. However, I'd like to hear from client devs and make sure nobody is expecting to use them first.

Resolved: we're dropping these.

Checklist

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have not leveraged AI to create the proposed changes.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

@tsmethurst
Copy link
Contributor

Wow! Thanks for this PR :D

Re: those _attributes params, I'd be happy to just drop them from this PR and we can implement that functionality later if necessary (if there are clients that break without it).

@VyrCossont
Copy link
Contributor Author

@tsmethurst sounds good. I'll remove that feature from this PR and we can resurrect it later if necessary.

@daenney daenney changed the title Implement Filter API v2 [feature] Implement Filter API v2 May 29, 2024
@tsmethurst
Copy link
Contributor

Great PR! I have only a few small comments and questions about error handling + return values. Once those are resolved this can be squerged imo. Excellent work, thank you for this :)

@tsmethurst tsmethurst merged commit 61a8d36 into superseriousbusiness:main May 31, 2024
2 checks passed
@tsmethurst
Copy link
Contributor

Great stuff!

nyarla pushed a commit to nyarla/gotosocial-modded that referenced this pull request Jun 19, 2024
* Use correct entity name

* We support server-side filters now

* Document filter v1 methods that can throw a 409

* Validate v1 filter phrase as filter title

* Always check v1 filter API status codes in tests

* Document keyword minimum requirement on filter API v1

* Make it possible to specify filter keyword update columns per filter keyword

* Implement v2 filter API

* Fix lint and tests

* Update Swagger spec

* Fix filter update test

* Update Swagger spec *correctly*

* Update actual files Swagger spec was generated from

* Remove keywords_attributes and statuses_attributes

* Add test for serialization of empty filter

* More helpful messages when object is owned by wrong account
nyarla pushed a commit to nyarla/gotosocial-modded that referenced this pull request Jun 19, 2024
* Use correct entity name

* We support server-side filters now

* Document filter v1 methods that can throw a 409

* Validate v1 filter phrase as filter title

* Always check v1 filter API status codes in tests

* Document keyword minimum requirement on filter API v1

* Make it possible to specify filter keyword update columns per filter keyword

* Implement v2 filter API

* Fix lint and tests

* Update Swagger spec

* Fix filter update test

* Update Swagger spec *correctly*

* Update actual files Swagger spec was generated from

* Remove keywords_attributes and statuses_attributes

* Add test for serialization of empty filter

* More helpful messages when object is owned by wrong account
@VyrCossont VyrCossont deleted the filter-api-v2 branch July 26, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants