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>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
// Copyright 2023, 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package forgefed
|
|
|
|
import (
|
|
"time"
|
|
|
|
"forgejo.org/modules/validation"
|
|
|
|
ap "github.com/go-ap/activitypub"
|
|
)
|
|
|
|
// ForgeLike activity data type
|
|
// swagger:model
|
|
type ForgeLike struct {
|
|
// swagger:ignore
|
|
ap.Activity
|
|
}
|
|
|
|
func NewForgeLike(actorIRI, objectIRI string, startTime time.Time) (ForgeLike, error) {
|
|
result := ForgeLike{}
|
|
result.Type = ap.LikeType
|
|
result.Actor = ap.IRI(actorIRI)
|
|
result.Object = ap.IRI(objectIRI)
|
|
result.StartTime = startTime
|
|
if valid, err := validation.IsValid(result); !valid {
|
|
return ForgeLike{}, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (like ForgeLike) MarshalJSON() ([]byte, error) {
|
|
return like.Activity.MarshalJSON()
|
|
}
|
|
|
|
func (like *ForgeLike) UnmarshalJSON(data []byte) error {
|
|
return like.Activity.UnmarshalJSON(data)
|
|
}
|
|
|
|
func (like ForgeLike) IsNewer(compareTo time.Time) bool {
|
|
return like.StartTime.After(compareTo)
|
|
}
|
|
|
|
func (like ForgeLike) Validate() []string {
|
|
var result []string
|
|
result = append(result, validation.ValidateNotEmpty(like.Type, "type")...)
|
|
result = append(result, validation.ValidateOneOf(like.Type, []any{ap.LikeType}, "type")...)
|
|
|
|
if like.Actor == nil {
|
|
result = append(result, "Actor should not be nil.")
|
|
} else {
|
|
result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
|
|
}
|
|
|
|
result = append(result, validation.ValidateNotEmpty(like.StartTime.String(), "startTime")...)
|
|
if like.StartTime.IsZero() {
|
|
result = append(result, "StartTime was invalid.")
|
|
}
|
|
|
|
if like.Object == nil {
|
|
result = append(result, "Object should not be nil.")
|
|
} else {
|
|
result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
|
|
}
|
|
|
|
return result
|
|
}
|