diff --git a/activity.go b/activity.go index 3a718c4..4783a0b 100644 --- a/activity.go +++ b/activity.go @@ -233,8 +233,8 @@ func needxonk(user *WhatAbout, x *Honk) bool { if x.What == "eradicate" { return true } - if thoudostbitethythumb(user.ID, x.Honker, x.XID) { - log.Printf("not saving thumb biter %s\n", x.Honker) + if thoudostbitethythumb(user.ID, x.Audience, x.XID) { + log.Printf("not saving thumb biter? %s", x.Honker) return false } return needxonkid(user, x.XID) diff --git a/fun.go b/fun.go index ff0de17..bfad2a7 100644 --- a/fun.go +++ b/fun.go @@ -324,17 +324,51 @@ func makeitworksomehowwithoutregardforkeycontinuity(keyname string, r *http.Requ return zag(r, payload) } -func thoudostbitethythumb(userid int64, who string, objid string) bool { - where := "" - m := re_unurl.FindStringSubmatch(who) - if len(m) > 2 { - where = m[1] +var thumbbiters map[int64]map[string]bool +var thumblock sync.Mutex + +func bitethethumbs() { + rows, err := stmtThumbBiters.Query() + if err != nil { + log.Printf("error getting thumbbiters: %s", err) + return } - row := stmtThumbBiter.QueryRow(who, where, userid) - var id int64 - err := row.Scan(&id) - if err == nil { - return true + defer rows.Close() + thumblock.Lock() + defer thumblock.Unlock() + thumbbiters = make(map[int64]map[string]bool) + for rows.Next() { + var userid int64 + var name, wherefore string + err = rows.Scan(&userid, &name, &wherefore) + if err != nil { + log.Printf("error scanning zonker: %s", err) + continue + } + m := thumbbiters[userid] + if m == nil { + m = make(map[string]bool) + thumbbiters[userid] = m + } + m[name] = true + } +} + +func thoudostbitethythumb(userid int64, who []string, objid string) bool { + thumblock.Lock() + biters := thumbbiters[userid] + thumblock.Unlock() + for _, w := range who { + if biters[w] { + return true + } + m := re_unurl.FindStringSubmatch(w) + if len(m) > 2 { + where := m[1] + if biters[where] { + return true + } + } } return false } diff --git a/honk.go b/honk.go index 091a8bd..5110dfc 100644 --- a/honk.go +++ b/honk.go @@ -321,7 +321,7 @@ func inbox(w http.ResponseWriter, r *http.Request) { return } objid, _ := jsongetstring(j, "id") - if thoudostbitethythumb(user.ID, who, objid) { + if thoudostbitethythumb(user.ID, []string{who}, objid) { log.Printf("ignoring thumb sucker %s", who) return } @@ -1052,6 +1052,7 @@ func savehonker(w http.ResponseWriter, r *http.Request) { } type Zonker struct { + ID int64 Name string Wherefore string } @@ -1059,7 +1060,7 @@ type Zonker struct { func killzone(w http.ResponseWriter, r *http.Request) { db := opendatabase() userinfo := login.GetUserInfo(r) - rows, err := db.Query("select name, wherefore from zonkers where userid = ?", userinfo.UserID) + rows, err := db.Query("select zonkerid, name, wherefore from zonkers where userid = ?", userinfo.UserID) if err != nil { log.Printf("err: %s", err) return @@ -1067,7 +1068,7 @@ func killzone(w http.ResponseWriter, r *http.Request) { var zonkers []Zonker for rows.Next() { var z Zonker - rows.Scan(&z.Name, &z.Wherefore) + rows.Scan(&z.ID, &z.Name, &z.Wherefore) zonkers = append(zonkers, z) } templinfo := getInfo(r) @@ -1081,6 +1082,16 @@ func killzone(w http.ResponseWriter, r *http.Request) { func killitwithfire(w http.ResponseWriter, r *http.Request) { userinfo := login.GetUserInfo(r) + itsok := r.FormValue("itsok") + if itsok == "iforgiveyou" { + zonkerid, _ := strconv.ParseInt(r.FormValue("zonkerid"), 10, 0) + db := opendatabase() + db.Exec("delete from zonkers where userid = ? and zonkerid = ?", + userinfo.UserID, zonkerid) + bitethethumbs() + http.Redirect(w, r, "/killzone", http.StatusSeeOther) + return + } wherefore := r.FormValue("wherefore") name := r.FormValue("name") if name == "" { @@ -1095,7 +1106,10 @@ func killitwithfire(w http.ResponseWriter, r *http.Request) { } db := opendatabase() db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", - userinfo.UserID, name, wherefore) + userinfo.UserID, name, wherefore) + if wherefore == "zonker" || wherefore == "zurl" { + bitethethumbs() + } http.Redirect(w, r, "/killzone", http.StatusSeeOther) } @@ -1174,6 +1188,8 @@ func serve() { savedstyleparams[s] = getstyleparam(s) } + bitethethumbs() + mux := mux.NewRouter() mux.Use(login.Checker) @@ -1227,7 +1243,7 @@ var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt -var stmtHasHonker, stmtThumbBiter, stmtZonkIt *sql.Stmt +var stmtHasHonker, stmtThumbBiters, stmtZonkIt *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s) @@ -1269,7 +1285,7 @@ func prepareStatements(db *sql.DB) { stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?") stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?") stmtZonkIt = preparetodie(db, "update honks set what = 'zonk' where userid = ? and xid = ?") - stmtThumbBiter = preparetodie(db, "select zonkerid from zonkers where ((name = ? and wherefore = 'zonker') or (name = ? and wherefore = 'zurl')) and userid = ?") + stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zurl')") } func ElaborateUnitTests() { diff --git a/views/zonkers.html b/views/zonkers.html index 2c20f8a..9a87035 100644 --- a/views/zonkers.html +++ b/views/zonkers.html @@ -19,10 +19,18 @@

+{{ $killcsrf := .KillCSRF }} {{ range .Zonkers }} -

+

What: {{ .Name }}

Where: {{ .Wherefore }} +

+ + + + +
+

{{ end }}