From 27d0796d7f775034f391ba8aaca99f2a81018842 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Tue, 14 Jun 2022 12:57:56 -0700 Subject: send to correct actors incase not following directly --- activitypub/activity.go | 12 ++++++++++++ activitypub/actor.go | 2 +- activitypub/object.go | 33 ++++++++++++++++++++++++++++++++- route/routes/actor.go | 5 ++--- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/activitypub/activity.go b/activitypub/activity.go index 5d89272..71f2d5c 100644 --- a/activitypub/activity.go +++ b/activitypub/activity.go @@ -44,8 +44,20 @@ func (activity Activity) AddFollowersTo() (Activity, error) { return activity, util.MakeError(err, "AddFollowersTo") } + // get followers of activity actor for _, k := range aFollowers.Items { activity.To = append(activity.To, k.Id) + reqActivity := Activity{Id: k.Id + "/followers"} + + bFollowers, err := reqActivity.GetCollection() + if err != nil { + return activity, util.MakeError(err, "AddFollowersTo") + } + + // get followers of activity actor followers + for _, j := range bFollowers.Items { + activity.To = append(activity.To, j.Id) + } } } diff --git a/activitypub/actor.go b/activitypub/actor.go index b69c831..afd9efd 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -143,7 +143,7 @@ func (actor Actor) AutoFollow() error { } func (actor Actor) DeleteCache() error { - query := `select id from cacheactivitystream where id in (select id from cacheactivitystream where actor=$1)` + query := `select id from cacheactivitystream where id in (select id from cacheactivitystream where actor=$1 and id in (select id from replies where inreplyto='')) ` rows, err := config.DB.Query(query, actor.Id) if err != nil { diff --git a/activitypub/object.go b/activitypub/object.go index 74fc136..5eb8e67 100644 --- a/activitypub/object.go +++ b/activitypub/object.go @@ -14,6 +14,37 @@ import ( "github.com/FChannel0/FChannel-Server/util" ) +func (obj ObjectBase) WantToCache(actor Actor) (bool, error) { + reqActivity := Activity{Id: obj.Actor + "/followers"} + objFollowers, err := reqActivity.GetCollection() + + if err != nil { + return false, util.MakeError(err, "WantToCache") + } + + actorFollowing, err := actor.GetFollowing() + + if err != nil { + return false, util.MakeError(err, "WantToCache") + } + + isOP, _ := obj.CheckIfOP() + + for _, e := range objFollowers.Items { + if e.Id == actor.Id { + return true, nil + } + + for _, k := range actorFollowing { + if e.Id == k.Id && !isOP && obj.InReplyTo[0].Id != "" { + return true, nil + } + } + } + + return false, nil +} + func (obj ObjectBase) CreateActivity(activityType string) (Activity, error) { var newActivity Activity @@ -1202,7 +1233,7 @@ func (obj NestedObjectBase) WritePreviewCache() error { func (obj ObjectBase) WriteReply() error { for i, e := range obj.InReplyTo { - if isOP, err := obj.CheckIfOP(); err == nil && !isOP && i == 0 { + if isOP, err := obj.CheckIfOP(); !isOP && i == 0 { var nObj ObjectBase nObj.Id = e.Id diff --git a/route/routes/actor.go b/route/routes/actor.go index 83cbca2..413f18c 100644 --- a/route/routes/actor.go +++ b/route/routes/actor.go @@ -56,12 +56,11 @@ func ActorInbox(ctx *fiber.Ctx) error { break } - if _, err := activity.Object.WriteCache(); err != nil { + if wantToCache, err := activity.Object.WantToCache(actor); !wantToCache { return util.MakeError(err, "ActorInbox") } - actor, err := activitypub.GetActorFromDB(e) - if err != nil { + if _, err := activity.Object.WriteCache(); err != nil { return util.MakeError(err, "ActorInbox") } -- cgit v1.2.3