Complete basic recipient list inbox algorithm.

このコミットが含まれているのは:
Cory Slep 2018-01-28 20:51:12 +01:00
コミット cd8ee5fb47
2個のファイルの変更103行の追加17行の削除

ファイルの表示

@ -8,7 +8,22 @@ import (
// ActorObject is an object that has "actor" or "attributedTo" properties, // ActorObject is an object that has "actor" or "attributedTo" properties,
// representing the author or originator of the object. // representing the author or originator of the object.
type ActorObject interface { type ActorObject interface {
// TODO: Populate HasInbox() (ok bool)
GetInbox() (v url.URL)
AttributedToLen() (l int)
IsAttributedToObject(index int) (ok bool)
GetAttributedToObject(index int) (v vocab.ObjectType)
IsAttributedToLink(index int) (ok bool)
GetAttributedToLink(index int) (v vocab.LinkType)
IsAttributedToIRI(index int) (ok bool)
GetAttributedToIRI(index int) (v url.URL)
ActorLen() (l int)
IsActorObject(index int) (ok bool)
GetActorObject(index int) (v vocab.ObjectType)
IsActorLink(index int) (ok bool)
GetActorLink(index int) (v vocab.LinkType)
IsActorIRI(index int) (ok bool)
GetActorIRI(index int) (v url.URL)
} }
// DeliverableObject is an object that is able to be sent to recipients via the // DeliverableObject is an object that is able to be sent to recipients via the

ファイルの表示

@ -87,18 +87,26 @@ func dereference(c *http.Client, u url.URL, agent string) ([]byte, error) {
// target URIs. Additionally, the DeliverableObject will have any hidden // target URIs. Additionally, the DeliverableObject will have any hidden
// hidden recipients ("bto" and "bcc") stripped from it. // hidden recipients ("bto" and "bcc") stripped from it.
func (c *Client) prepare(o DeliverableObject) ([]url.URL, error) { func (c *Client) prepare(o DeliverableObject) ([]url.URL, error) {
// Get inboxes of recipients
var r []url.URL var r []url.URL
r = append(r, getToIRIs(o)...) r = append(r, getToIRIs(o)...)
r = append(r, getBToIRIs(o)...) r = append(r, getBToIRIs(o)...)
r = append(r, getCcIRIs(o)...) r = append(r, getCcIRIs(o)...)
r = append(r, getBccIRIs(o)...) r = append(r, getBccIRIs(o)...)
r = append(r, getAudienceIRIs(o)...) r = append(r, getAudienceIRIs(o)...)
i, err := c.resolveInboxes(r, 0, c.MaxDepth) // TODO: Handle public collection
receiverActors, err := c.resolveInboxes(r, 0, c.MaxDepth)
if err != nil { if err != nil {
return nil, err return nil, err
} }
targets := getInboxes(i) targets := getInboxes(receiverActors)
ignore := getActorsInboxes(o) // Get inboxes of sender(s)
senderActors, err := c.resolveInboxes(getActorsAttributedToURI(o), 0, c.MaxDepth)
if err != nil {
return nil, err
}
ignore := getInboxes(senderActors)
// Post-processing
r = dedupeIRIs(targets, ignore) r = dedupeIRIs(targets, ignore)
stripHiddenRecipients(o) stripHiddenRecipients(o)
return r, nil return r, nil
@ -188,17 +196,50 @@ func (c *Client) resolveInboxes(r []url.URL, depth int, max int) ([]ActorObject,
// getInboxes extracts the 'inbox' IRIs from actors. // getInboxes extracts the 'inbox' IRIs from actors.
func getInboxes(a []ActorObject) []url.URL { func getInboxes(a []ActorObject) []url.URL {
// TODO: implement var u []url.URL
return nil for _, actor := range a {
if actor.HasInbox() {
u = append(u, actor.GetInbox())
}
}
return u
} }
// getActorsInboxes attempts to find the inbox URIs for the "actor" and // getActorAttributedToURI attempts to find the URIs for the "actor" and
// "attributedTo" originators on the object. If the inbox URIs are not found, // "attributedTo" originators on the object.
// then the one or more actors are resolved as usual, which may result in this func getActorsAttributedToURI(a ActorObject) []url.URL {
// server pinging itself. var u []url.URL
func getActorsInboxes(a ActorObject) []url.URL { for i := 0; i < a.AttributedToLen(); i++ {
// TODO: implement if a.IsAttributedToObject(i) {
return nil obj := a.GetAttributedToObject(i)
if obj.HasId() {
u = append(u, obj.GetId())
}
} else if a.IsAttributedToLink(i) {
l := a.GetAttributedToLink(i)
if l.HasHref() {
u = append(u, l.GetHref())
}
} else if a.IsAttributedToIRI(i) {
u = append(u, a.GetAttributedToIRI(i))
}
}
for i := 0; i < a.ActorLen(); i++ {
if a.IsActorObject(i) {
obj := a.GetActorObject(i)
if obj.HasId() {
u = append(u, obj.GetId())
}
} else if a.IsActorLink(i) {
l := a.GetActorLink(i)
if l.HasHref() {
u = append(u, l.GetHref())
}
} else if a.IsActorIRI(i) {
u = append(u, a.GetActorIRI(i))
}
}
return u
} }
// stripHiddenRecipients removes "bto" and "bcc" from the DeliverableObject. // stripHiddenRecipients removes "bto" and "bcc" from the DeliverableObject.
@ -463,8 +504,23 @@ type itemer interface {
// getURIsInItemer will extract 'items' from the provided Collection or // getURIsInItemer will extract 'items' from the provided Collection or
// CollectionPage. // CollectionPage.
func getURIsInItemer(i itemer) []url.URL { func getURIsInItemer(i itemer) []url.URL {
// TODO: Implement var u []url.URL
return nil for j := 0; j < i.ItemsLen(); j++ {
if i.IsItemsObject(j) {
obj := i.GetItemsObject(j)
if obj.HasId() {
u = append(u, obj.GetId())
}
} else if i.IsItemsLink(j) {
l := i.GetItemsLink(j)
if l.HasHref() {
u = append(u, l.GetHref())
}
} else if i.IsItemsIRI(j) {
u = append(u, i.GetItemsIRI(j))
}
}
return u
} }
type orderedItemer interface { type orderedItemer interface {
@ -480,6 +536,21 @@ type orderedItemer interface {
// getURIsInOrderedItemer will extract 'items' from the provided // getURIsInOrderedItemer will extract 'items' from the provided
// OrderedCollection or OrderedCollectionPage. // OrderedCollection or OrderedCollectionPage.
func getURIsInOrderedItemer(i orderedItemer) []url.URL { func getURIsInOrderedItemer(i orderedItemer) []url.URL {
// TODO: Implement var u []url.URL
return nil for j := 0; j < i.OrderedItemsLen(); j++ {
if i.IsOrderedItemsObject(j) {
obj := i.GetOrderedItemsObject(j)
if obj.HasId() {
u = append(u, obj.GetId())
}
} else if i.IsOrderedItemsLink(j) {
l := i.GetOrderedItemsLink(j)
if l.HasHref() {
u = append(u, l.GetHref())
}
} else if i.IsOrderedItemsIRI(j) {
u = append(u, i.GetOrderedItemsIRI(j))
}
}
return u
} }