From 4bd5e68b2b811eef42045149f4b7abdc6a2ba9e7 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:41:04 +0200 Subject: [PATCH] [bugfix] Ensure id set on outgoing Reject + Accept (#3312) --- internal/processing/workers/federate.go | 62 ++++--------------------- internal/typeutils/internaltoas.go | 46 ++++++++++++++++++ 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/internal/processing/workers/federate.go b/internal/processing/workers/federate.go index d14f38902..a0fd6bf69 100644 --- a/internal/processing/workers/federate.go +++ b/internal/processing/workers/federate.go @@ -1149,41 +1149,18 @@ func (f *federate) AcceptInteraction( return nil } - // Parse relevant URI(s). + // Parse outbox URI. outboxIRI, err := parseURI(req.TargetAccount.OutboxURI) if err != nil { return err } - acceptingAcctIRI, err := parseURI(req.TargetAccount.URI) + // Convert req to Accept. + accept, err := f.converter.InteractionReqToASAccept(ctx, req) if err != nil { - return err + return gtserror.Newf("error converting request to Accept: %w", err) } - interactingAcctURI, err := parseURI(req.InteractingAccount.URI) - if err != nil { - return err - } - - interactionURI, err := parseURI(req.InteractionURI) - if err != nil { - return err - } - - // Create a new Accept. - accept := streams.NewActivityStreamsAccept() - - // Set interacted-with account - // as Actor of the Accept. - ap.AppendActorIRIs(accept, acceptingAcctIRI) - - // Set the interacted-with object - // as Object of the Accept. - ap.AppendObjectIRIs(accept, interactionURI) - - // Address the Accept To the interacting acct. - ap.AppendTo(accept, interactingAcctURI) - // Send the Accept via the Actor's outbox. if _, err := f.FederatingActor().Send( ctx, outboxIRI, accept, @@ -1221,41 +1198,18 @@ func (f *federate) RejectInteraction( return nil } - // Parse relevant URI(s). + // Parse outbox URI. outboxIRI, err := parseURI(req.TargetAccount.OutboxURI) if err != nil { return err } - rejectingAcctIRI, err := parseURI(req.TargetAccount.URI) + // Convert req to Reject. + reject, err := f.converter.InteractionReqToASReject(ctx, req) if err != nil { - return err + return gtserror.Newf("error converting request to Reject: %w", err) } - interactingAcctURI, err := parseURI(req.InteractingAccount.URI) - if err != nil { - return err - } - - interactionURI, err := parseURI(req.InteractionURI) - if err != nil { - return err - } - - // Create a new Reject. - reject := streams.NewActivityStreamsReject() - - // Set interacted-with account - // as Actor of the Reject. - ap.AppendActorIRIs(reject, rejectingAcctIRI) - - // Set the interacted-with object - // as Object of the Reject. - ap.AppendObjectIRIs(reject, interactionURI) - - // Address the Reject To the interacting acct. - ap.AppendTo(reject, interactingAcctURI) - // Send the Reject via the Actor's outbox. if _, err := f.FederatingActor().Send( ctx, outboxIRI, reject, diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go index 03710bec8..d317d6f39 100644 --- a/internal/typeutils/internaltoas.go +++ b/internal/typeutils/internaltoas.go @@ -2005,3 +2005,49 @@ func (c *Converter) InteractionReqToASAccept( return accept, nil } + +// InteractionReqToASReject converts a *gtsmodel.InteractionRequest +// to an ActivityStreams Reject, addressed to the interacting account. +func (c *Converter) InteractionReqToASReject( + ctx context.Context, + req *gtsmodel.InteractionRequest, +) (vocab.ActivityStreamsReject, error) { + reject := streams.NewActivityStreamsReject() + + rejectID, err := url.Parse(req.URI) + if err != nil { + return nil, gtserror.Newf("invalid reject uri: %w", err) + } + + actorIRI, err := url.Parse(req.TargetAccount.URI) + if err != nil { + return nil, gtserror.Newf("invalid account uri: %w", err) + } + + objectIRI, err := url.Parse(req.InteractionURI) + if err != nil { + return nil, gtserror.Newf("invalid target uri: %w", err) + } + + toIRI, err := url.Parse(req.InteractingAccount.URI) + if err != nil { + return nil, gtserror.Newf("invalid interacting account uri: %w", err) + } + + // Set id to the URI of + // interaction request. + ap.SetJSONLDId(reject, rejectID) + + // Actor is the account that + // owns the approval / reject. + ap.AppendActorIRIs(reject, actorIRI) + + // Object is the interaction URI. + ap.AppendObjectIRIs(reject, objectIRI) + + // Address to the owner + // of interaction URI. + ap.AppendTo(reject, toIRI) + + return reject, nil +}