2017-09-11 20:45:57 +00:00
|
|
|
package activitypub
|
|
|
|
|
2018-10-11 09:26:00 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2019-01-22 15:37:30 +00:00
|
|
|
as "github.com/go-ap/activitystreams"
|
2018-10-11 09:26:00 +00:00
|
|
|
)
|
2018-10-04 19:05:01 +00:00
|
|
|
|
2017-09-16 17:53:11 +00:00
|
|
|
type (
|
2018-03-27 14:16:07 +00:00
|
|
|
// FollowingCollection is a list of everybody that the actor has followed, added as a side effect.
|
|
|
|
// The following collection MUST be either an OrderedCollection or a Collection and MAY
|
|
|
|
// be filtered on privileges of an authenticated user or as appropriate when no authentication is given.
|
2017-09-16 17:53:11 +00:00
|
|
|
FollowingCollection Following
|
2017-09-11 20:45:57 +00:00
|
|
|
|
2018-03-27 14:16:07 +00:00
|
|
|
// Following is a type alias for a simple Collection
|
2018-10-11 09:26:00 +00:00
|
|
|
Following as.Collection
|
2017-09-16 17:53:11 +00:00
|
|
|
)
|
2018-10-04 19:05:01 +00:00
|
|
|
|
|
|
|
// FollowingNew initializes a new Following
|
|
|
|
func FollowingNew() *Following {
|
2018-10-11 09:26:00 +00:00
|
|
|
id := as.ObjectID("following")
|
2018-10-04 19:05:01 +00:00
|
|
|
|
2018-11-23 14:22:56 +00:00
|
|
|
i := Following{Parent: as.Parent{ID: id, Type: as.CollectionType}}
|
2018-10-11 09:26:00 +00:00
|
|
|
i.Name = as.NaturalLanguageValueNew()
|
|
|
|
i.Content = as.NaturalLanguageValueNew()
|
|
|
|
i.Summary = as.NaturalLanguageValueNew()
|
2018-10-04 19:05:01 +00:00
|
|
|
|
|
|
|
i.TotalItems = 0
|
|
|
|
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append adds an element to an FollowingCollection
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f *FollowingCollection) Append(o as.Item) error {
|
|
|
|
if f == nil {
|
2018-10-04 19:05:01 +00:00
|
|
|
return fmt.Errorf("nil ")
|
|
|
|
}
|
2018-10-11 18:48:38 +00:00
|
|
|
f.Items = append(f.Items, o)
|
|
|
|
f.TotalItems++
|
2018-10-04 19:05:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append adds an element to an Following
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f *Following) Append(ob as.Item) error {
|
|
|
|
f.Items = append(f.Items, ob)
|
|
|
|
f.TotalItems++
|
2018-10-04 19:05:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetID returns the ObjectID corresponding to FollowingCollection
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f FollowingCollection) GetID() *as.ObjectID {
|
|
|
|
return f.Collection().GetID()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLink returns the IRI corresponding to the current FollowingCollection object
|
|
|
|
func (f FollowingCollection) GetLink() as.IRI {
|
|
|
|
return as.IRI(f.ID)
|
2018-10-04 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetType returns the FollowingCollection's type
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f FollowingCollection) GetType() as.ActivityVocabularyType {
|
|
|
|
return f.Type
|
2018-10-04 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsLink returns false for an FollowingCollection object
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f FollowingCollection) IsLink() bool {
|
2018-10-04 19:05:01 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsObject returns true for a FollowingCollection object
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f FollowingCollection) IsObject() bool {
|
2018-10-04 19:05:01 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetID returns the ObjectID corresponding to Following
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f Following) GetID() *as.ObjectID {
|
|
|
|
return f.Collection().GetID()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLink returns the IRI corresponding to the current Following object
|
|
|
|
func (f Following) GetLink() as.IRI {
|
|
|
|
return as.IRI(f.ID)
|
2018-10-04 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetType returns the Following's type
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f Following) GetType() as.ActivityVocabularyType {
|
|
|
|
return f.Type
|
2018-10-04 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsLink returns false for an Following object
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f Following) IsLink() bool {
|
2018-10-04 19:05:01 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsObject returns true for a Following object
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f Following) IsObject() bool {
|
2018-10-04 19:05:01 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f *FollowingCollection) UnmarshalJSON(data []byte) error {
|
|
|
|
c := as.Collection(*f)
|
2018-10-04 19:05:01 +00:00
|
|
|
err := c.UnmarshalJSON(data)
|
|
|
|
|
2018-10-11 18:48:38 +00:00
|
|
|
*f = FollowingCollection(c)
|
2018-10-04 19:05:01 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f *Following) UnmarshalJSON(data []byte) error {
|
|
|
|
c := as.Collection(*f)
|
2018-10-04 19:05:01 +00:00
|
|
|
err := c.UnmarshalJSON(data)
|
|
|
|
|
2018-10-11 18:48:38 +00:00
|
|
|
*f = Following(c)
|
2018-10-04 19:05:01 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collection returns the underlying Collection type
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f Following) Collection() as.CollectionInterface {
|
|
|
|
c := as.Collection(f)
|
2018-10-04 19:05:01 +00:00
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collection returns the underlying Collection type
|
2018-10-11 18:48:38 +00:00
|
|
|
func (f FollowingCollection) Collection() as.CollectionInterface {
|
|
|
|
c := as.Collection(f)
|
2018-10-04 19:05:01 +00:00
|
|
|
return &c
|
|
|
|
}
|