diff options
-rw-r--r-- | activitypub/actor.go | 56 | ||||
-rw-r--r-- | route/routes/actor.go | 36 | ||||
-rw-r--r-- | views/catalog.html | 1 | ||||
-rw-r--r-- | 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 @@ <span class="subject"><b>{{ .Name }}</b></span> <span class="name"><b>{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }}</b></span> <span class="tripcode"> {{ .TripCode }} </span> - <span class="timestamp" data-utc="{{.Published | timeToUnix}}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}#{{ shortURL $board.Actor.Outbox .Id }}">No.</a> <a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">Report</a>]{{ end }}</span> + <span class="timestamp" data-utc="{{.Published | timeToUnix}}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}">No.</a> <a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">Report</a>]{{ end }}</span> <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread .Id $page.PostType }}</p> {{ if .Replies }} {{ $replies := .Replies }} |