From f93f32ee27fbd3afbccf30fb55550a1ee6c2c2a2 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sat, 17 Jul 2021 13:26:36 -0700 Subject: bug fix for auto follow errors --- follow.go | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'follow.go') diff --git a/follow.go b/follow.go index 5fb7017..14bf165 100644 --- a/follow.go +++ b/follow.go @@ -1,9 +1,13 @@ package main -import "net/http" -import "database/sql" -import _ "github.com/lib/pq" -import "encoding/json" +import ( + "database/sql" + "encoding/json" + "net/http" + + _ "github.com/lib/pq" + +) func GetActorFollowing(w http.ResponseWriter, db *sql.DB, id string) { var following Collection @@ -161,19 +165,38 @@ func IsAlreadyFollowing(db *sql.DB, actor string, follow string) bool { } } + return false; +} + +func IsAlreadyFollower(db *sql.DB, actor string, follow string) bool { + followers := GetActorFollowDB(db, actor) + + for _, e := range followers { + 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) + alreadyFollow := IsAlreadyFollower(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 + + _, err := db.Exec(query, activity.Actor.Id, activity.Object.Actor) + + if CheckError(err, "error with follower db insert/delete") != nil { + activity.Type = "Reject" + return activity + } } else { - query = `insert into follower (id, follower) values ($1, $2)` - activity.Summary = activity.Object.Actor + " Follow " + activity.Actor.Id + query = `insert into follower (id, follower) values ($1, $2)` + activity.Summary = activity.Object.Actor + " Follow " + activity.Actor.Id } _, err := db.Exec(query, activity.Actor.Id, activity.Object.Actor) @@ -181,7 +204,7 @@ func SetActorFollowerDB(db *sql.DB, activity Activity) Activity { if CheckError(err, "error with follower db insert/delete") != nil { activity.Type = "Reject" return activity - } + } activity.Type = "Accept" return activity @@ -204,7 +227,7 @@ func SetActorFollowingDB(db *sql.DB, activity Activity) Activity { if !IsActorLocal(db, activity.Actor.Id) { go DeleteActorCache(db, activity.Actor.Id) } - } else { + } else { query = `insert into following (id, following) values ($1, $2)` activity.Summary = activity.Object.Actor + " Following " + activity.Actor.Id if !IsActorLocal(db, activity.Actor.Id) { @@ -236,7 +259,7 @@ func AutoFollow(db *sql.DB, actor string) { } } - if !isFollowing && e.Id != Domain { + if !isFollowing && e.Id != Domain && e.Id != actor { followActivity := MakeFollowActivity(db, actor, e.Id) if FingerActor(e.Id).Id != "" { -- cgit v1.2.3