summaryrefslogtreecommitdiff
path: root/internal/ap/interfaces.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/ap/interfaces.go')
-rw-r--r--internal/ap/interfaces.go183
1 files changed, 157 insertions, 26 deletions
diff --git a/internal/ap/interfaces.go b/internal/ap/interfaces.go
index 5372eb01e..4538c476f 100644
--- a/internal/ap/interfaces.go
+++ b/internal/ap/interfaces.go
@@ -23,11 +23,76 @@ import (
"github.com/superseriousbusiness/activity/streams/vocab"
)
+// IsAccountable returns whether AS vocab type name is acceptable as Accountable.
+func IsAccountable(typeName string) bool {
+ switch typeName {
+ case ActorPerson,
+ ActorApplication,
+ ActorOrganization,
+ ActorService,
+ ActorGroup:
+ return true
+ default:
+ return false
+ }
+}
+
+// ToAccountable safely tries to cast vocab.Type as Accountable, also checking for expected AS type names.
+func ToAccountable(t vocab.Type) (Accountable, bool) {
+ accountable, ok := t.(Accountable)
+ if !ok || !IsAccountable(t.GetTypeName()) {
+ return nil, false
+ }
+ return accountable, true
+}
+
+// IsStatusable returns whether AS vocab type name is acceptable as Statusable.
+func IsStatusable(typeName string) bool {
+ switch typeName {
+ case ObjectArticle,
+ ObjectDocument,
+ ObjectImage,
+ ObjectVideo,
+ ObjectNote,
+ ObjectPage,
+ ObjectEvent,
+ ObjectPlace,
+ ObjectProfile,
+ ActivityQuestion:
+ return true
+ default:
+ return false
+ }
+}
+
+// ToStatusable safely tries to cast vocab.Type as Statusable, also checking for expected AS type names.
+func ToStatusable(t vocab.Type) (Statusable, bool) {
+ statusable, ok := t.(Statusable)
+ if !ok || !IsStatusable(t.GetTypeName()) {
+ return nil, false
+ }
+ return statusable, true
+}
+
+// IsPollable returns whether AS vocab type name is acceptable as Pollable.
+func IsPollable(typeName string) bool {
+ return typeName == ActivityQuestion
+}
+
+// ToPollable safely tries to cast vocab.Type as Pollable, also checking for expected AS type names.
+func ToPollable(t vocab.Type) (Pollable, bool) {
+ pollable, ok := t.(Pollable)
+ if !ok || !IsPollable(t.GetTypeName()) {
+ return nil, false
+ }
+ return pollable, true
+}
+
// Accountable represents the minimum activitypub interface for representing an 'account'.
-// This interface is fulfilled by: Person, Application, Organization, Service, and Group
+// (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).
type Accountable interface {
- WithJSONLDId
- WithTypeName
+ vocab.Type
WithPreferredUsername
WithIcon
@@ -35,7 +100,6 @@ type Accountable interface {
WithImage
WithSummary
WithAttachment
- WithSetSummary
WithDiscoverable
WithURL
WithPublicKey
@@ -50,15 +114,13 @@ type Accountable interface {
}
// Statusable represents the minimum activitypub interface for representing a 'status'.
-// This interface is fulfilled by: Article, Document, Image, Video, Note, Page, Event, Place, Mention, Profile
+// (see: IsStatusable() for types implementing this, though you MUST make sure to check
+// the typeName as this bare interface may be implementable by non-Statusable types).
type Statusable interface {
- WithJSONLDId
- WithTypeName
+ vocab.Type
WithSummary
- WithSetSummary
WithName
- WithSetName
WithInReplyTo
WithPublished
WithURL
@@ -68,20 +130,40 @@ type Statusable interface {
WithSensitive
WithConversation
WithContent
- WithSetContent
WithAttachment
WithTag
WithReplies
}
-// Attachmentable represents the minimum activitypub interface for representing a 'mediaAttachment'.
+// Pollable represents the minimum activitypub interface for representing a 'poll' (it's a subset of a status).
+// (see: IsPollable() 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 Pollable interface {
+ WithOneOf
+ WithAnyOf
+ WithEndTime
+ WithClosed
+ WithVotersCount
+
+ // base-interface
+ Statusable
+}
+
+// PollOptionable represents the minimum activitypub interface for representing a poll 'option'.
+// (see: IsPollOptionable() for types implementing this).
+type PollOptionable interface {
+ WithTypeName
+ WithName
+ WithReplies
+}
+
+// Attachmentable represents the minimum activitypub interface for representing a 'mediaAttachment'. (see: IsAttachmentable).
// This interface is fulfilled by: Audio, Document, Image, Video
type Attachmentable interface {
WithTypeName
WithMediaType
WithURL
WithName
- WithSetName
WithBlurhash
}
@@ -160,8 +242,7 @@ type ReplyToable interface {
// CollectionPageIterator represents the minimum interface for interacting with a wrapped
// CollectionPage or OrderedCollectionPage in order to access both next / prev pages and items.
type CollectionPageIterator interface {
- WithJSONLDId
- WithTypeName
+ vocab.Type
NextPage() WithIRI
PrevPage() WithIRI
@@ -189,12 +270,14 @@ type Flaggable interface {
// WithJSONLDId represents an activity with JSONLDIdProperty.
type WithJSONLDId interface {
GetJSONLDId() vocab.JSONLDIdProperty
+ SetJSONLDId(vocab.JSONLDIdProperty)
}
// WithIRI represents an object (possibly) representable as an IRI.
type WithIRI interface {
GetIRI() *url.URL
IsIRI() bool
+ SetIRI(*url.URL)
}
// WithType ...
@@ -210,20 +293,18 @@ type WithTypeName interface {
// WithPreferredUsername represents an activity with ActivityStreamsPreferredUsernameProperty
type WithPreferredUsername interface {
GetActivityStreamsPreferredUsername() vocab.ActivityStreamsPreferredUsernameProperty
+ SetActivityStreamsPreferredUsername(vocab.ActivityStreamsPreferredUsernameProperty)
}
// WithIcon represents an activity with ActivityStreamsIconProperty
type WithIcon interface {
GetActivityStreamsIcon() vocab.ActivityStreamsIconProperty
+ SetActivityStreamsIcon(vocab.ActivityStreamsIconProperty)
}
// WithName represents an activity with ActivityStreamsNameProperty
type WithName interface {
GetActivityStreamsName() vocab.ActivityStreamsNameProperty
-}
-
-// WithSetName represents an activity with a settable ActivityStreamsNameProperty
-type WithSetName interface {
SetActivityStreamsName(vocab.ActivityStreamsNameProperty)
}
@@ -235,81 +316,91 @@ type WithImage interface {
// WithSummary represents an activity with ActivityStreamsSummaryProperty
type WithSummary interface {
GetActivityStreamsSummary() vocab.ActivityStreamsSummaryProperty
-}
-
-// WithSetSummary represents an activity that can have summary set on it.
-type WithSetSummary interface {
SetActivityStreamsSummary(vocab.ActivityStreamsSummaryProperty)
}
// WithDiscoverable represents an activity with TootDiscoverableProperty
type WithDiscoverable interface {
GetTootDiscoverable() vocab.TootDiscoverableProperty
+ SetTootDiscoverable(vocab.TootDiscoverableProperty)
}
// WithURL represents an activity with ActivityStreamsUrlProperty
type WithURL interface {
GetActivityStreamsUrl() vocab.ActivityStreamsUrlProperty
+ SetActivityStreamsUrl(vocab.ActivityStreamsUrlProperty)
}
// WithPublicKey represents an activity with W3IDSecurityV1PublicKeyProperty
type WithPublicKey interface {
GetW3IDSecurityV1PublicKey() vocab.W3IDSecurityV1PublicKeyProperty
+ SetW3IDSecurityV1PublicKey(vocab.W3IDSecurityV1PublicKeyProperty)
}
// WithInbox represents an activity with ActivityStreamsInboxProperty
type WithInbox interface {
GetActivityStreamsInbox() vocab.ActivityStreamsInboxProperty
+ SetActivityStreamsInbox(vocab.ActivityStreamsInboxProperty)
}
// WithOutbox represents an activity with ActivityStreamsOutboxProperty
type WithOutbox interface {
GetActivityStreamsOutbox() vocab.ActivityStreamsOutboxProperty
+ SetActivityStreamsOutbox(vocab.ActivityStreamsOutboxProperty)
}
// WithFollowing represents an activity with ActivityStreamsFollowingProperty
type WithFollowing interface {
GetActivityStreamsFollowing() vocab.ActivityStreamsFollowingProperty
+ SetActivityStreamsFollowing(vocab.ActivityStreamsFollowingProperty)
}
// WithFollowers represents an activity with ActivityStreamsFollowersProperty
type WithFollowers interface {
GetActivityStreamsFollowers() vocab.ActivityStreamsFollowersProperty
+ SetActivityStreamsFollowers(vocab.ActivityStreamsFollowersProperty)
}
// WithFeatured represents an activity with TootFeaturedProperty
type WithFeatured interface {
GetTootFeatured() vocab.TootFeaturedProperty
+ SetTootFeatured(vocab.TootFeaturedProperty)
}
// WithAttributedTo represents an activity with ActivityStreamsAttributedToProperty
type WithAttributedTo interface {
GetActivityStreamsAttributedTo() vocab.ActivityStreamsAttributedToProperty
+ SetActivityStreamsAttributedTo(vocab.ActivityStreamsAttributedToProperty)
}
// WithAttachment represents an activity with ActivityStreamsAttachmentProperty
type WithAttachment interface {
GetActivityStreamsAttachment() vocab.ActivityStreamsAttachmentProperty
+ SetActivityStreamsAttachment(vocab.ActivityStreamsAttachmentProperty)
}
// WithTo represents an activity with ActivityStreamsToProperty
type WithTo interface {
GetActivityStreamsTo() vocab.ActivityStreamsToProperty
+ SetActivityStreamsTo(vocab.ActivityStreamsToProperty)
}
// 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
+ SetActivityStreamsSensitive(vocab.ActivityStreamsSensitiveProperty)
}
// WithConversation ...
@@ -319,36 +410,37 @@ type WithConversation interface { // TODO
// WithContent represents an activity with ActivityStreamsContentProperty
type WithContent interface {
GetActivityStreamsContent() vocab.ActivityStreamsContentProperty
-}
-
-// WithSetContent represents an activity that can have content set on it.
-type WithSetContent interface {
SetActivityStreamsContent(vocab.ActivityStreamsContentProperty)
}
// WithPublished represents an activity with ActivityStreamsPublishedProperty
type WithPublished interface {
GetActivityStreamsPublished() vocab.ActivityStreamsPublishedProperty
+ SetActivityStreamsPublished(vocab.ActivityStreamsPublishedProperty)
}
// WithTag represents an activity with ActivityStreamsTagProperty
type WithTag interface {
GetActivityStreamsTag() vocab.ActivityStreamsTagProperty
+ SetActivityStreamsTag(vocab.ActivityStreamsTagProperty)
}
// WithReplies represents an activity with ActivityStreamsRepliesProperty
type WithReplies interface {
GetActivityStreamsReplies() vocab.ActivityStreamsRepliesProperty
+ SetActivityStreamsReplies(vocab.ActivityStreamsRepliesProperty)
}
// WithMediaType represents an activity with ActivityStreamsMediaTypeProperty
type WithMediaType interface {
GetActivityStreamsMediaType() vocab.ActivityStreamsMediaTypeProperty
+ SetActivityStreamsMediaType(vocab.ActivityStreamsMediaTypeProperty)
}
// WithBlurhash represents an activity with TootBlurhashProperty
type WithBlurhash interface {
GetTootBlurhash() vocab.TootBlurhashProperty
+ SetTootBlurhash(vocab.TootBlurhashProperty)
}
// type withFocalPoint interface {
@@ -358,44 +450,83 @@ type WithBlurhash interface {
// WithHref represents an activity with ActivityStreamsHrefProperty
type WithHref interface {
GetActivityStreamsHref() vocab.ActivityStreamsHrefProperty
+ SetActivityStreamsHref(vocab.ActivityStreamsHrefProperty)
}
// WithUpdated represents an activity with ActivityStreamsUpdatedProperty
type WithUpdated interface {
GetActivityStreamsUpdated() vocab.ActivityStreamsUpdatedProperty
+ SetActivityStreamsUpdated(vocab.ActivityStreamsUpdatedProperty)
}
// WithActor represents an activity with ActivityStreamsActorProperty
type WithActor interface {
GetActivityStreamsActor() vocab.ActivityStreamsActorProperty
+ SetActivityStreamsActor(vocab.ActivityStreamsActorProperty)
}
// WithObject represents an activity with ActivityStreamsObjectProperty
type WithObject interface {
GetActivityStreamsObject() vocab.ActivityStreamsObjectProperty
+ SetActivityStreamsObject(vocab.ActivityStreamsObjectProperty)
}
// WithNext represents an activity with ActivityStreamsNextProperty
type WithNext interface {
GetActivityStreamsNext() vocab.ActivityStreamsNextProperty
+ SetActivityStreamsNext(vocab.ActivityStreamsNextProperty)
}
// WithPartOf represents an activity with ActivityStreamsPartOfProperty
type WithPartOf interface {
GetActivityStreamsPartOf() vocab.ActivityStreamsPartOfProperty
+ SetActivityStreamsPartOf(vocab.ActivityStreamsPartOfProperty)
}
// WithItems represents an activity with ActivityStreamsItemsProperty
type WithItems interface {
GetActivityStreamsItems() vocab.ActivityStreamsItemsProperty
+ SetActivityStreamsItems(vocab.ActivityStreamsItemsProperty)
}
// WithManuallyApprovesFollowers represents a Person or profile with the ManuallyApprovesFollowers property.
type WithManuallyApprovesFollowers interface {
GetActivityStreamsManuallyApprovesFollowers() vocab.ActivityStreamsManuallyApprovesFollowersProperty
+ SetActivityStreamsManuallyApprovesFollowers(vocab.ActivityStreamsManuallyApprovesFollowersProperty)
}
// WithEndpoints represents a Person or profile with the endpoints property
type WithEndpoints interface {
GetActivityStreamsEndpoints() vocab.ActivityStreamsEndpointsProperty
+ SetActivityStreamsEndpoints(vocab.ActivityStreamsEndpointsProperty)
+}
+
+// WithOneOf represents an activity with the oneOf property.
+type WithOneOf interface {
+ GetActivityStreamsOneOf() vocab.ActivityStreamsOneOfProperty
+ SetActivityStreamsOneOf(vocab.ActivityStreamsOneOfProperty)
+}
+
+// WithOneOf represents an activity with the oneOf property.
+type WithAnyOf interface {
+ GetActivityStreamsAnyOf() vocab.ActivityStreamsAnyOfProperty
+ SetActivityStreamsAnyOf(vocab.ActivityStreamsAnyOfProperty)
+}
+
+// WithEndTime represents an activity with the endTime property.
+type WithEndTime interface {
+ GetActivityStreamsEndTime() vocab.ActivityStreamsEndTimeProperty
+ SetActivityStreamsEndTime(vocab.ActivityStreamsEndTimeProperty)
+}
+
+// WithClosed represents an activity with the closed property.
+type WithClosed interface {
+ GetActivityStreamsClosed() vocab.ActivityStreamsClosedProperty
+ SetActivityStreamsClosed(vocab.ActivityStreamsClosedProperty)
+}
+
+// WithVotersCount represents an activity with the votersCount property.
+type WithVotersCount interface {
+ GetTootVotersCount() vocab.TootVotersCountProperty
+ SetTootVotersCount(vocab.TootVotersCountProperty)
}