Skip to content

Commit

Permalink
ActivityPub: add cli option to refetch followers (inbox, username)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlelse committed Dec 26, 2024
1 parent 48cc603 commit d61addc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
28 changes: 28 additions & 0 deletions activityPub.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,31 @@ func (a *goBlog) signRequest(r *http.Request, blogIri string) error {
defer a.apSignMutex.Unlock()
return a.apSigner.SignRequest(a.apPrivateKey, blogIri+"#main-key", r, bodyBuf.Bytes())
}

func (a *goBlog) apRefetchFollowers(blogName string) error {
followers, err := a.db.apGetAllFollowers(blogName)
if err != nil {
return err
}
for _, fol := range followers {
actor, err := a.apGetRemoteActor(ap.IRI(fol.follower), blogName)
if err != nil || actor == nil {
a.error("ActivityPub: Failed to retrieve remote actor info", "actor", fol.follower)
continue
}
inbox := actor.Inbox.GetLink()
if endpoints := actor.Endpoints; endpoints != nil && endpoints.SharedInbox != nil && endpoints.SharedInbox.GetLink() != "" {
inbox = endpoints.SharedInbox.GetLink()
}
if inbox == "" {
a.error("ActivityPub: Failed to get inbox for actor", "actor", fol.follower)
continue
}
username := apUsername(actor)
if err = a.db.apAddFollower(blogName, actor.GetLink().String(), inbox.String(), username); err != nil {
a.error("ActivityPub: Failed to update follower info", "err", err)
return err
}
}
return nil
}
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ func main() {
return
}

// ActivityPub refetch followers
if len(os.Args) >= 2 && os.Args[1] == "activitypub" {
if !app.apEnabled() {
app.logErrAndQuit("ActivityPub not enabled")
return
}
if err = app.initActivityPub(); err != nil {
app.logErrAndQuit("Failed to init ActivityPub", "err", err)
return
}
if len(os.Args) >= 4 && os.Args[2] == "refetch-followers" {
blog := os.Args[3]
if err = app.apRefetchFollowers(blog); err != nil {
app.logErrAndQuit("Failed to refetch activitypub followers", "blog", blog, "err", err)
return
}
app.shutdown.ShutdownAndWait()
return
}
}

// Initialize components
app.initComponents()

Expand Down

0 comments on commit d61addc

Please sign in to comment.