2024-01-03 12:29:12 -05:00
|
|
|
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package forgefed
|
|
|
|
|
|
|
|
import (
|
2024-01-13 08:17:11 -05:00
|
|
|
"time"
|
|
|
|
|
2024-01-03 12:29:12 -05:00
|
|
|
"code.gitea.io/gitea/modules/validation"
|
2024-02-09 11:46:27 -05:00
|
|
|
|
2024-01-03 12:29:12 -05:00
|
|
|
ap "github.com/go-ap/activitypub"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ForgeLike activity data type
|
|
|
|
// swagger:model
|
|
|
|
type ForgeLike struct {
|
|
|
|
// swagger:ignore
|
|
|
|
ap.Activity
|
|
|
|
}
|
|
|
|
|
2024-01-13 08:17:11 -05:00
|
|
|
func (like ForgeLike) MarshalJSON() ([]byte, error) {
|
|
|
|
return like.Activity.MarshalJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (like *ForgeLike) UnmarshalJSON(data []byte) error {
|
|
|
|
return like.Activity.UnmarshalJSON(data)
|
2024-01-03 12:29:12 -05:00
|
|
|
}
|
|
|
|
|
2024-01-13 08:17:11 -05:00
|
|
|
func (like ForgeLike) IsNewer(compareTo time.Time) bool {
|
|
|
|
return like.StartTime.After(compareTo)
|
2024-01-03 12:29:12 -05:00
|
|
|
}
|
|
|
|
|
2024-01-13 08:17:11 -05:00
|
|
|
func (like ForgeLike) Validate() []string {
|
2024-01-03 12:29:12 -05:00
|
|
|
var result []string
|
2024-01-13 08:17:11 -05:00
|
|
|
result = append(result, validation.ValidateNotEmpty(string(like.Type), "type")...)
|
|
|
|
result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"})...)
|
|
|
|
result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
|
|
|
|
result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
|
|
|
|
result = append(result, validation.ValidateNotEmpty(like.StartTime.String(), "startTime")...)
|
|
|
|
if like.StartTime.IsZero() {
|
2024-01-03 12:52:41 -05:00
|
|
|
result = append(result, "StartTime was invalid.")
|
|
|
|
}
|
2024-01-03 12:29:12 -05:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|