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/federation/federatingdb/reject.go | 52 +++++++++++++++++------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'internal/federation/federatingdb/reject.go') diff --git a/internal/federation/federatingdb/reject.go b/internal/federation/federatingdb/reject.go index 5ec3b1a27..88e5ca975 100644 --- a/internal/federation/federatingdb/reject.go +++ b/internal/federation/federatingdb/reject.go @@ -31,6 +31,7 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/log" "code.superseriousbusiness.org/gotosocial/internal/messages" "code.superseriousbusiness.org/gotosocial/internal/uris" + "code.superseriousbusiness.org/gotosocial/internal/util" ) func (f *DB) Reject(ctx context.Context, reject vocab.ActivityStreamsReject) error { @@ -305,21 +306,24 @@ func (f *DB) rejectStatusIRI( InteractingAccountID: receivingAcct.ID, InteractingAccount: receivingAcct, InteractionURI: status.URI, - URI: activityID, + Polite: util.Ptr(false), + ResponseURI: activityID, RejectedAt: time.Now(), } if apObjectType == ap.ObjectNote { // Reply. + req.InteractionRequestURI = gtsmodel.ForwardCompatibleInteractionRequestURI(status.URI, gtsmodel.ReplyRequestSuffix) req.InteractionType = gtsmodel.InteractionReply - req.StatusID = status.InReplyToID - req.Status = status.InReplyTo + req.TargetStatusID = status.InReplyToID + req.TargetStatus = status.InReplyTo req.Reply = status } else { // Announce. + req.InteractionRequestURI = gtsmodel.ForwardCompatibleInteractionRequestURI(status.URI, gtsmodel.AnnounceRequestSuffix) req.InteractionType = gtsmodel.InteractionAnnounce - req.StatusID = status.BoostOfID - req.Status = status.BoostOf + req.TargetStatusID = status.BoostOfID + req.TargetStatus = status.BoostOf req.Announce = status } @@ -331,8 +335,8 @@ func (f *DB) rejectStatusIRI( case req.IsRejected(): // Interaction has already been rejected. Just // update to this Reject URI and then return early. - req.URI = activityID - if err := f.state.DB.UpdateInteractionRequest(ctx, req, "uri"); err != nil { + req.ResponseURI = activityID + if err := f.state.DB.UpdateInteractionRequest(ctx, req, "response_uri"); err != nil { err := gtserror.Newf("db error updating interaction request: %w", err) return gtserror.NewErrorInternalError(err) } @@ -343,11 +347,11 @@ func (f *DB) rejectStatusIRI( // Rejected, even if previously Accepted. req.AcceptedAt = time.Time{} req.RejectedAt = time.Now() - req.URI = activityID + req.ResponseURI = activityID if err := f.state.DB.UpdateInteractionRequest(ctx, req, "accepted_at", "rejected_at", - "uri", + "response_uri", ); err != nil { err := gtserror.Newf("db error updating interaction request: %w", err) return gtserror.NewErrorInternalError(err) @@ -430,16 +434,18 @@ func (f *DB) rejectLikeIRI( // No interaction request existed yet for this // fave, create a pre-rejected request now. req = >smodel.InteractionRequest{ - ID: id.NewULID(), - TargetAccountID: requestingAcct.ID, - TargetAccount: requestingAcct, - InteractingAccountID: receivingAcct.ID, - InteractingAccount: receivingAcct, - InteractionURI: fave.URI, - InteractionType: gtsmodel.InteractionLike, - Like: fave, - URI: activityID, - RejectedAt: time.Now(), + ID: id.NewULID(), + TargetAccountID: requestingAcct.ID, + TargetAccount: requestingAcct, + InteractingAccountID: receivingAcct.ID, + InteractingAccount: receivingAcct, + InteractionRequestURI: gtsmodel.ForwardCompatibleInteractionRequestURI(fave.URI, gtsmodel.LikeRequestSuffix), + InteractionURI: fave.URI, + InteractionType: gtsmodel.InteractionLike, + Polite: util.Ptr(false), + Like: fave, + ResponseURI: activityID, + RejectedAt: time.Now(), } if err := f.state.DB.PutInteractionRequest(ctx, req); err != nil { @@ -450,8 +456,8 @@ func (f *DB) rejectLikeIRI( case req.IsRejected(): // Interaction has already been rejected. Just // update to this Reject URI and then return early. - req.URI = activityID - if err := f.state.DB.UpdateInteractionRequest(ctx, req, "uri"); err != nil { + req.ResponseURI = activityID + if err := f.state.DB.UpdateInteractionRequest(ctx, req, "response_uri"); err != nil { err := gtserror.Newf("db error updating interaction request: %w", err) return gtserror.NewErrorInternalError(err) } @@ -462,11 +468,11 @@ func (f *DB) rejectLikeIRI( // Rejected, even if previously Accepted. req.AcceptedAt = time.Time{} req.RejectedAt = time.Now() - req.URI = activityID + req.ResponseURI = activityID if err := f.state.DB.UpdateInteractionRequest(ctx, req, "accepted_at", "rejected_at", - "uri", + "response_uri", ); err != nil { err := gtserror.Newf("db error updating interaction request: %w", err) return gtserror.NewErrorInternalError(err) -- cgit v1.2.3