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] Interaction requests client api + settings panel #3215

Merged
merged 21 commits into from
Aug 24, 2024

Conversation

tsmethurst
Copy link
Contributor

@tsmethurst tsmethurst commented Aug 19, 2024

Description

If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.

If this is a documentation change, please briefly describe what you've changed and why.

This pull request adds review and rejection / approval of interaction requests via the client API and settings panel.

Screenshot from 2024-08-19 14-32-41

Screenshot from 2024-08-19 14-32-51

To support this, requests and rejections are now stored in the database in addition to approvals, as that was just the easiest way of making it possible to page through requests (and, in future, page through approvals and rejections).

The structure of the approvals table has also changed. To make things a bit easier for myself, the current table is just dropped and recreated with the new schema, which means existing approvals will be lost. Since approvals were not in a release yet, I don't think this is a big deal, since only people running snapshots had interaction policies up to now (and therefore stored Accepts), but I welcome feedback on this and can make more of an effort to preserve existing Accepts if we decide it's necessary to do this.

Still draft because I'd still like to do the following:

  • [ ] Clean up any lingering unique indexes from dropped table (if db type = postgres) Not necessary.
  • Add some more tests.
  • [ ] Have the interaction filter check if a previous InteractionRejection exists for a fave or boost of a status by a given account, and automatically reject reattempts (so people can't spam interaction requests at you). I'll do this in a separate PR + it might not be necessary or desirable anyway, not sure yet.

Part of #3057

Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: [ ] -> [x]

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

  • 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. -- will do this in a separate PR
  • 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 tsmethurst changed the title [feature] Interaction requests client api [feature] Interaction requests client api + settings panel Aug 19, 2024
@tsmethurst tsmethurst force-pushed the interaction_requests_client_api branch from a36c033 to 29e4726 Compare August 20, 2024 13:32
@tsmethurst tsmethurst marked this pull request as ready for review August 20, 2024 14:44
ctx context.Context,
req *gtsmodel.InteractionRequest,
) (*gtsmodel.InteractionApproval, gtserror.WithCode) {
if req.Like == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need to check for these here. if they were nil but the ID for the object was there as it should be, then the initial GetInteractionRequest() to the database should have returned error in the final stage populating it. Adding these nil checks here makes it seem like this is an (at least somewhat) expected situation. Absolute worst-case it'll just panic on attempting to deref ptr below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if that does happen, it could potentially be a serious issue. a not-found is likely to end up getting masked and we won't end up dealing with it, whereas a panic and unexpected 500 definitely does get our attention :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the db functions to be OK with NotFound errors when trying to fetch a Like, Reply, or Announce to populate an interaction request. Especially now that rejections are using the same model as accepts and requests, there's a fair chance that if someone tries to fetch an interaction request from the db, and it's for something that's been rejected, the Like, Reply, or Announce won't be in the database anymore, so it is a semi-expected error. Given that, I think it's sensible to have nil checking here. I've changed it now so that an error not found is returned if the Like (or whatever) can't be found, which should be warning enough I think.

}

if !includeLikes && !includeReplies && !includeBoosts {
const text = "at least one of favourites, replies, or boosts must be true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the api response may make a bit more sense if this was must be set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather leave it as is, since "must be set" would also suggest you could set them all, but to false.

TableExpr("? AS ?", bun.Ident("statuses"), bun.Ident("status")).
Where("? = ?", bun.Ident("status.account_id"), account.ID).
Where("? IS NOT NULL", bun.Ident("status.pinned_at")).
Where("NOT ? = ?", bun.Ident("status.pending_approval"), true).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this actually possible for a pinned status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you could create a reply to someone, and then try to pin your reply. Or something daft like that. I suppose we could just make it so that you can't pin pending statuses, instead.

docs/api/swagger.yaml Outdated Show resolved Hide resolved
@tsmethurst tsmethurst merged commit f23f04e into main Aug 24, 2024
3 checks passed
@tsmethurst tsmethurst deleted the interaction_requests_client_api branch August 24, 2024 09:49
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.

3 participants