Add support for wrapping objects in Create activity.
このコミットが含まれているのは:
コミット
7400a3197f
13
pub/fed.go
13
pub/fed.go
|
@ -145,6 +145,9 @@ type Application interface {
|
|||
// the provided object in the outbox of the user represented by the
|
||||
// client id token.
|
||||
AddToOutboxResolver(id string) (*streams.Resolver, error)
|
||||
// ActorIRI returns the actor's IRI associated with the given client ID
|
||||
// token.
|
||||
ActorIRI(id string) (url.URL, error)
|
||||
}
|
||||
|
||||
// Receiver is provided by users of this library and designed to handle
|
||||
|
@ -329,7 +332,15 @@ func (f *federator) PostOutbox(id string) HandlerFunc {
|
|||
}
|
||||
newId := f.App.NewId(id, typer)
|
||||
if !isActivityType(typer) {
|
||||
// TODO: Wrap in Create Activity
|
||||
actorIri, err := f.App.ActorIRI(id)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
obj, ok := typer.(vocab.ObjectType)
|
||||
if !ok {
|
||||
return true, fmt.Errorf("wrap in create: cannot convert to vocab.ObjectType: %T", typer)
|
||||
}
|
||||
typer = f.wrapInCreate(obj, actorIri)
|
||||
}
|
||||
typer.SetId(newId)
|
||||
if m, err = typer.Serialize(); err != nil {
|
||||
|
|
|
@ -89,6 +89,64 @@ func (f *federator) postToOutbox(b []byte, to url.URL) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// wrapInCreate will automatically wrap the provided object in a Create
|
||||
// activity. This will copy over the 'to', 'bto', 'cc', 'bcc', and 'audience'
|
||||
// properties. It will also copy over the published time if present.
|
||||
func (f *federator) wrapInCreate(o vocab.ObjectType, actor url.URL) *vocab.Create {
|
||||
c := &vocab.Create{}
|
||||
c.AddObject(o)
|
||||
c.AddActorIRI(actor)
|
||||
if o.IsPublished() {
|
||||
c.SetPublished(o.GetPublished())
|
||||
}
|
||||
for i := 0; i < o.ToLen(); i++ {
|
||||
if o.IsToObject(i) {
|
||||
c.AddToObject(o.GetToObject(i))
|
||||
} else if o.IsToLink(i) {
|
||||
c.AddToLink(o.GetToLink(i))
|
||||
} else if o.IsToIRI(i) {
|
||||
c.AddToIRI(o.GetToIRI(i))
|
||||
}
|
||||
}
|
||||
for i := 0; i < o.BtoLen(); i++ {
|
||||
if o.IsBtoObject(i) {
|
||||
c.AddBtoObject(o.GetBtoObject(i))
|
||||
} else if o.IsBtoLink(i) {
|
||||
c.AddBtoLink(o.GetBtoLink(i))
|
||||
} else if o.IsBtoIRI(i) {
|
||||
c.AddBtoIRI(o.GetBtoIRI(i))
|
||||
}
|
||||
}
|
||||
for i := 0; i < o.CcLen(); i++ {
|
||||
if o.IsCcObject(i) {
|
||||
c.AddCcObject(o.GetCcObject(i))
|
||||
} else if o.IsCcLink(i) {
|
||||
c.AddCcLink(o.GetCcLink(i))
|
||||
} else if o.IsCcIRI(i) {
|
||||
c.AddCcIRI(o.GetCcIRI(i))
|
||||
}
|
||||
}
|
||||
for i := 0; i < o.BccLen(); i++ {
|
||||
if o.IsBccObject(i) {
|
||||
c.AddBccObject(o.GetBccObject(i))
|
||||
} else if o.IsBccLink(i) {
|
||||
c.AddBccLink(o.GetBccLink(i))
|
||||
} else if o.IsBccIRI(i) {
|
||||
c.AddBccIRI(o.GetBccIRI(i))
|
||||
}
|
||||
}
|
||||
for i := 0; i < o.AudienceLen(); i++ {
|
||||
if o.IsAudienceObject(i) {
|
||||
c.AddAudienceObject(o.GetAudienceObject(i))
|
||||
} else if o.IsAudienceLink(i) {
|
||||
c.AddAudienceLink(o.GetAudienceLink(i))
|
||||
} else if o.IsAudienceIRI(i) {
|
||||
c.AddAudienceIRI(o.GetAudienceIRI(i))
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// TODO: (Section 7) HTTP caching mechanisms [RFC7234] SHOULD be respected when appropriate, both when receiving responses from other servers as well as sending responses to other servers.
|
||||
|
||||
// prepare takes a DeliverableObject and returns a list of the proper recipient
|
||||
|
|
読み込み中…
新しいイシューから参照