Generalizing the itemcollection deduplication function
This commit is contained in:
parent
4a1645657e
commit
b21a965f7a
3 changed files with 21 additions and 17 deletions
14
activity.go
14
activity.go
|
@ -696,7 +696,7 @@ func IntransitiveActivityNew(id ObjectID, typ ActivityVocabularyType) *Intransit
|
|||
func (a *Activity) Recipients() ItemCollection {
|
||||
var actor ItemCollection
|
||||
actor.Append(a.Actor)
|
||||
rec, _ := recipientsDeduplication(&actor, &a.To, &a.Bto, &a.CC, &a.BCC, &a.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&actor, &a.To, &a.Bto, &a.CC, &a.BCC, &a.Audience)
|
||||
a.BCC = a.BCC[:0]
|
||||
a.Bto = a.Bto[:0]
|
||||
return rec
|
||||
|
@ -706,7 +706,7 @@ func (a *Activity) Recipients() ItemCollection {
|
|||
func (i *IntransitiveActivity) Recipients() ItemCollection {
|
||||
var actor ItemCollection
|
||||
actor.Append(i.Actor)
|
||||
rec, _ := recipientsDeduplication(&actor, &i.To, &i.Bto, &i.CC, &i.BCC, &i.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&actor, &i.To, &i.Bto, &i.CC, &i.BCC, &i.Audience)
|
||||
i.BCC = i.BCC[:0]
|
||||
i.Bto = i.Bto[:0]
|
||||
return rec
|
||||
|
@ -717,7 +717,7 @@ func (b *Block) Recipients() ItemCollection {
|
|||
var dedupObjects ItemCollection
|
||||
dedupObjects.Append(b.Actor)
|
||||
dedupObjects.Append(b.Object)
|
||||
rec, _ := recipientsDeduplication(&dedupObjects, &b.To, &b.Bto, &b.CC, &b.BCC, &b.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&dedupObjects, &b.To, &b.Bto, &b.CC, &b.BCC, &b.Audience)
|
||||
b.BCC = b.BCC[:0]
|
||||
b.Bto = b.Bto[:0]
|
||||
return rec
|
||||
|
@ -728,7 +728,7 @@ func (c *Create) Recipients() ItemCollection {
|
|||
var dedupObjects ItemCollection
|
||||
dedupObjects.Append(c.Actor)
|
||||
dedupObjects.Append(c.Object)
|
||||
rec, _ := recipientsDeduplication(&dedupObjects, &c.To, &c.Bto, &c.CC, &c.BCC, &c.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&dedupObjects, &c.To, &c.Bto, &c.CC, &c.BCC, &c.Audience)
|
||||
c.BCC = c.BCC[:0]
|
||||
c.Bto = c.Bto[:0]
|
||||
return rec
|
||||
|
@ -739,7 +739,7 @@ func (l *Like) Recipients() ItemCollection {
|
|||
var dedupObjects ItemCollection
|
||||
dedupObjects.Append(l.Actor)
|
||||
dedupObjects.Append(l.Object)
|
||||
rec, _ := recipientsDeduplication(&dedupObjects, &l.To, &l.Bto, &l.CC, &l.BCC, &l.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&dedupObjects, &l.To, &l.Bto, &l.CC, &l.BCC, &l.Audience)
|
||||
l.BCC = l.BCC[:0]
|
||||
l.Bto = l.Bto[:0]
|
||||
return rec
|
||||
|
@ -750,7 +750,7 @@ func (d *Dislike) Recipients() ItemCollection {
|
|||
var dedupObjects ItemCollection
|
||||
dedupObjects.Append(d.Actor)
|
||||
dedupObjects.Append(d.Object)
|
||||
rec, _ := recipientsDeduplication(&dedupObjects, &d.To, &d.Bto, &d.CC, &d.BCC, &d.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&dedupObjects, &d.To, &d.Bto, &d.CC, &d.BCC, &d.Audience)
|
||||
d.BCC = d.BCC[:0]
|
||||
d.Bto = d.Bto[:0]
|
||||
return rec
|
||||
|
@ -761,7 +761,7 @@ func (u *Update) Recipients() ItemCollection {
|
|||
var dedupObjects ItemCollection
|
||||
dedupObjects.Append(u.Actor)
|
||||
dedupObjects.Append(u.Object)
|
||||
rec, _ := recipientsDeduplication(&dedupObjects, &u.To, &u.Bto, &u.CC, &u.BCC, &u.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&dedupObjects, &u.To, &u.Bto, &u.CC, &u.BCC, &u.Audience)
|
||||
u.BCC = u.BCC[:0]
|
||||
u.Bto = u.Bto[:0]
|
||||
return rec
|
||||
|
|
14
object.go
14
object.go
|
@ -515,8 +515,8 @@ func (o Object) GetType() ActivityVocabularyType {
|
|||
return o.Type
|
||||
}
|
||||
|
||||
// recipientsDeduplication normalizes the received arguments lists
|
||||
func recipientsDeduplication(recCols ...*ItemCollection) (ItemCollection, error) {
|
||||
// ItemCollectionDeduplication normalizes the received arguments lists into a single unified one
|
||||
func ItemCollectionDeduplication(recCols ...*ItemCollection) (ItemCollection, error) {
|
||||
rec := make(ItemCollection, 0)
|
||||
|
||||
for _, recCol := range recCols {
|
||||
|
@ -749,7 +749,7 @@ func (t *Tombstone) UnmarshalJSON(data []byte) error {
|
|||
// Recipients performs recipient de-duplication on the Object's To, Bto, CC and BCC properties
|
||||
func (o *object) Recipients() ItemCollection {
|
||||
var aud ItemCollection
|
||||
rec, _ := recipientsDeduplication(&aud, &o.To, &o.Bto, &o.CC, &o.BCC, &o.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&aud, &o.To, &o.Bto, &o.CC, &o.BCC, &o.Audience)
|
||||
o.BCC = o.BCC[:0]
|
||||
o.Bto = o.Bto[:0]
|
||||
return rec
|
||||
|
@ -758,7 +758,7 @@ func (o *object) Recipients() ItemCollection {
|
|||
// Recipients performs recipient de-duplication on the Place object's To, Bto, CC and BCC properties
|
||||
func (p *Place) Recipients() ItemCollection {
|
||||
var aud ItemCollection
|
||||
rec, _ := recipientsDeduplication(&aud, &p.To, &p.Bto, &p.CC, &p.BCC, &p.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&aud, &p.To, &p.Bto, &p.CC, &p.BCC, &p.Audience)
|
||||
p.BCC = p.BCC[:0]
|
||||
p.Bto = p.Bto[:0]
|
||||
return rec
|
||||
|
@ -767,7 +767,7 @@ func (p *Place) Recipients() ItemCollection {
|
|||
// Recipients performs recipient de-duplication on the Profile object's To, Bto, CC and BCC properties
|
||||
func (p *Profile) Recipients() ItemCollection {
|
||||
var aud ItemCollection
|
||||
rec, _ := recipientsDeduplication(&aud, &p.To, &p.Bto, &p.CC, &p.BCC, &p.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&aud, &p.To, &p.Bto, &p.CC, &p.BCC, &p.Audience)
|
||||
p.BCC = p.BCC[:0]
|
||||
p.Bto = p.Bto[:0]
|
||||
return rec
|
||||
|
@ -776,7 +776,7 @@ func (p *Profile) Recipients() ItemCollection {
|
|||
// Recipients performs recipient de-duplication on the Relationship object's To, Bto, CC and BCC properties
|
||||
func (r *Relationship) Recipients() ItemCollection {
|
||||
var aud ItemCollection
|
||||
rec, _ := recipientsDeduplication(&aud, &r.To, &r.Bto, &r.CC, &r.BCC, &r.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&aud, &r.To, &r.Bto, &r.CC, &r.BCC, &r.Audience)
|
||||
r.BCC = r.BCC[:0]
|
||||
r.Bto = r.Bto[:0]
|
||||
return rec
|
||||
|
@ -785,7 +785,7 @@ func (r *Relationship) Recipients() ItemCollection {
|
|||
// Recipients performs recipient de-duplication on the Tombstone object's To, Bto, CC and BCC properties
|
||||
func (t *Tombstone) Recipients() ItemCollection {
|
||||
var aud ItemCollection
|
||||
rec, _ := recipientsDeduplication(&aud, &t.To, &t.Bto, &t.CC, &t.BCC, &t.Audience)
|
||||
rec, _ := ItemCollectionDeduplication(&aud, &t.To, &t.Bto, &t.CC, &t.BCC, &t.Audience)
|
||||
t.BCC = t.BCC[:0]
|
||||
t.Bto = t.Bto[:0]
|
||||
return rec
|
||||
|
|
|
@ -327,7 +327,7 @@ func TestRecipients(t *testing.T) {
|
|||
t.Errorf("Objects array should have exactly 8(eight) elements, not %d", len(first))
|
||||
}
|
||||
|
||||
recipientsDeduplication(&first)
|
||||
ItemCollectionDeduplication(&first)
|
||||
if len(first) != 4 {
|
||||
t.Errorf("Objects array should have exactly 4(four) elements, not %d", len(first))
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ func TestRecipients(t *testing.T) {
|
|||
second.Append(bar)
|
||||
second.Append(foo)
|
||||
|
||||
recipientsDeduplication(&first, &second)
|
||||
ItemCollectionDeduplication(&first, &second)
|
||||
if len(first) != 4 {
|
||||
t.Errorf("First Objects array should have exactly 8(eight) elements, not %d", len(first))
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ func TestRecipients(t *testing.T) {
|
|||
t.Errorf("Second Objects array should have exactly 0(zero) elements, not %d", len(second))
|
||||
}
|
||||
|
||||
_, err := recipientsDeduplication(&first, &second, nil)
|
||||
_, err := ItemCollectionDeduplication(&first, &second, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Deduplication with empty array failed")
|
||||
}
|
||||
|
@ -731,3 +731,7 @@ func TestNaturalLanguageValues_String(t *testing.T) {
|
|||
func TestNaturalLanguageValues_Count(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
||||
func TestItemCollectionDeduplication(t *testing.T) {
|
||||
t.Skipf("TODO")
|
||||
}
|
||||
|
|
Reference in a new issue