diff options
author | mariusor | 2022-05-24 12:23:01 +0200 |
---|---|---|
committer | mariusor | 2022-05-24 12:23:01 +0200 |
commit | a8ab351bd662b66a34ef348faa89492dd3faf809 (patch) | |
tree | 21883668b2a659ac9fbdff985a6f840dbc2f0ce2 | |
parent | 835c891752efe49fcfe7aa33081f21ca5cd0e1e1 (diff) |
Improve CollectionType.Of
We now check that both following things happen
Collection type matches OnActor collection types
Item type matches a Actor activity types
-rw-r--r-- | typer.go | 44 |
1 files changed, 21 insertions, 23 deletions
@@ -143,32 +143,30 @@ func (t CollectionType) Of(i pub.Item) pub.Item { return nil } var it pub.Item - pub.OnActor(i, func(a *pub.Actor) error { - if t == Inbox && a.Inbox != nil { - it = a.Inbox - } - if t == Outbox && a.Outbox != nil { - it = a.Outbox - } - if t == Liked && a.Liked != nil { - it = a.Liked - } - if t == Following && a.Following != nil { - it = a.Following - } - if t == Followers && a.Followers != nil { - it = a.Followers - } - return nil - }) + if OnActor.Contains(t) && pub.ActorTypes.Contains(i.GetType()) { + pub.OnActor(i, func(a *pub.Actor) error { + switch t { + case Inbox: + it = a.Inbox + case Outbox: + it = a.Outbox + case Liked: + it = a.Liked + case Following: + it = a.Following + case Followers: + it = a.Followers + } + return nil + }) + } pub.OnObject(i, func(o *pub.Object) error { - if t == Likes && o.Likes != nil { + switch t { + case Likes: it = o.Likes - } - if t == Shares && o.Shares != nil { + case Shares: it = o.Shares - } - if t == Replies && o.Replies != nil { + case Replies: it = o.Replies } return nil |