diff --git a/activity.go b/activity.go index 418c1cc..7e427c0 100644 --- a/activity.go +++ b/activity.go @@ -1882,7 +1882,7 @@ func unfollowme(user *WhatAbout, who string, name string, j junk.Junk) { } } -func followyou(user *WhatAbout, honkerid int64) { +func followyou(user *WhatAbout, honkerid int64, sync bool) { var url, owner string db := opendatabase() row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep', 'presub', 'sub')", @@ -1899,10 +1899,14 @@ func followyou(user *WhatAbout, honkerid int64) { elog.Printf("error updating honker: %s", err) return } - go subsub(user, url, owner, folxid) + if sync { + subsub(user, url, owner, folxid) + } else { + go subsub(user, url, owner, folxid) + } } -func unfollowyou(user *WhatAbout, honkerid int64) { +func unfollowyou(user *WhatAbout, honkerid int64, sync bool) { db := opendatabase() row := db.QueryRow("select xid, owner, folxid from honkers where honkerid = ? and userid = ? and flavor in ('sub')", honkerid, user.ID) @@ -1918,7 +1922,11 @@ func unfollowyou(user *WhatAbout, honkerid int64) { elog.Printf("error updating honker: %s", err) return } - go itakeitallback(user, url, owner, folxid) + if sync { + itakeitallback(user, url, owner, folxid) + } else { + go itakeitallback(user, url, owner, folxid) + } } func followyou2(user *WhatAbout, j junk.Junk) { diff --git a/database.go b/database.go index 40e2768..99bd8ad 100644 --- a/database.go +++ b/database.go @@ -1002,9 +1002,6 @@ func savehonker(user *WhatAbout, url, name, flavor, combos, mj string) (int64, e return 0, err } honkerid, _ := res.LastInsertId() - if flavor == "presub" { - followyou(user, honkerid) - } return honkerid, nil } diff --git a/docs/honk.8 b/docs/honk.8 index 1b045df..739617d 100644 --- a/docs/honk.8 +++ b/docs/honk.8 @@ -142,6 +142,11 @@ command. Users may be deleted with the .Ic deluser Ar username command. +.Pp +Follow and unfollow requests can be sent via command line with +.Ic follow Ar username Ar url +and +.Ic unfollow Ar username Ar url . .Ss Maintenance The database may grow large over time. The diff --git a/honk.go b/honk.go index 1898085..d8cce9b 100644 --- a/honk.go +++ b/honk.go @@ -373,6 +373,42 @@ func main() { return } chpass(args[1]) + case "follow": + if len(args) < 3 { + fmt.Printf("usage: honk follow username url\n") + return + } + user, err := butwhatabout(args[1]) + if err != nil { + fmt.Printf("user not found") + return + } + var meta HonkerMeta + mj, _ := jsonify(&meta) + honkerid, err := savehonker(user, args[2], "", "presub", "", mj) + if err != nil { + fmt.Printf("had some trouble with that: %s", err) + return + } + followyou(user, honkerid, true) + case "unfollow": + if len(args) < 3 { + fmt.Printf("usage: honk unfollow username url\n") + return + } + user, err := butwhatabout(args[1]) + if err != nil { + fmt.Printf("user not found") + return + } + row := db.QueryRow("select honkerid from honkers where xid = ? and userid = ?", args[2], user.ID) + var honkerid int64 + err = row.Scan(&honkerid) + if err != nil { + fmt.Printf("sorry couldn't find them") + return + } + unfollowyou(user, honkerid, true) case "cleanup": arg := "30" if len(args) > 1 { diff --git a/web.go b/web.go index 42de0e0..274559f 100644 --- a/web.go +++ b/web.go @@ -1923,15 +1923,15 @@ func submithonker(w http.ResponseWriter, r *http.Request) *Honker { if honkerid > 0 { if r.FormValue("delete") == "delete" { - unfollowyou(user, honkerid) + unfollowyou(user, honkerid, false) stmtDeleteHonker.Exec(honkerid) return h } if r.FormValue("unsub") == "unsub" { - unfollowyou(user, honkerid) + unfollowyou(user, honkerid, false) } if r.FormValue("sub") == "sub" { - followyou(user, honkerid) + followyou(user, honkerid, false) } _, err := stmtUpdateHonker.Exec(name, combos, mj, honkerid, u.UserID) if err != nil { @@ -1956,6 +1956,9 @@ func submithonker(w http.ResponseWriter, r *http.Request) *Honker { http.Error(w, "had some trouble with that: "+err.Error(), http.StatusInternalServerError) return nil } + if flavor == "presub" { + followyou(user, honkerid, false) + } h.ID = id return h }