From ba8270e97ceb7702ef1facde6f8452ae3005e806 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 11 Oct 2019 16:03:17 -0400 Subject: [PATCH] allow saving honks for later --- database.go | 13 +++++++++---- honk.go | 5 +++++ views/header.html | 3 ++- views/honk.html | 9 +++++++-- views/honkpage.js | 16 ++++++++-------- web.go | 31 +++++++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 15 deletions(-) diff --git a/database.go b/database.go index 035a2ec..708df2a 100644 --- a/database.go +++ b/database.go @@ -171,6 +171,10 @@ func gethonksforme(userid int64) []*Honk { rows, err := stmtHonksForMe.Query(userid, dt, userid) return getsomehonks(rows, err) } +func getsavedhonks(userid int64) []*Honk { + rows, err := stmtHonksISaved.Query(userid) + return getsomehonks(rows, err) +} func gethonksbyhonker(userid int64, honker string) []*Honk { rows, err := stmtHonksByHonker.Query(userid, honker, userid) return getsomehonks(rows, err) @@ -537,15 +541,15 @@ func cleanupdb(arg string) { if err != nil { honker := arg expdate := time.Now().UTC().Add(-3 * 24 * time.Hour).Format(dbtimeformat) - where = "dt < ? and whofore = 0 and honker = ?" + where = "dt < ? and honker = ?" sqlargs = append(sqlargs, expdate) sqlargs = append(sqlargs, honker) } else { expdate := time.Now().UTC().Add(-time.Duration(days) * 24 * time.Hour).Format(dbtimeformat) - where = "dt < ? and whofore = 0 and convoy not in (select convoy from honks where whofore = 2 or whofore = 3)" + where = "dt < ? and convoy not in (select convoy from honks where flags & 4 or whofore = 2 or whofore = 3)" sqlargs = append(sqlargs, expdate) } - doordie(db, "delete from honks where "+where, sqlargs...) + doordie(db, "delete from honks where flags & 4 = 0 and whofore = 0 and "+where, sqlargs...) doordie(db, "delete from donks where honkid not in (select honkid from honks)") doordie(db, "delete from onts where honkid not in (select honkid from honks)") doordie(db, "delete from honkmeta where honkid not in (select honkid from honks)") @@ -607,7 +611,7 @@ var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZo var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtHonksForUserFirstClass, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *sql.Stmt -var stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt +var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s) @@ -638,6 +642,7 @@ func prepareStatements(db *sql.DB) { stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ?"+myhonkers+butnotthose+limit) stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and (what <> 'tonk')"+myhonkers+butnotthose+limit) stmtHonksForMe = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and whofore = 1"+butnotthose+limit) + stmtHonksISaved = preparetodie(db, selecthonks+"where honks.userid = ? and flags & 4") stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on (honkers.xid = honks.honker or honkers.xid = honks.oonker) where honks.userid = ? and honkers.name = ?"+butnotthose+limit) stmtHonksByXonker = preparetodie(db, selecthonks+" where honks.userid = ? and (honker = ? or oonker = ?)"+butnotthose+limit) stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.combos like ?"+butnotthose+limit) diff --git a/honk.go b/honk.go index ad9824d..b8e335a 100644 --- a/honk.go +++ b/honk.go @@ -74,6 +74,7 @@ type OldRevision struct { const ( flagIsAcked = 1 flagIsBonked = 2 + flagIsSaved = 4 ) func (honk *Honk) IsAcked() bool { @@ -84,6 +85,10 @@ func (honk *Honk) IsBonked() bool { return honk.Flags&flagIsBonked != 0 } +func (honk *Honk) IsSaved() bool { + return honk.Flags&flagIsSaved != 0 +} + type Donk struct { FileID int64 XID string diff --git a/views/header.html b/views/header.html index 6bf64b0..0260e9d 100644 --- a/views/header.html +++ b/views/header.html @@ -33,11 +33,11 @@
  • tags
  • events +
  • saved
  • honkers
  • hfcs
  • my honks
  • xzone -
  • funzone
  • account
  • @@ -45,6 +45,7 @@
  • help diff --git a/views/honk.html b/views/honk.html index 1da714e..e745f2d 100644 --- a/views/honk.html +++ b/views/honk.html @@ -102,9 +102,14 @@ in reply to: {{ .RID }} {{ if .Honk.IsAcked }} - + {{ else }} - + +{{ end }} +{{ if .Honk.IsSaved }} + +{{ else }} + {{ end }} diff --git a/views/honkpage.js b/views/honkpage.js index eb05e3b..91a9217 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -53,15 +53,13 @@ function zonkit(el, xid) { p.remove() } } -function ackit(el, xid) { - el.innerHTML = "acked" +function flogit(el, how, xid) { + var s = how + if (s[s.length-1] != "e") { s += "e" } + s += "d" + el.innerHTML = s el.disabled = true - post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "ack", "what": xid})) -} -function deackit(el, xid) { - el.innerHTML = "deacked" - el.disabled = true - post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "deack", "what": xid})) + post("/zonkit", encode({"CSRF": csrftoken, "wherefore": how, "what": xid})) } function fillinhonks(xhr) { var doc = xhr.responseXML @@ -213,6 +211,8 @@ function relinklinks() { el.onclick = pageswitcher("atme", "") el = document.getElementById("firstlink") el.onclick = pageswitcher("first", "") + el = document.getElementById("savedlink") + el.onclick = pageswitcher("saved", "") relinklinks() window.onpopstate = statechanger history.replaceState(curpagestate, "some title", "") diff --git a/web.go b/web.go index 66bb89e..6095307 100644 --- a/web.go +++ b/web.go @@ -109,6 +109,10 @@ func homepage(w http.ResponseWriter, r *http.Request) { templinfo["PageName"] = "first" honks = gethonksforuser(userid) honks = osmosis(honks, userid) + case "/saved": + templinfo["ServerMessage"] = "saved honks" + templinfo["PageName"] = "saved" + honks = getsavedhonks(userid) default: templinfo["PageName"] = "home" honks = gethonksforuser(userid) @@ -852,6 +856,28 @@ func zonkit(w http.ResponseWriter, r *http.Request) { userinfo := login.GetUserInfo(r) user, _ := butwhatabout(userinfo.Username) + if wherefore == "save" { + xonk := getxonk(userinfo.UserID, what) + if xonk != nil { + _, err := stmtUpdateFlags.Exec(flagIsSaved, xonk.ID) + if err != nil { + log.Printf("error saving: %s", err) + } + } + return + } + + if wherefore == "unsave" { + xonk := getxonk(userinfo.UserID, what) + if xonk != nil { + _, err := stmtClearFlags.Exec(flagIsSaved, xonk.ID) + if err != nil { + log.Printf("error unsaving: %s", err) + } + } + return + } + // my hammer is too big, oh well defer oldjonks.Flush() @@ -1572,6 +1598,10 @@ func webhydra(w http.ResponseWriter, r *http.Request) { honks = gethonksforuserfirstclass(userid) honks = osmosis(honks, userid) templinfo["ServerMessage"] = "first class only" + case "saved": + honks = getsavedhonks(userid) + templinfo["PageName"] = "saved" + templinfo["ServerMessage"] = "saved honks" case "combo": c := r.FormValue("c") honks = gethonksbycombo(userid, c) @@ -1689,6 +1719,7 @@ func serve() { loggedin := mux.NewRoute().Subrouter() loggedin.Use(login.Required) loggedin.HandleFunc("/first", homepage) + loggedin.HandleFunc("/saved", homepage) loggedin.HandleFunc("/account", accountpage) loggedin.HandleFunc("/funzone", showfunzone) loggedin.HandleFunc("/chpass", dochpass)