diff --git a/src/activitypub/object.go b/src/activitypub/object.go index 4ea0b57..a0a7756 100644 --- a/src/activitypub/object.go +++ b/src/activitypub/object.go @@ -284,6 +284,7 @@ func RecipientsDeduplication(recArgs ...*ObjectsArr) error { if recList == nil { continue } + toRemove := make([]int, 0) for i, rec := range *recList { save := true @@ -301,11 +302,7 @@ func RecipientsDeduplication(recArgs ...*ObjectsArr) error { sort.Sort(sort.Reverse(sort.IntSlice(toRemove))) for _, idx := range toRemove { - if idx == len(*recList) { - *recList = (*recList)[:idx] - } else { - *recList = append((*recList)[:idx], (*recList)[idx+1:]...) - } + *recList = append((*recList)[:idx], (*recList)[idx+1:]...) } } return nil diff --git a/src/activitypub/object_test.go b/src/activitypub/object_test.go index 3c7f459..a12186c 100644 --- a/src/activitypub/object_test.go +++ b/src/activitypub/object_test.go @@ -178,7 +178,18 @@ func TestRecipientsDeduplication(t *testing.T) { RecipientsDeduplication(&first) if len(first) != 4 { - t.Errorf("Objects array should have exactly 8(eight) elements, not %d", len(first)) + t.Errorf("Objects array should have exactly 4(four) elements, not %d", len(first)) } + second := make(ObjectsArr, 0) + second.Append(bar) + second.Append(foo) + + RecipientsDeduplication(&first, &second) + if len(first) != 4 { + t.Errorf("First Objects array should have exactly 8(eight) elements, not %d", len(first)) + } + if len(second) != 0 { + t.Errorf("Second Objects array should have exactly 0(zero) elements, not %d", len(second)) + } }