summaryrefslogtreecommitdiffstats
path: root/modules/forgefed/activity.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /modules/forgefed/activity.go
parentInitial commit. (diff)
downloadforgejo-upstream.tar.xz
forgejo-upstream.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'modules/forgefed/activity.go')
-rw-r--r--modules/forgefed/activity.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/modules/forgefed/activity.go b/modules/forgefed/activity.go
new file mode 100644
index 0000000..247abd2
--- /dev/null
+++ b/modules/forgefed/activity.go
@@ -0,0 +1,65 @@
+// Copyright 2023, 2024 The Forgejo Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package forgefed
+
+import (
+ "time"
+
+ "code.gitea.io/gitea/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) // That's us, a User
+ result.Object = ap.IRI(objectIRI) // That's them, a Repository
+ 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(string(like.Type), "type")...)
+ result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"}, "type")...)
+ if like.Actor == nil {
+ result = append(result, "Actor should not be nil.")
+ } else {
+ result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
+ }
+ if like.Object == nil {
+ result = append(result, "Object should not be nil.")
+ } else {
+ result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
+ }
+ result = append(result, validation.ValidateNotEmpty(like.StartTime.String(), "startTime")...)
+ if like.StartTime.IsZero() {
+ result = append(result, "StartTime was invalid.")
+ }
+
+ return result
+}