Inboxes and outboxes now contain IRIs.

As part of normalization of objects and not embedding them everywhere.
このコミットが含まれているのは:
Cory Slep 2018-06-06 22:26:48 +02:00
コミット 53c59ed335
2個のファイルの変更17行の追加5行の削除

ファイルの表示

@ -2172,10 +2172,13 @@ func TestPostInbox_Create_SetsObject(t *testing.T) {
req := ActivityPubRequest(httptest.NewRequest("POST", testInboxURI, bytes.NewBuffer(MustSerialize(testCreateNote))))
gotSet := 0
var setObject PubObject
var gotSetInbox PubObject
app.MockFederateApp.set = func(c context.Context, o PubObject) error {
gotSet++
if gotSet == 1 {
setObject = o
} else if gotSet == 2 {
gotSetInbox = o
}
return nil
}
@ -2183,6 +2186,9 @@ func TestPostInbox_Create_SetsObject(t *testing.T) {
return nil
}
handled, err := p.PostInbox(context.Background(), resp, req)
expectedInbox := &vocab.OrderedCollection{}
expectedInbox.AppendType("OrderedCollection")
expectedInbox.AppendOrderedItemsIRI(testCreateNote.GetId())
if err != nil {
t.Fatal(err)
} else if !handled {
@ -2191,6 +2197,8 @@ func TestPostInbox_Create_SetsObject(t *testing.T) {
t.Fatalf("expected %d, got %d", 2, gotSet)
} else if err := PubObjectEquals(setObject, testNote); err != nil {
t.Fatalf("unexpected set object: %s", err)
} else if err := PubObjectEquals(gotSetInbox, expectedInbox); err != nil {
t.Fatalf("unexpected callback object: %s", err)
}
}
@ -4497,7 +4505,7 @@ func TestPostOutbox_Create_SetCreatedObject(t *testing.T) {
handled, err := p.PostOutbox(context.Background(), resp, req)
expectedOutbox := &vocab.OrderedCollection{}
expectedOutbox.AppendType("OrderedCollection")
expectedOutbox.AppendOrderedItemsObject(testClientExpectedCreateNote)
expectedOutbox.AppendOrderedItemsIRI(testClientExpectedCreateNote.GetId())
if err != nil {
t.Fatal(err)
} else if !handled {

ファイルの表示

@ -1726,7 +1726,6 @@ func (f *federator) ownsAnyObjects(c context.Context, a vocab.ActivityType) (boo
return f.ownsAnyIRIs(c, iris), nil
}
// TODO: Only Set IRIs
func (f *federator) addToOutbox(c context.Context, r *http.Request, m map[string]interface{}) error {
outbox, err := f.App.GetOutbox(c, r, ReadWrite)
if err != nil {
@ -1739,11 +1738,13 @@ func (f *federator) addToOutbox(c context.Context, r *http.Request, m map[string
if err := f.App.Set(c, activity); err != nil {
return err
}
outbox.PrependOrderedItemsObject(activity)
if !activity.HasId() {
return fmt.Errorf("activity missing id")
}
outbox.PrependOrderedItemsIRI(activity.GetId())
return f.App.Set(c, outbox)
}
// TODO: Only Set IRIs
func (f *federator) addToInbox(c context.Context, r *http.Request, m map[string]interface{}) error {
inbox, err := f.App.GetInbox(c, r, ReadWrite)
if err != nil {
@ -1757,8 +1758,11 @@ func (f *federator) addToInbox(c context.Context, r *http.Request, m map[string]
if err != nil {
return err
}
if !activity.HasId() {
return fmt.Errorf("activity missing id")
}
if !iriSet[activity.GetId().String()] {
inbox.PrependOrderedItemsObject(activity)
inbox.PrependOrderedItemsIRI(activity.GetId())
return f.App.Set(c, inbox)
}
return nil