allow acking a honk
Ted Unangst tedu@tedunangst.com
Fri, 16 Aug 2019 15:35:12 -0400
3 files changed,
31 insertions(+),
4 deletions(-)
M
honk.go
→
honk.go
@@ -78,6 +78,14 @@ Open string
Donks []*Donk } +const ( + flagIsAcked = 1 +) + +func honkIsAcked(flags int64) bool { + return flags&flagIsAcked != 0 +} + type Donk struct { FileID int64 XID string@@ -635,7 +643,14 @@ w.Header().Set("Content-Type", theonetruename)
j.Write(w) return } - honks := gethonksbyconvoy(-1, h.Convoy) + rawhonks := gethonksbyconvoy(h.UserID, h.Convoy) + var honks []*Honk + for _, h := range rawhonks { + if h.Public && (h.Whofore == 2 || honkIsAcked(h.Flags)) { + honks = append(honks, h) + } + } + honkpage(w, r, u, nil, honks, "one honk maybe more") }@@ -912,9 +927,13 @@
func zonkit(w http.ResponseWriter, r *http.Request) { wherefore := r.FormValue("wherefore") what := r.FormValue("what") - switch wherefore { - case "zonk": - case "zonvoy": + + if wherefore == "ack" { + _, err := stmtUpdateFlags.Exec(flagIsAcked, what) + if err != nil { + log.Printf("error acking: %s", err) + } + return } log.Printf("zonking %s %s", wherefore, what)@@ -1586,6 +1605,7 @@ var stmtFindZonk, stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt +var stmtUpdateFlags *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)@@ -1638,6 +1658,7 @@ stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?")
stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)") stmtDeleteXonker = preparetodie(db, "delete from xonkers where name = ? and flavor = ?") stmtRecentHonkers = preparetodie(db, "select distinct(honker) from honks where userid = ? and honker not in (select xid from honkers where userid = ? and flavor = 'sub') order by honkid desc limit 100") + stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where xid = ?") } func ElaborateUnitTests() {
M
views/honk.html
→
views/honk.html
@@ -78,6 +78,7 @@ {{ end }}
<button onclick="showhonkform(this, '{{ .Honk.XID }}', '{{ .Honk.Handle }}');">honk back</button> <button onclick="muteit(this, '{{ .Honk.Convoy }}');">mute</button> <button onclick="zonkit(this, '{{ .Honk.XID }}');">zonk</button> +<button onclick="ackit(this, '{{ .Honk.XID }}');">ack</button> </div> </details> <p>
M
views/honkpage.html
→
views/honkpage.html
@@ -60,5 +60,10 @@ if (p) {
p.remove() } } +function ackit(el, xid) { + el.innerHTML = "acked" + el.disabled = true + post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid)) +} </script> {{ end }}