summaryrefslogtreecommitdiff
path: root/internal/ap/interfaces.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-04 20:21:20 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-04 20:21:20 +0000
commit41435a6c4ee0a5b52528890edf3fbf5a9dc0a6c8 (patch)
tree987b5d7787b24f6f6e340bbcf7fd1b052fe40dfc /internal/ap/interfaces.go
parent[docs/bugfix] fix link to swagger yaml (#2333) (diff)
downloadgotosocial-41435a6c4ee0a5b52528890edf3fbf5a9dc0a6c8.tar.xz
[feature] support canceling scheduled tasks, some federation API performance improvements (#2329)
Diffstat (limited to 'internal/ap/interfaces.go')
-rw-r--r--internal/ap/interfaces.go98
1 files changed, 85 insertions, 13 deletions
diff --git a/internal/ap/interfaces.go b/internal/ap/interfaces.go
index 6ba3c3735..fed69d69d 100644
--- a/internal/ap/interfaces.go
+++ b/internal/ap/interfaces.go
@@ -23,6 +23,21 @@ import (
"github.com/superseriousbusiness/activity/streams/vocab"
)
+// IsActivityable returns whether AS vocab type name is acceptable as Activityable.
+func IsActivityable(typeName string) bool {
+ return isActivity(typeName) ||
+ isIntransitiveActivity(typeName)
+}
+
+// ToActivityable safely tries to cast vocab.Type as Activityable, also checking for expected AS type names.
+func ToActivityable(t vocab.Type) (Activityable, bool) {
+ activityable, ok := t.(Activityable)
+ if !ok || !IsActivityable(t.GetTypeName()) {
+ return nil, false
+ }
+ return activityable, true
+}
+
// IsAccountable returns whether AS vocab type name is acceptable as Accountable.
func IsAccountable(typeName string) bool {
switch typeName {
@@ -88,6 +103,43 @@ func ToPollable(t vocab.Type) (Pollable, bool) {
return pollable, true
}
+// IsPollOptionable returns whether AS vocab type name is acceptable as PollOptionable.
+func IsPollOptionable(typeName string) bool {
+ return typeName == ObjectNote
+}
+
+// ToPollOptionable safely tries to cast vocab.Type as PollOptionable, also checking for expected AS type names.
+func ToPollOptionable(t vocab.Type) (PollOptionable, bool) {
+ note, ok := t.(vocab.ActivityStreamsNote)
+ if !ok || !IsPollOptionable(t.GetTypeName()) {
+ return nil, false
+ }
+ if note.GetActivityStreamsContent() != nil ||
+ note.GetActivityStreamsName() == nil {
+ // A PollOption is an ActivityStreamsNote
+ // WITHOUT a content property, instead only
+ // a name property.
+ return nil, false
+ }
+ return note, true
+}
+
+// Activityable represents the minimum activitypub interface for representing an 'activity'.
+// (see: IsActivityable() for types implementing this, though you MUST make sure to check
+// the typeName as this bare interface may be implementable by non-Activityable types).
+type Activityable interface {
+ // Activity is also a vocab.Type
+ vocab.Type
+
+ WithTo
+ WithCc
+ WithBcc
+ WithAttributedTo
+ WithActor
+ WithObject
+ WithPublished
+}
+
// Accountable represents the minimum activitypub interface for representing an 'account'.
// (see: IsAccountable() for types implementing this, though you MUST make sure to check
// the typeName as this bare interface may be implementable by non-Accountable types).
@@ -126,7 +178,7 @@ type Statusable interface {
WithURL
WithAttributedTo
WithTo
- WithCC
+ WithCc
WithSensitive
WithConversation
WithContent
@@ -145,16 +197,21 @@ type Pollable interface {
WithClosed
WithVotersCount
- // base-interface
+ // base-interfaces
Statusable
}
-// PollOptionable represents the minimum activitypub interface for representing a poll 'option'.
-// (see: IsPollOptionable() for types implementing this).
+// PollOptionable represents the minimum activitypub interface for representing a poll 'vote'.
+// (see: IsPollOptionable() for types implementing this, though you MUST make sure to check
+// the typeName as this bare interface may be implementable by non-Pollable types).
type PollOptionable interface {
- WithTypeName
+ vocab.Type
+
WithName
+ WithTo
+ WithInReplyTo
WithReplies
+ WithAttributedTo
}
// Attachmentable represents the minimum activitypub interface for representing a 'mediaAttachment'. (see: IsAttachmentable).
@@ -226,13 +283,13 @@ type Announceable interface {
WithObject
WithPublished
WithTo
- WithCC
+ WithCc
}
// Addressable represents the minimum interface for an addressed activity.
type Addressable interface {
WithTo
- WithCC
+ WithCc
}
// ReplyToable represents the minimum interface for an Activity that can be InReplyTo another activity.
@@ -268,6 +325,15 @@ type TypeOrIRI interface {
WithType
}
+// Property represents the minimum interface for an ActivityStreams property with IRIs.
+type Property[T TypeOrIRI] interface {
+ Len() int
+ At(int) T
+
+ AppendIRI(*url.URL)
+ SetIRI(int, *url.URL)
+}
+
// WithJSONLDId represents an activity with JSONLDIdProperty.
type WithJSONLDId interface {
GetJSONLDId() vocab.JSONLDIdProperty
@@ -386,18 +452,24 @@ type WithTo interface {
SetActivityStreamsTo(vocab.ActivityStreamsToProperty)
}
+// WithCC represents an activity with ActivityStreamsCcProperty
+type WithCc interface {
+ GetActivityStreamsCc() vocab.ActivityStreamsCcProperty
+ SetActivityStreamsCc(vocab.ActivityStreamsCcProperty)
+}
+
+// WithCC represents an activity with ActivityStreamsBccProperty
+type WithBcc interface {
+ GetActivityStreamsBcc() vocab.ActivityStreamsBccProperty
+ SetActivityStreamsBcc(vocab.ActivityStreamsBccProperty)
+}
+
// WithInReplyTo represents an activity with ActivityStreamsInReplyToProperty
type WithInReplyTo interface {
GetActivityStreamsInReplyTo() vocab.ActivityStreamsInReplyToProperty
SetActivityStreamsInReplyTo(vocab.ActivityStreamsInReplyToProperty)
}
-// WithCC represents an activity with ActivityStreamsCcProperty
-type WithCC interface {
- GetActivityStreamsCc() vocab.ActivityStreamsCcProperty
- SetActivityStreamsCc(vocab.ActivityStreamsCcProperty)
-}
-
// WithSensitive represents an activity with ActivityStreamsSensitiveProperty
type WithSensitive interface {
GetActivityStreamsSensitive() vocab.ActivityStreamsSensitiveProperty