mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Interaction requests client api + settings panel (#3215)
* [feature] Interaction requests client api + settings panel * test accept / reject * fmt * don't pin rejected interaction * use single db model for interaction accept, reject, and request * swaggor * env sharting * append errors * remove ErrNoEntries checks * change intReqID to reqID * rename "pend" to "request" * markIntsPending -> mark interactionsPending * use log instead of returning error when rejecting interaction * empty migration * jolly renaming * make interactionURI unique again * swag grr * remove unnecessary locks * invalidate as last step
This commit is contained in:
@@ -1127,17 +1127,17 @@ func (f *federate) MoveAccount(ctx context.Context, account *gtsmodel.Account) e
|
||||
|
||||
func (f *federate) AcceptInteraction(
|
||||
ctx context.Context,
|
||||
approval *gtsmodel.InteractionApproval,
|
||||
req *gtsmodel.InteractionRequest,
|
||||
) error {
|
||||
// Populate model.
|
||||
if err := f.state.DB.PopulateInteractionApproval(ctx, approval); err != nil {
|
||||
return gtserror.Newf("error populating approval: %w", err)
|
||||
if err := f.state.DB.PopulateInteractionRequest(ctx, req); err != nil {
|
||||
return gtserror.Newf("error populating request: %w", err)
|
||||
}
|
||||
|
||||
// Bail if interacting account is ours:
|
||||
// we've already accepted internally and
|
||||
// shouldn't send an Accept to ourselves.
|
||||
if approval.InteractingAccount.IsLocal() {
|
||||
if req.InteractingAccount.IsLocal() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1145,27 +1145,27 @@ func (f *federate) AcceptInteraction(
|
||||
// we can't Accept on another
|
||||
// instance's behalf. (This
|
||||
// should never happen but...)
|
||||
if approval.Account.IsRemote() {
|
||||
if req.TargetAccount.IsRemote() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parse relevant URI(s).
|
||||
outboxIRI, err := parseURI(approval.Account.OutboxURI)
|
||||
outboxIRI, err := parseURI(req.TargetAccount.OutboxURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acceptingAcctIRI, err := parseURI(approval.Account.URI)
|
||||
acceptingAcctIRI, err := parseURI(req.TargetAccount.URI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
interactingAcctURI, err := parseURI(approval.InteractingAccount.URI)
|
||||
interactingAcctURI, err := parseURI(req.InteractingAccount.URI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
interactionURI, err := parseURI(approval.InteractionURI)
|
||||
interactionURI, err := parseURI(req.InteractionURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1190,7 +1190,79 @@ func (f *federate) AcceptInteraction(
|
||||
); err != nil {
|
||||
return gtserror.Newf(
|
||||
"error sending activity %T for %v via outbox %s: %w",
|
||||
accept, approval.InteractionType, outboxIRI, err,
|
||||
accept, req.InteractionType, outboxIRI, err,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *federate) RejectInteraction(
|
||||
ctx context.Context,
|
||||
req *gtsmodel.InteractionRequest,
|
||||
) error {
|
||||
// Populate model.
|
||||
if err := f.state.DB.PopulateInteractionRequest(ctx, req); err != nil {
|
||||
return gtserror.Newf("error populating request: %w", err)
|
||||
}
|
||||
|
||||
// Bail if interacting account is ours:
|
||||
// we've already rejected internally and
|
||||
// shouldn't send an Reject to ourselves.
|
||||
if req.InteractingAccount.IsLocal() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Bail if account isn't ours:
|
||||
// we can't Reject on another
|
||||
// instance's behalf. (This
|
||||
// should never happen but...)
|
||||
if req.TargetAccount.IsRemote() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parse relevant URI(s).
|
||||
outboxIRI, err := parseURI(req.TargetAccount.OutboxURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rejectingAcctIRI, err := parseURI(req.TargetAccount.URI)
|
||||
if err != nil {
|
||||
return 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,
|
||||
); err != nil {
|
||||
return gtserror.Newf(
|
||||
"error sending activity %T for %v via outbox %s: %w",
|
||||
reject, req.InteractionType, outboxIRI, err,
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user