From 754b7be9cfd3f50e6e219177cdd4c992a2d9c38f Mon Sep 17 00:00:00 2001 From: tobi Date: Sun, 14 Sep 2025 15:37:35 +0200 Subject: [feature] Support new model of interaction flow for forward compat with v0.21.0 (#4394) ~~Still WIP!~~ This PR allows v0.20.0 of GtS to be forward-compatible with the interaction request / authorization flow that will fully replace the current flow in v0.21.0. Basically, this means we need to recognize LikeRequest, ReplyRequest, and AnnounceRequest, and in response to those requests, deliver either a Reject or an Accept, with the latter pointing towards a LikeAuthorization, ReplyAuthorization, or AnnounceAuthorization, respectively. This can then be used by the remote instance to prove to third parties that the interaction has been accepted by the interactee. These Authorization types need to be dereferencable to third parties, so we need to serve them. As well as recognizing the above "polite" interaction request types, we also need to still serve appropriate responses to "impolite" interaction request types, where an instance that's unaware of interaction policies tries to interact with a post by sending a reply, like, or boost directly, without wrapping it in a WhateverRequest type. Doesn't fully close https://codeberg.org/superseriousbusiness/gotosocial/issues/4026 but gets damn near (just gotta update the federating with GtS documentation). Migrations tested on both Postgres and SQLite. Co-authored-by: kim Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4394 Co-authored-by: tobi Co-committed-by: tobi --- internal/db/bundb/interaction.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'internal/db/bundb/interaction.go') diff --git a/internal/db/bundb/interaction.go b/internal/db/bundb/interaction.go index b42eb46f6..2128a7aa6 100644 --- a/internal/db/bundb/interaction.go +++ b/internal/db/bundb/interaction.go @@ -58,31 +58,45 @@ func (i *interactionDB) GetInteractionRequestByID(ctx context.Context, id string ) } -func (i *interactionDB) GetInteractionRequestByInteractionURI(ctx context.Context, uri string) (*gtsmodel.InteractionRequest, error) { +func (i *interactionDB) GetInteractionRequestByInteractionURI(ctx context.Context, intURI string) (*gtsmodel.InteractionRequest, error) { return i.getInteractionRequest( ctx, "InteractionURI", func(request *gtsmodel.InteractionRequest) error { return i. newInteractionRequestQ(request). - Where("? = ?", bun.Ident("interaction_request.interaction_uri"), uri). + Where("? = ?", bun.Ident("interaction_request.interaction_uri"), intURI). Scan(ctx) }, - uri, + intURI, ) } -func (i *interactionDB) GetInteractionRequestByURI(ctx context.Context, uri string) (*gtsmodel.InteractionRequest, error) { +func (i *interactionDB) GetInteractionRequestByResponseURI(ctx context.Context, respURI string) (*gtsmodel.InteractionRequest, error) { return i.getInteractionRequest( ctx, - "URI", + "ResponseURI", func(request *gtsmodel.InteractionRequest) error { return i. newInteractionRequestQ(request). - Where("? = ?", bun.Ident("interaction_request.uri"), uri). + Where("? = ?", bun.Ident("interaction_request.response_uri"), respURI). Scan(ctx) }, - uri, + respURI, + ) +} + +func (i *interactionDB) GetInteractionRequestByAuthorizationURI(ctx context.Context, authURI string) (*gtsmodel.InteractionRequest, error) { + return i.getInteractionRequest( + ctx, + "AuthorizationURI", + func(request *gtsmodel.InteractionRequest) error { + return i. + newInteractionRequestQ(request). + Where("? = ?", bun.Ident("interaction_request.authorization_uri"), authURI). + Scan(ctx) + }, + authURI, ) } @@ -173,11 +187,11 @@ func (i *interactionDB) PopulateInteractionRequest(ctx context.Context, req *gts errs = gtserror.NewMultiError(4) ) - if req.Status == nil { + if req.TargetStatus == nil { // Target status is not set, fetch from the database. - req.Status, err = i.state.DB.GetStatusByID( + req.TargetStatus, err = i.state.DB.GetStatusByID( gtscontext.SetBarebones(ctx), - req.StatusID, + req.TargetStatusID, ) if err != nil { errs.Appendf("error populating interactionRequest target: %w", err) -- cgit v1.2.3