all repos — honk @ 22409ad9a9390dd542e97944a0760261640d37d6

my fork of honk

add combos for the micromanagement of friends
Ted Unangst tedu@tedunangst.com
Mon, 22 Apr 2019 17:03:55 -0400
commit

22409ad9a9390dd542e97944a0760261640d37d6

parent

d3309c6c285cfe98f89fea2673a525cdbd440ec4

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

jump to
M honk.gohonk.go

@@ -33,6 +33,7 @@ notrand "math/rand"

"net/http" "os" "sort" + "strconv" "strings" "sync" "time"

@@ -86,6 +87,7 @@ UserID int64

Name string XID string Flavor string + Combos []string } var serverName string

@@ -423,6 +425,13 @@ honks := gethonksbyhonker(u.UserID, name)

honkpage(w, r, nil, nil, honks) } +func viewcombo(w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + u := GetUserInfo(r) + honks := gethonksbycombo(u.UserID, name) + honkpage(w, r, nil, nil, honks) +} + func fingerlicker(w http.ResponseWriter, r *http.Request) { orig := r.FormValue("resource")

@@ -542,7 +551,9 @@ defer rows.Close()

var honkers []*Honker for rows.Next() { var f Honker - err = rows.Scan(&f.ID, &f.UserID, &f.Name, &f.XID, &f.Flavor) + var combos string + err = rows.Scan(&f.ID, &f.UserID, &f.Name, &f.XID, &f.Flavor, &combos) + f.Combos = strings.Split(strings.TrimSpace(combos), " ") if err != nil { log.Printf("error scanning honker: %s", err) return nil

@@ -616,6 +627,11 @@ func gethonksbyhonker(userid int64, honker string) []*Honk {

rows, err := stmtHonksByHonker.Query(userid, honker) return getsomehonks(rows, err) } +func gethonksbycombo(userid int64, combo string) []*Honk { + combo = "% " + combo + " %" + rows, err := stmtHonksByCombo.Query(userid, combo) + return getsomehonks(rows, err) +} func getsomehonks(rows *sql.Rows, err error) []*Honk { if err != nil {

@@ -874,7 +890,7 @@

http.Redirect(w, r, "/", http.StatusSeeOther) } -func showhonkers(w http.ResponseWriter, r *http.Request) { +func viewhonkers(w http.ResponseWriter, r *http.Request) { userinfo := GetUserInfo(r) templinfo := getInfo(r) templinfo["Honkers"] = gethonkers(userinfo.UserID)

@@ -926,14 +942,27 @@ return ""

} func savehonker(w http.ResponseWriter, r *http.Request) { + u := GetUserInfo(r) name := r.FormValue("name") url := r.FormValue("url") peep := r.FormValue("peep") + combos := r.FormValue("combos") + honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0) + + if honkerid > 0 { + combos = " " + strings.TrimSpace(combos) + " " + _, err := stmtUpdateHonker.Exec(combos, honkerid, u.UserID) + if err != nil { + log.Printf("update honker err: %s", err) + return + } + http.Redirect(w, r, "/honkers", http.StatusSeeOther) + } + flavor := "presub" if peep == "peep" { flavor = "peep" } - if url == "" { return }

@@ -943,13 +972,10 @@ }

if url == "" { return } - - u := GetUserInfo(r) - db := opendatabase() - _, err := db.Exec("insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)", - u.UserID, name, url, flavor) + _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) if err != nil { log.Print(err) + return } if flavor == "presub" { user, _ := butwhatabout(u.Username)

@@ -1115,8 +1141,9 @@ loggedin.Handle("/bonk", CSRFWrap("honkhonk", http.HandlerFunc(savebonk)))

loggedin.Handle("/zonkit", CSRFWrap("honkhonk", http.HandlerFunc(zonkit))) loggedin.Handle("/killitwithfire", CSRFWrap("killitwithfire", http.HandlerFunc(killitwithfire))) loggedin.Handle("/saveuser", CSRFWrap("saveuser", http.HandlerFunc(saveuser))) - loggedin.HandleFunc("/honkers", showhonkers) + loggedin.HandleFunc("/honkers", viewhonkers) loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker) + loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", viewcombo) loggedin.Handle("/savehonker", CSRFWrap("savehonker", http.HandlerFunc(savehonker))) err = http.Serve(listener, mux)

@@ -1125,7 +1152,8 @@ log.Fatal(err)

} } -var stmtHonkers, stmtDubbers, stmtOneXonk, stmtHonks, stmtUserHonks *sql.Stmt +var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateHonker *sql.Stmt +var stmtOneXonk, stmtHonks, stmtUserHonks, stmtHonksByCombo *sql.Stmt var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt

@@ -1141,7 +1169,9 @@ return stmt

} func prepareStatements(db *sql.DB) { - stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'sub' or flavor = 'peep'") + stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos from honkers where userid = ? and flavor = 'sub' or flavor = 'peep'") + stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos) values (?, ?, ?, ?, ?)") + stmtUpdateHonker = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'") stmtOneXonk = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where xid = ?") stmtHonks = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honker = '' order by honkid desc limit 50")

