all repos — honk @ 3d6a33079b292791e0df393ce1b0617eb6e5b01a

my fork of honk

command line follow and unfollow
Ted Unangst tedu@tedunangst.com
Wed, 01 Mar 2023 14:48:50 -0500
commit

3d6a33079b292791e0df393ce1b0617eb6e5b01a

parent

2dc8a9e8a18ca67b02e4a2b79f05c685e8ab3a5d

5 files changed, 59 insertions(+), 10 deletions(-)

jump to
M activity.goactivity.go

@@ -1882,7 +1882,7 @@ return

} } -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 @@ if err != nil {

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 @@ if err != nil {

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) {
M database.godatabase.go

@@ -1002,9 +1002,6 @@ elog.Print(err)

return 0, err } honkerid, _ := res.LastInsertId() - if flavor == "presub" { - followyou(user, honkerid) - } return honkerid, nil }
M docs/honk.8docs/honk.8

@@ -142,6 +142,11 @@ .Pp

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
M honk.gohonk.go

@@ -373,6 +373,42 @@ fmt.Printf("usage: honk chpass username\n")

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 {
M web.goweb.go

@@ -1923,15 +1923,15 @@ }

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 {

@@ -1955,6 +1955,9 @@ id, err := savehonker(user, url, name, flavor, combos, mj)

if err != nil { 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