From e97c3e9d2d1bedf63a7d341eb199c9500bcd8cd9 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Thu, 15 Jul 2021 14:47:22 -0700 Subject: can follow other boards followers or following by passing in the url you want to follow eg https://fchan.xyz/b/following and your board will follow all the boards that board is following or https://fchan.xyz/b/followers to follow all that boards followers --- follow.go | 17 +++++++++++------ main.go | 50 +++++++++++++++++++++++++++++++++++++++++++------- static/faq.html | 2 +- static/manage.html | 6 +++--- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/follow.go b/follow.go index b0f0515..5fb7017 100644 --- a/follow.go +++ b/follow.go @@ -152,17 +152,22 @@ func RejectActivity(activity Activity) Activity { return accept } -func SetActorFollowerDB(db *sql.DB, activity Activity) Activity { - var query string - alreadyFollow := false - followers := GetActorFollowDB(db, activity.Actor.Id) +func IsAlreadyFollowing(db *sql.DB, actor string, follow string) bool { + followers := GetActorFollowingDB(db, actor) for _, e := range followers { - if e.Id == activity.Object.Actor { - alreadyFollow = true + if e.Id == follow { + return true } } + return false; +} + +func SetActorFollowerDB(db *sql.DB, activity Activity) Activity { + var query string + alreadyFollow := IsAlreadyFollowing(db, activity.Actor.Id, activity.Object.Actor) + if alreadyFollow { query = `delete from follower where id=$1 and follower=$2` activity.Summary = activity.Object.Actor + " Unfollow " + activity.Actor.Id diff --git a/main.go b/main.go index d36fec5..68daf39 100644 --- a/main.go +++ b/main.go @@ -474,15 +474,51 @@ func main() { if follow || adminFollow { r.ParseForm() - followActivity := MakeFollowActivity(db, r.FormValue("actor"), r.FormValue("follow")) + following := regexp.MustCompile(`(.+)\/following`) + followers := regexp.MustCompile(`(.+)\/followers`) + + follow := r.FormValue("follow") + actorId := r.FormValue("actor") + + //follow all of boards following + if following.MatchString(follow) { + followingActor := FingerActor(follow) + col := GetActorCollection(followingActor.Following) + for _, e := range col.Items { + if !IsAlreadyFollowing(db, actorId, e.Id) && e.Id != Domain { + followActivity := MakeFollowActivity(db, actorId, e.Id) + + if FingerActor(e.Id).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } + } + } + + //follow all of boards followers + } else if followers.MatchString(follow){ + followersActor := FingerActor(follow) + col := GetActorCollection(followersActor.Followers) + for _, e := range col.Items { + if !IsAlreadyFollowing(db, actorId, e.Id) && e.Id != Domain { + followActivity := MakeFollowActivity(db, actorId, e.Id) + if FingerActor(e.Id).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } + } + } + + //do a normal follow to a single board + } else { + followActivity := MakeFollowActivity(db, actorId, follow) - if followActivity.Actor.Id == Domain && !IsActorLocal(db, followActivity.Object.Actor) { - w.Write([]byte("main board can only follow local boards. Create a new board and then follow outside boards from it.")) - return - } + if followActivity.Actor.Id == Domain && !IsActorLocal(db, followActivity.Object.Actor) { + w.Write([]byte("main board can only follow local boards. Create a new board and then follow outside boards from it.")) + return + } - if FingerActor(r.FormValue("follow")).Id != "" { - MakeActivityRequestOutbox(db, followActivity) + if FingerActor(follow).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } } var redirect string diff --git a/static/faq.html b/static/faq.html index 5d70e8e..08a38f4 100644 --- a/static/faq.html +++ b/static/faq.html @@ -56,7 +56,7 @@
Soon™.
v0.0.9-dev
+v0.0.10-dev