From 34f2844ffe7951c271b0e70b3ab0393f917e5036 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 19 Aug 2019 00:01:00 -0400 Subject: [PATCH] allow deacking a post as well --- honk.go | 19 ++++++++++++++----- views/honk.html | 4 ++++ views/honkpage.html | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/honk.go b/honk.go index ae38792..44210aa 100644 --- a/honk.go +++ b/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 @@ func showhonk(w http.ResponseWriter, r *http.Request) { 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 @@ func showhonk(w http.ResponseWriter, r *http.Request) { } 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 @@ func zonkit(w http.ResponseWriter, r *http.Request) { 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.St 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 @@ func prepareStatements(db *sql.DB) { 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() { diff --git a/views/honk.html b/views/honk.html index 3267123..56ebdb7 100644 --- a/views/honk.html +++ b/views/honk.html @@ -78,7 +78,11 @@ in reply to: {{ .RID }} +{{ if .Honk.IsAcked }} + +{{ else }} +{{ end }}

diff --git a/views/honkpage.html b/views/honkpage.html index 6a61300..38781e5 100644 --- a/views/honkpage.html +++ b/views/honkpage.html @@ -65,5 +65,10 @@ function ackit(el, xid) { 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)) +} {{ end }}