allow deacking a post as well
Ted Unangst tedu@tedunangst.com
Mon, 19 Aug 2019 00:01:00 -0400
3 files changed,
23 insertions(+),
5 deletions(-)
M
honk.go
→
honk.go
@@ -83,8 +83,8 @@ const (
flagIsAcked = 1 ) -func honkIsAcked(flags int64) bool { - return flags&flagIsAcked != 0 +func (honk *Honk) IsAcked() bool { + return honk.Flags&flagIsAcked != 0 } type Donk struct {@@ -639,7 +639,7 @@ }
rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) if friendorfoe(r.Header.Get("Accept")) { for _, h := range rawhonks { - if h.RID == honk.XID && h.Public && (h.Whofore == 2 || honkIsAcked(h.Flags)) { + if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) { honk.Replies = append(honk.Replies, h) } }@@ -652,7 +652,7 @@ return
} var honks []*Honk for _, h := range rawhonks { - if h.Public && (h.Whofore == 2 || honkIsAcked(h.Flags)) { + if h.Public && (h.Whofore == 2 || h.IsAcked()) { honks = append(honks, h) } }@@ -942,6 +942,14 @@ }
return } + if wherefore == "deack" { + _, err := stmtClearFlags.Exec(flagIsAcked, what) + if err != nil { + log.Printf("error deacking: %s", err) + } + return + } + log.Printf("zonking %s %s", wherefore, what) userinfo := login.GetUserInfo(r) if wherefore == "zonk" {@@ -1611,7 +1619,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 +var stmtUpdateFlags, stmtClearFlags *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)@@ -1665,6 +1673,7 @@ 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 = ?") + stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where xid = ?") } func ElaborateUnitTests() {
M
views/honk.html
→
views/honk.html
@@ -78,7 +78,11 @@ {{ 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> +{{ if .Honk.IsAcked }} +<button onclick="deackit(this, '{{ .Honk.XID }}');">deack</button> +{{ else }} <button onclick="ackit(this, '{{ .Honk.XID }}');">ack</button> +{{ end }} </div> </details> <p>
M
views/honkpage.html
→
views/honkpage.html
@@ -65,5 +65,10 @@ el.innerHTML = "acked"
el.disabled = true post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid)) } +function deackit(el, xid) { + el.innerHTML = "deacked" + el.disabled = true + post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid)) +} </script> {{ end }}