mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-25 03:33:49 +00:00
This PR is part of #4767. It 1. adds the ability to follow a local person from a distant federation server (see tests/integration/api_activitypub_person_inbox_follow_test.go) 2. streamlines the router code (refactor the person conversion & handling of inbox requests in service direction, unifies service call signature & error handling) 3. introduces queues for decoupling outgoing communication (delivery retry to cope network issues or distant service downtimes) and 4. adds minor fixes to integration tests (test timeout & invalid inbox activities) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8720 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Co-committed-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package federation
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"forgejo.org/models/user"
|
|
"forgejo.org/modules/log"
|
|
|
|
ap "github.com/go-ap/activitypub"
|
|
)
|
|
|
|
func processPersonInboxUndo(ctx context.Context, ctxUser *user.User, activity *ap.Activity) (ServiceResult, error) {
|
|
if activity.Object.GetType() != ap.FollowType {
|
|
log.Error("Invalid object type for Undo activity: %v", activity.Object.GetType())
|
|
return ServiceResult{}, NewErrNotAcceptablef("Invalid object type for Undo activity: %v", activity.Object.GetType())
|
|
}
|
|
|
|
actorURI := activity.Actor.GetLink().String()
|
|
_, federatedUser, _, err := findFederatedUser(ctx, actorURI)
|
|
if err != nil {
|
|
log.Error("User not found: %v", err)
|
|
return ServiceResult{}, NewErrInternalf("User not found: %v", err)
|
|
}
|
|
|
|
if federatedUser != nil {
|
|
following, err := user.IsFollowingAp(ctx, ctxUser, federatedUser)
|
|
if err != nil {
|
|
log.Error("forgefed.IsFollowing: %v", err)
|
|
return ServiceResult{}, NewErrInternalf("forgefed.IsFollowing: %v", err)
|
|
}
|
|
if !following {
|
|
// The local user is not following the federated one, nothing to do.
|
|
log.Trace("Local user[%d] is not following federated user[%d]", ctxUser.ID, federatedUser.ID)
|
|
return NewServiceResultStatusOnly(http.StatusNoContent), nil
|
|
}
|
|
if err := user.RemoveFollower(ctx, ctxUser, federatedUser); err != nil {
|
|
log.Error("Unable to remove follower", err)
|
|
return ServiceResult{}, NewErrInternalf("Unable to remove follower: %v", err)
|
|
}
|
|
}
|
|
|
|
return NewServiceResultStatusOnly(http.StatusNoContent), nil
|
|
}
|