mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-15 07:20:26 +00:00
Picks the update commit from https://codeberg.org/forgejo/forgejo/pulls/11200 and fixes the new incompatibilities. I ran full end-to-end tests against Forgejo and basic end-to-end tests against GoToSocial which appear to be working. Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11301 Reviewed-by: elle <0xllx0@noreply.codeberg.org> Co-authored-by: famfo <famfo@famfo.xyz> Co-committed-by: famfo <famfo@famfo.xyz>
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{ap.NilLangRef: ap.Content(item.NoteContent)},
|
|
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(ap.NilLangRef, ap.Content(user.FullName))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
person.PreferredUsername = ap.NaturalLanguageValuesNew()
|
|
err = person.PreferredUsername.Set(ap.NilLangRef, 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
|
|
}
|