From 7306338e7f23d652b6b0bfecddcee408a4227169 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Tue, 14 Jun 2022 14:50:32 -0700 Subject: added sendtofollowers to cc incase not already sending to followers ie. sending from other server than fchannel --- activitypub/actor.go | 56 +++++++++++++++++++++++++++++++++++------------ route/routes/actor.go | 36 +++++++++--------------------- views/catalog.html | 1 - views/partials/posts.html | 2 +- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/activitypub/actor.go b/activitypub/actor.go index afd9efd..be51460 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -893,34 +893,32 @@ func (actor Actor) SetAutoSubscribe() error { } func (actor Actor) SendToFollowers(activity Activity) error { - nActor, err := GetActorFromDB(actor.Id) - - if err != nil { - return util.MakeError(err, "SendToFollowers") - } - - activity.Actor = &nActor - followers, err := nActor.GetFollower() + followers, err := actor.GetFollower() if err != nil { return util.MakeError(err, "SendToFollowers") } - var to []string + var cc []string for _, e := range followers { + var isTo = false + for _, k := range activity.To { if e.Id != k { - to = append(to, e.Id) + isTo = true } } + + if !isTo { + cc = append(cc, e.Id) + } } - activity.To = to + activity.To = make([]string, 0) + activity.Cc = cc - if len(activity.Object.InReplyTo) > 0 { - err = activity.MakeRequestInbox() - } + err = activity.MakeRequestInbox() return util.MakeError(err, "SendToFollowers") } @@ -1169,3 +1167,33 @@ func (actor Actor) GetJanitors() ([]util.Verify, error) { return list, nil } + +func (actor Actor) ProcessInboxCreate(activity Activity) error { + if local, _ := actor.IsLocal(); local { + if local, _ := activity.Actor.IsLocal(); !local { + reqActivity := Activity{Id: activity.Object.Id} + col, err := reqActivity.GetCollection() + if err != nil { + return util.MakeError(err, "ActorInbox") + } + + if len(col.OrderedItems) < 1 { + return util.MakeError(errors.New("Object does not exist"), "ActorInbox") + } + + if wantToCache, err := activity.Object.WantToCache(actor); !wantToCache { + return util.MakeError(err, "ActorInbox") + } + + if _, err := activity.Object.WriteCache(); err != nil { + return util.MakeError(err, "ActorInbox") + } + + if err := actor.ArchivePosts(); err != nil { + return util.MakeError(err, "ActorInbox") + } + } + } + + return nil +} diff --git a/route/routes/actor.go b/route/routes/actor.go index 413f18c..8690b78 100644 --- a/route/routes/actor.go +++ b/route/routes/actor.go @@ -44,39 +44,23 @@ func ActorInbox(ctx *fiber.Ctx) error { case "Create": for _, e := range activity.To { actor := activitypub.Actor{Id: e} - if local, _ := actor.IsLocal(); local { - if local, _ := activity.Actor.IsLocal(); !local { - reqActivity := activitypub.Activity{Id: activity.Object.Id} - col, err := reqActivity.GetCollection() - if err != nil { - return util.MakeError(err, "ActorInbox") - } - - if len(col.OrderedItems) < 1 { - break - } - - if wantToCache, err := activity.Object.WantToCache(actor); !wantToCache { - return util.MakeError(err, "ActorInbox") - } - - if _, err := activity.Object.WriteCache(); err != nil { - return util.MakeError(err, "ActorInbox") - } + if err := actor.ProcessInboxCreate(activity); err != nil { + return util.MakeError(err, "ActorInbox") + } - if err := actor.ArchivePosts(); err != nil { - return util.MakeError(err, "ActorInbox") - } + if err := actor.SendToFollowers(activity); err != nil { + return util.MakeError(err, "ActorInbox") + } + } - //SendToFollowers(e, activity) - } - } else if err != nil { + for _, e := range activity.Cc { + actor := activitypub.Actor{Id: e} + if err := actor.ProcessInboxCreate(activity); err != nil { return util.MakeError(err, "ActorInbox") } } break - case "Delete": for _, e := range activity.To { actor, err := activitypub.GetActorFromDB(e) diff --git a/views/catalog.html b/views/catalog.html index 6a99d8f..f19c489 100644 --- a/views/catalog.html +++ b/views/catalog.html @@ -89,4 +89,3 @@ {{ template "partials/footer" .page }} {{ template "partials/general_scripts" .page }} -{{ template "partials/post_scripts" .page }} diff --git a/views/partials/posts.html b/views/partials/posts.html index 8ae1745..d57a199 100644 --- a/views/partials/posts.html +++ b/views/partials/posts.html @@ -48,7 +48,7 @@ {{ .Name }} {{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }} {{ .TripCode }} - +
{{ parseContent $board.Actor $opId .Content $thread .Id $page.PostType }}
{{ if .Replies }} {{ $replies := .Replies }} -- cgit v1.2.3