diff options
author | FChannel <> | 2021-07-15 13:49:29 -0700 |
---|---|---|
committer | FChannel <> | 2021-07-15 13:49:29 -0700 |
commit | 22ee823b6e9200317337941c2ad41ca9df9dd855 (patch) | |
tree | 8ff9518bb529ff476bf4d667ea3f72b4cba970a2 /follow.go | |
parent | 26f59904f0f1d7a908969ad0f5846448b0e7451b (diff) |
added auto follow for boards
Diffstat (limited to 'follow.go')
-rw-r--r-- | follow.go | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -217,3 +217,49 @@ func SetActorFollowingDB(db *sql.DB, activity Activity) Activity { activity.Type = "Accept" return activity } + +func AutoFollow(db *sql.DB, actor string) { + following := GetActorFollowingDB(db, actor) + follower := GetActorFollowDB(db, actor) + + isFollowing := false + + for _, e := range follower { + for _, k := range following { + if e.Id == k.Id { + isFollowing = true + } + } + + if !isFollowing && e.Id != Domain { + followActivity := MakeFollowActivity(db, actor, e.Id) + + if FingerActor(e.Id).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } + } + } +} + +func MakeFollowActivity(db *sql.DB, actor string, follow string) Activity { + var followActivity Activity + + followActivity.AtContext.Context = "https://www.w3.org/ns/activitystreams" + followActivity.Type = "Follow" + + var obj ObjectBase + var nactor Actor + if actor == Domain { + nactor = GetActorFromDB(db, actor) + } else { + nactor = FingerActor(actor) + } + + followActivity.Actor = &nactor + followActivity.Object = &obj + + followActivity.Object.Actor = follow + followActivity.To = append(followActivity.To, follow) + + return followActivity +} |