mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +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>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// Copyright 2024, 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package forgefed
|
|
|
|
import (
|
|
"forgejo.org/modules/validation"
|
|
|
|
ap "github.com/go-ap/activitypub"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ForgeFollow activity data type
|
|
// swagger:model
|
|
type ForgeFollow struct {
|
|
// swagger:ignore
|
|
ap.Activity
|
|
}
|
|
|
|
func NewForgeFollowFromAp(activity ap.Activity) (ForgeFollow, error) {
|
|
result := ForgeFollow{}
|
|
result.Activity = activity
|
|
if valid, err := validation.IsValid(result); !valid {
|
|
return ForgeFollow{}, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func NewForgeFollow(actor, object string) (ForgeFollow, error) {
|
|
result := ForgeFollow{}
|
|
result.Type = ap.FollowType
|
|
result.ID = ap.IRI(actor + "/follows/" + uuid.New().String())
|
|
result.Actor = ap.IRI(actor)
|
|
result.Object = ap.IRI(object)
|
|
if valid, err := validation.IsValid(result); !valid {
|
|
return ForgeFollow{}, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (follow ForgeFollow) MarshalJSON() ([]byte, error) {
|
|
return follow.Activity.MarshalJSON()
|
|
}
|
|
|
|
func (follow *ForgeFollow) UnmarshalJSON(data []byte) error {
|
|
return follow.Activity.UnmarshalJSON(data)
|
|
}
|
|
|
|
func (follow ForgeFollow) Validate() []string {
|
|
var result []string
|
|
result = append(result, validation.ValidateNotEmpty(follow.Type, "type")...)
|
|
result = append(result, validation.ValidateOneOf(follow.Type, []any{ap.FollowType}, "type")...)
|
|
result = append(result, validation.ValidateIDExists(follow.Actor, "actor")...)
|
|
result = append(result, validation.ValidateIDExists(follow.Object, "object")...)
|
|
|
|
return result
|
|
}
|