@@ -1149,6 +1179,7 @@ stmtUserHonks = preparetodie(db, "select honkid, honks.userid, username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honker = '' and username = ? order by honkid desc limit 50")

stmtHonksForUser = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honks.userid = ? and dt > ? and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100) order by honkid desc limit 250") stmtHonksForMe = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honks.userid = ? and dt > ? and whofore = 1 and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100) order by honkid desc limit 250") stmtHonksByHonker = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ? order by honkid desc limit 50") + stmtHonksByCombo = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.combos like ? order by honkid desc limit 50") stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtFileData = preparetodie(db, "select media, content from files where xid = ?") stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
M schema.sqlschema.sql

@@ -2,7 +2,7 @@

create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer); create table donks (honkid integer, fileid integer); create table files(fileid integer primary key, xid text, name text, url text, media text, content blob); -create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, pubkey text); +create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, pubkey text); create table xonkers (xonkerid integer primary key, xid text, ibox text, obox text, sbox text, pubkey text); create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text); create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob);
M upgradedb.goupgradedb.go

@@ -60,6 +60,11 @@ doordie(db, "update honks set whofore = 1 where honkid in (select honkid from honks join users on honks.userid = users.userid where instr(audience, username) > 0)")

doordie(db, "update config set value = 4 where key = 'dbversion'") fallthrough case 4: + doordie(db, "alter table honkers add column combos text") + doordie(db, "update honkers set combos = ''") + doordie(db, "update config set value = 5 where key = 'dbversion'") + fallthrough + case 5: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -70,7 +70,7 @@

var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 4 +var myVersion = 5 func initdb() { schema, err := ioutil.ReadFile("schema.sql")
M views/honkers.htmlviews/honkers.html

@@ -12,14 +12,19 @@ <input tabindex=1 type="checkbox" id="peep" name="peep" value="peep"><span></span></span>

<p><input tabindex=1 type="submit" name="add honker" value="add honker"> </form> </div> +{{ $honkercsrf := .HonkerCSRF }} {{ range .Honkers }} -<div class="honk" id="honker{{ .ID }}"> -<p> -<span class="linktitle">{{ .Name }}</span> +<form action="/savehonker" method="POST" class="honk"> +<input type="hidden" name="CSRF" value="{{ $honkercsrf }}"> +<input type="hidden" name="honkerid" value="{{ .ID }}"> +<p>name: {{ .Name }} <p>url: {{ .XID }} +<p>flavor: {{ .Flavor }} <p><a href="/h/{{ .Name }}">honks</a> -<p>flavor: {{ .Flavor }} -</div> +<p>combos:{{ range .Combos }} <a href="/c/{{ . }}">{{ . }}</a>{{ end }} +<p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}"> +<p><input type="submit" name="save" value="save"> +</form> {{ end }} </div> </div>