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 +++++++++++++++++++++++++++++++++---------- main.go | 17 ++++++++--------- outboxPost.go | 4 ++-- 3 files changed, 43 insertions(+), 21 deletions(-) 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 != "" { diff --git a/main.go b/main.go index 2d2831b..3959dae 100644 --- a/main.go +++ b/main.go @@ -528,18 +528,17 @@ func main() { return } - if FingerActor(follow).Id != "" { - MakeActivityRequestOutbox(db, followActivity) + if FingerActor(follow).Id != ""{ + MakeActivityRequestOutbox(db, followActivity) } - } - var redirect string - if(actor.Name != "main") { - redirect = "/" + actor.Name + var redirect string + if(actor.Name != "main") { + redirect = "/" + actor.Name + } + + http.Redirect(w, r, "/" + *Key + "/" + redirect, http.StatusSeeOther) } - - http.Redirect(w, r, "/" + *Key + "/" + redirect, http.StatusSeeOther) - } else if manage && actor.Name != "" { t := template.Must(template.New("").Funcs(template.FuncMap{ "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/manage.html")) diff --git a/outboxPost.go b/outboxPost.go index 88c85e1..356647e 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -515,7 +515,7 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { nActor := FingerActor(activity.Actor.Id) activity.Actor = &nActor } - + if !VerifyHeaderSignature(r, *activity.Actor) { response := RejectActivity(activity) MakeActivityRequest(db, response) @@ -564,7 +564,7 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { if e.Id == activity.Actor.Id { alreadyFollow = true } - } + } if autoSub && !alreadyFollow { followActivity := MakeFollowActivity(db, response.Actor.Id, response.Object.Actor) -- cgit v1.2.3