all repos — honk @ 27931774809051fb985782e0271da58e3911c851

my fork of honk

allow saving honks for later
Ted Unangst tedu@tedunangst.com
Fri, 11 Oct 2019 16:03:17 -0400
commit

27931774809051fb985782e0271da58e3911c851

parent

ed28d731aad0057cfa6431f6ca57816f2687305c

6 files changed, 62 insertions(+), 15 deletions(-)

jump to
M database.godatabase.go

@@ -171,6 +171,10 @@ dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)

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 @@ var where 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, stmtSaveZonker *sql.Stmt

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 @@ myhonkers := " and honker in (select xid from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'presub') and combos not like '% - %')"

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)
M honk.gohonk.go

@@ -74,6 +74,7 @@

const ( flagIsAcked = 1 flagIsBonked = 2 + flagIsSaved = 4 ) func (honk *Honk) IsAcked() bool {

@@ -82,6 +83,10 @@ }

func (honk *Honk) IsBonked() bool { return honk.Flags&flagIsBonked != 0 +} + +func (honk *Honk) IsSaved() bool { + return honk.Flags&flagIsSaved != 0 } type Donk struct {
M views/header.htmlviews/header.html

@@ -33,11 +33,11 @@ </ul>

</details> <li><a href="/o">tags</a> <li><a href="/events">events</a> +<li><a id="savedlink" href="/saved">saved</a> <li><a href="/honkers">honkers</a> <li><a href="/hfcs">hfcs</a> <li><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">my honks</a> <li><a href="/xzone">xzone</a> -<li><a href="/funzone">funzone</a> <li><a href="/account">account</a> <li style="list-style-type:none; margin-left:-1em"> <details>

@@ -45,6 +45,7 @@ <summary>more stuff</summary>

<ul> <li><a href="/about">about</a> <li><a href="/front">front</a> +<li><a href="/funzone">funzone</a> </ul> </details> <li><a href="/help/honk.1.html">help</a>
M views/honk.htmlviews/honk.html

@@ -102,9 +102,14 @@ <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> +<button onclick="flogit(this, 'deack', '{{ .Honk.XID }}');">deack</button> +{{ else }} +<button onclick="flogit(this, 'ack', '{{ .Honk.XID }}');">ack</button> +{{ end }} +{{ if .Honk.IsSaved }} +<button onclick="flogit(this, 'unsave', '{{ .Honk.XID }}');">unsave</button> {{ else }} -<button onclick="ackit(this, '{{ .Honk.XID }}');">ack</button> +<button onclick="flogit(this, 'save', '{{ .Honk.XID }}');">save</button> {{ end }} <button><a href="/edit?xid={{ .Honk.XID }}">edit</a></button> </div>
M views/honkpage.jsviews/honkpage.js

@@ -53,15 +53,13 @@ if (p) {

p.remove() } } -function ackit(el, xid) { - el.innerHTML = "acked" - el.disabled = true - post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "ack", "what": xid})) -} -function deackit(el, xid) { - el.innerHTML = "deacked" +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": "deack", "what": xid})) + post("/zonkit", encode({"CSRF": csrftoken, "wherefore": how, "what": xid})) } function fillinhonks(xhr) { var doc = xhr.responseXML

@@ -213,6 +211,8 @@ el = document.getElementById("atmelink")

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", "")
M web.goweb.go

@@ -109,6 +109,10 @@ case "/first":

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 @@ what := r.FormValue("what")

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 @@ case "first":

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 @@

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)