2017-09-11 20:45:57 +00:00
|
|
|
package activitypub
|
|
|
|
|
2018-10-11 09:26:00 +00:00
|
|
|
import (
|
2019-01-22 15:37:30 +00:00
|
|
|
as "github.com/go-ap/activitystreams"
|
2018-10-11 09:26:00 +00:00
|
|
|
)
|
2018-07-25 10:13:55 +00:00
|
|
|
|
2017-09-16 17:53:11 +00:00
|
|
|
type (
|
2018-03-27 14:16:07 +00:00
|
|
|
// InboxStream contains all activities received by the actor.
|
|
|
|
// The server SHOULD filter content according to the requester's permission.
|
|
|
|
// In general, the owner of an inbox is likely to be able to access all of their inbox contents.
|
|
|
|
// Depending on access control, some other content may be public, whereas other content may
|
|
|
|
// require authentication for non-owner users, if they can access the inbox at all.
|
2019-05-18 21:13:00 +00:00
|
|
|
InboxStream = Inbox
|
2017-09-11 20:45:57 +00:00
|
|
|
|
2018-03-27 14:16:07 +00:00
|
|
|
// Inbox is a type alias for an Ordered Collection
|
2018-10-11 09:26:00 +00:00
|
|
|
Inbox as.OrderedCollection
|
2017-09-16 17:53:11 +00:00
|
|
|
)
|
2018-04-09 11:10:27 +00:00
|
|
|
|
|
|
|
// InboxNew initializes a new Inbox
|
2018-10-11 09:26:00 +00:00
|
|
|
func InboxNew() *as.OrderedCollection {
|
|
|
|
id := as.ObjectID("inbox")
|
2018-04-09 11:10:27 +00:00
|
|
|
|
2018-11-23 14:22:56 +00:00
|
|
|
i := as.OrderedCollection{Parent: as.Parent{ID: id, Type: as.CollectionType}}
|
2019-02-21 17:00:03 +00:00
|
|
|
i.Name = as.NaturalLanguageValuesNew()
|
|
|
|
i.Content = as.NaturalLanguageValuesNew()
|
2018-06-09 12:05:46 +00:00
|
|
|
|
2018-04-09 11:10:27 +00:00
|
|
|
i.TotalItems = 0
|
|
|
|
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
|
2018-07-16 13:48:37 +00:00
|
|
|
// Append adds an element to an Inbox
|
2018-10-11 09:26:00 +00:00
|
|
|
func (i *Inbox) Append(ob as.Item) error {
|
2018-07-18 19:23:23 +00:00
|
|
|
i.OrderedItems = append(i.OrderedItems, ob)
|
|
|
|
i.TotalItems++
|
2018-07-16 13:48:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-18 19:23:23 +00:00
|
|
|
// GetID returns the ObjectID corresponding to Inbox
|
2018-10-11 09:26:00 +00:00
|
|
|
func (i Inbox) GetID() *as.ObjectID {
|
2018-09-01 09:54:52 +00:00
|
|
|
return i.Collection().GetID()
|
2018-07-18 19:23:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 18:48:38 +00:00
|
|
|
// GetLink returns the IRI corresponding to the current Inbox object
|
|
|
|
func (i Inbox) GetLink() as.IRI {
|
|
|
|
return as.IRI(i.ID)
|
|
|
|
}
|
|
|
|
|
2018-07-18 19:23:23 +00:00
|
|
|
// GetType returns the Inbox's type
|
2018-10-11 09:26:00 +00:00
|
|
|
func (i Inbox) GetType() as.ActivityVocabularyType {
|
2018-07-18 19:23:23 +00:00
|
|
|
return i.Type
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsLink returns false for an Inbox object
|
2018-10-04 19:04:31 +00:00
|
|
|
func (i Inbox) IsLink() bool {
|
2018-07-18 19:23:23 +00:00
|
|
|
return false
|
|
|
|
}
|
2018-07-18 19:34:08 +00:00
|
|
|
|
|
|
|
// IsObject returns true for a Inbox object
|
2018-10-04 19:04:31 +00:00
|
|
|
func (i Inbox) IsObject() bool {
|
2018-07-18 19:34:08 +00:00
|
|
|
return true
|
|
|
|
}
|
2018-07-24 21:11:08 +00:00
|
|
|
|
|
|
|
// UnmarshalJSON
|
|
|
|
func (i *Inbox) UnmarshalJSON(data []byte) error {
|
2019-05-18 21:13:00 +00:00
|
|
|
if as.ItemTyperFunc == nil {
|
|
|
|
as.ItemTyperFunc = JSONGetItemByType
|
|
|
|
}
|
2018-10-11 09:26:00 +00:00
|
|
|
c := as.OrderedCollection(*i)
|
2018-07-24 21:11:08 +00:00
|
|
|
err := c.UnmarshalJSON(data)
|
|
|
|
|
|
|
|
*i = Inbox(c)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
2018-09-01 09:54:52 +00:00
|
|
|
|
|
|
|
// Collection returns the underlying Collection type
|
2018-10-11 09:26:00 +00:00
|
|
|
func (i Inbox) Collection() as.CollectionInterface {
|
|
|
|
c := as.OrderedCollection(i)
|
2018-10-04 18:33:32 +00:00
|
|
|
return &c
|
2018-09-01 09:54:52 +00:00
|
|
|
}
|