diff options
-rw-r--r-- | follow.go | 43 | ||||
-rw-r--r-- | main.go | 17 | ||||
-rw-r--r-- | outboxPost.go | 4 |
3 files changed, 43 insertions, 21 deletions
@@ -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 @@ -162,18 +166,37 @@ 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 != "" { @@ -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) |