mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	This PR is part of #4767. It contains * a refactoring of validation error messages * adds the ability to send user-activities to distant federated servers Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8792 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>
		
			
				
	
	
		
			60 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
	
		
			1.7 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/forgefed"
 | |
| 	"forgejo.org/modules/log"
 | |
| 	context_service "forgejo.org/services/context"
 | |
| 
 | |
| 	ap "github.com/go-ap/activitypub"
 | |
| 	"github.com/go-ap/jsonld"
 | |
| )
 | |
| 
 | |
| func ProcessPersonInbox(ctx context.Context, user *user.User, activity *ap.Activity) (ServiceResult, error) {
 | |
| 	switch activity.Type {
 | |
| 	case ap.CreateType:
 | |
| 		return processPersonInboxCreate(ctx, user, activity)
 | |
| 	case ap.FollowType:
 | |
| 		return processPersonFollow(ctx, user, activity)
 | |
| 	case ap.UndoType:
 | |
| 		return processPersonInboxUndo(ctx, user, activity)
 | |
| 	case ap.AcceptType:
 | |
| 		return processPersonInboxAccept(activity)
 | |
| 	}
 | |
| 
 | |
| 	log.Error("Unsupported PersonInbox activity: %v", activity.Type)
 | |
| 	return ServiceResult{}, NewErrNotAcceptablef("unsupported activity: %v", activity.Type)
 | |
| }
 | |
| 
 | |
| func FollowRemoteActor(ctx *context_service.APIContext, localUser *user.User, actorURI string) error {
 | |
| 	_, federatedUser, federationHost, err := FindOrCreateFederatedUser(ctx.Base, actorURI)
 | |
| 	if err != nil {
 | |
| 		log.Error("Federated user not found (%s): %v", actorURI, err)
 | |
| 		ctx.Error(http.StatusNotAcceptable, "Federated user not found", err)
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	followReq, err := forgefed.NewForgeFollow(localUser.APActorID(), actorURI)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	payload, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI)).
 | |
| 		Marshal(followReq)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	hostURL := federationHost.AsURL()
 | |
| 	return deliveryQueue.Push(deliveryQueueItem{
 | |
| 		InboxURL: hostURL.JoinPath(federatedUser.InboxPath).String(),
 | |
| 		Doer:     localUser,
 | |
| 		Payload:  payload,
 | |
| 	})
 | |
| }
 |