mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-20 09:45:55 +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>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package convert
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forgejo.org/models/activities"
|
|
user_model "forgejo.org/models/user"
|
|
"forgejo.org/modules/activitypub"
|
|
|
|
ap "github.com/go-ap/activitypub"
|
|
)
|
|
|
|
func ToActivityPubPersonFeedItem(item *activities.FederatedUserActivity) ap.Note {
|
|
return ap.Note{
|
|
AttributedTo: ap.IRI(item.ActorURI),
|
|
Content: ap.NaturalLanguageValues{{Value: ap.Content(item.NoteContent), Ref: ap.NilLangRef}},
|
|
ID: ap.IRI(item.NoteURL),
|
|
URL: ap.IRI(item.OriginalNote),
|
|
}
|
|
}
|
|
|
|
func ToActivityPubPerson(ctx context.Context, user *user_model.User) (*ap.Person, error) {
|
|
link := user.APActorID()
|
|
person := ap.PersonNew(ap.IRI(link))
|
|
|
|
person.Name = ap.NaturalLanguageValuesNew()
|
|
err := person.Name.Set("en", ap.Content(user.FullName))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
person.PreferredUsername = ap.NaturalLanguageValuesNew()
|
|
err = person.PreferredUsername.Set("en", ap.Content(user.Name))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
person.URL = ap.IRI(user.HTMLURL())
|
|
|
|
person.Icon = ap.Image{
|
|
Type: ap.ImageType,
|
|
MediaType: "image/png",
|
|
URL: ap.IRI(user.AvatarLink(ctx)),
|
|
}
|
|
|
|
person.Inbox = ap.IRI(link + "/inbox")
|
|
person.Outbox = ap.IRI(link + "/outbox")
|
|
|
|
person.PublicKey.ID = ap.IRI(link + "#main-key")
|
|
person.PublicKey.Owner = ap.IRI(link)
|
|
|
|
publicKeyPem, err := activitypub.GetPublicKey(ctx, user)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
person.PublicKey.PublicKeyPem = publicKeyPem
|
|
|
|
return person, nil
|
|
}
|