[bugfix] Ensure id set on outgoing Reject + Accept (#3312)

This commit is contained in:
tobi 2024-09-16 22:41:04 +02:00 committed by GitHub
parent d4d6631435
commit 4bd5e68b2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 54 deletions

View File

@ -1149,41 +1149,18 @@ func (f *federate) AcceptInteraction(
return nil return nil
} }
// Parse relevant URI(s). // Parse outbox URI.
outboxIRI, err := parseURI(req.TargetAccount.OutboxURI) outboxIRI, err := parseURI(req.TargetAccount.OutboxURI)
if err != nil { if err != nil {
return err return err
} }
acceptingAcctIRI, err := parseURI(req.TargetAccount.URI) // Convert req to Accept.
accept, err := f.converter.InteractionReqToASAccept(ctx, req)
if err != nil { 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. // Send the Accept via the Actor's outbox.
if _, err := f.FederatingActor().Send( if _, err := f.FederatingActor().Send(
ctx, outboxIRI, accept, ctx, outboxIRI, accept,
@ -1221,41 +1198,18 @@ func (f *federate) RejectInteraction(
return nil return nil
} }
// Parse relevant URI(s). // Parse outbox URI.
outboxIRI, err := parseURI(req.TargetAccount.OutboxURI) outboxIRI, err := parseURI(req.TargetAccount.OutboxURI)
if err != nil { if err != nil {
return err return err
} }
rejectingAcctIRI, err := parseURI(req.TargetAccount.URI) // Convert req to Reject.
reject, err := f.converter.InteractionReqToASReject(ctx, req)
if err != nil { 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. // Send the Reject via the Actor's outbox.
if _, err := f.FederatingActor().Send( if _, err := f.FederatingActor().Send(
ctx, outboxIRI, reject, ctx, outboxIRI, reject,

View File

@ -2005,3 +2005,49 @@ func (c *Converter) InteractionReqToASAccept(
return accept, nil 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
}