allow saving honks for later

This commit is contained in:
Ted Unangst 2019-10-11 16:03:17 -04:00
parent ed02a0dd72
commit ba8270e97c
6 changed files with 62 additions and 15 deletions

View File

@ -171,6 +171,10 @@ func gethonksforme(userid int64) []*Honk {
rows, err := stmtHonksForMe.Query(userid, dt, userid) rows, err := stmtHonksForMe.Query(userid, dt, userid)
return getsomehonks(rows, err) 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 { func gethonksbyhonker(userid int64, honker string) []*Honk {
rows, err := stmtHonksByHonker.Query(userid, honker, userid) rows, err := stmtHonksByHonker.Query(userid, honker, userid)
return getsomehonks(rows, err) return getsomehonks(rows, err)
@ -537,15 +541,15 @@ func cleanupdb(arg string) {
if err != nil { if err != nil {
honker := arg honker := arg
expdate := time.Now().UTC().Add(-3 * 24 * time.Hour).Format(dbtimeformat) 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, expdate)
sqlargs = append(sqlargs, honker) sqlargs = append(sqlargs, honker)
} else { } else {
expdate := time.Now().UTC().Add(-time.Duration(days) * 24 * time.Hour).Format(dbtimeformat) 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) 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 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 onts where honkid not in (select honkid from honks)")
doordie(db, "delete from honkmeta 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 stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt
var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt
var stmtHonksForUserFirstClass, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *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 { func preparetodie(db *sql.DB, s string) *sql.Stmt {
stmt, err := db.Prepare(s) 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) 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) 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) 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) 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) 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) stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.combos like ?"+butnotthose+limit)

View File

@ -74,6 +74,7 @@ type OldRevision struct {
const ( const (
flagIsAcked = 1 flagIsAcked = 1
flagIsBonked = 2 flagIsBonked = 2
flagIsSaved = 4
) )
func (honk *Honk) IsAcked() bool { func (honk *Honk) IsAcked() bool {
@ -84,6 +85,10 @@ func (honk *Honk) IsBonked() bool {
return honk.Flags&flagIsBonked != 0 return honk.Flags&flagIsBonked != 0
} }
func (honk *Honk) IsSaved() bool {
return honk.Flags&flagIsSaved != 0
}
type Donk struct { type Donk struct {
FileID int64 FileID int64
XID string XID string

View File

@ -33,11 +33,11 @@
</details> </details>
<li><a href="/o">tags</a> <li><a href="/o">tags</a>
<li><a href="/events">events</a> <li><a href="/events">events</a>
<li><a id="savedlink" href="/saved">saved</a>
<li><a href="/honkers">honkers</a> <li><a href="/honkers">honkers</a>
<li><a href="/hfcs">hfcs</a> <li><a href="/hfcs">hfcs</a>
<li><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">my honks</a> <li><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">my honks</a>
<li><a href="/xzone">xzone</a> <li><a href="/xzone">xzone</a>
<li><a href="/funzone">funzone</a>
<li><a href="/account">account</a> <li><a href="/account">account</a>
<li style="list-style-type:none; margin-left:-1em"> <li style="list-style-type:none; margin-left:-1em">
<details> <details>
@ -45,6 +45,7 @@
<ul> <ul>
<li><a href="/about">about</a> <li><a href="/about">about</a>
<li><a href="/front">front</a> <li><a href="/front">front</a>
<li><a href="/funzone">funzone</a>
</ul> </ul>
</details> </details>
<li><a href="/help/honk.1.html">help</a> <li><a href="/help/honk.1.html">help</a>

View File

@ -102,9 +102,14 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
<button onclick="muteit(this, '{{ .Honk.Convoy }}');">mute</button> <button onclick="muteit(this, '{{ .Honk.Convoy }}');">mute</button>
<button onclick="zonkit(this, '{{ .Honk.XID }}');">zonk</button> <button onclick="zonkit(this, '{{ .Honk.XID }}');">zonk</button>
{{ if .Honk.IsAcked }} {{ if .Honk.IsAcked }}
<button onclick="deackit(this, '{{ .Honk.XID }}');">deack</button> <button onclick="flogit(this, 'deack', '{{ .Honk.XID }}');">deack</button>
{{ else }} {{ else }}
<button onclick="ackit(this, '{{ .Honk.XID }}');">ack</button> <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="flogit(this, 'save', '{{ .Honk.XID }}');">save</button>
{{ end }} {{ end }}
<button><a href="/edit?xid={{ .Honk.XID }}">edit</a></button> <button><a href="/edit?xid={{ .Honk.XID }}">edit</a></button>
</div> </div>

View File

@ -53,15 +53,13 @@ function zonkit(el, xid) {
p.remove() p.remove()
} }
} }
function ackit(el, xid) { function flogit(el, how, xid) {
el.innerHTML = "acked" var s = how
if (s[s.length-1] != "e") { s += "e" }
s += "d"
el.innerHTML = s
el.disabled = true el.disabled = true
post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "ack", "what": xid})) post("/zonkit", encode({"CSRF": csrftoken, "wherefore": how, "what": xid}))
}
function deackit(el, xid) {
el.innerHTML = "deacked"
el.disabled = true
post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "deack", "what": xid}))
} }
function fillinhonks(xhr) { function fillinhonks(xhr) {
var doc = xhr.responseXML var doc = xhr.responseXML
@ -213,6 +211,8 @@ function relinklinks() {
el.onclick = pageswitcher("atme", "") el.onclick = pageswitcher("atme", "")
el = document.getElementById("firstlink") el = document.getElementById("firstlink")
el.onclick = pageswitcher("first", "") el.onclick = pageswitcher("first", "")
el = document.getElementById("savedlink")
el.onclick = pageswitcher("saved", "")
relinklinks() relinklinks()
window.onpopstate = statechanger window.onpopstate = statechanger
history.replaceState(curpagestate, "some title", "") history.replaceState(curpagestate, "some title", "")

31
web.go
View File

@ -109,6 +109,10 @@ func homepage(w http.ResponseWriter, r *http.Request) {
templinfo["PageName"] = "first" templinfo["PageName"] = "first"
honks = gethonksforuser(userid) honks = gethonksforuser(userid)
honks = osmosis(honks, userid) honks = osmosis(honks, userid)
case "/saved":
templinfo["ServerMessage"] = "saved honks"
templinfo["PageName"] = "saved"
honks = getsavedhonks(userid)
default: default:
templinfo["PageName"] = "home" templinfo["PageName"] = "home"
honks = gethonksforuser(userid) honks = gethonksforuser(userid)
@ -852,6 +856,28 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
userinfo := login.GetUserInfo(r) userinfo := login.GetUserInfo(r)
user, _ := butwhatabout(userinfo.Username) 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 // my hammer is too big, oh well
defer oldjonks.Flush() defer oldjonks.Flush()
@ -1572,6 +1598,10 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
honks = gethonksforuserfirstclass(userid) honks = gethonksforuserfirstclass(userid)
honks = osmosis(honks, userid) honks = osmosis(honks, userid)
templinfo["ServerMessage"] = "first class only" templinfo["ServerMessage"] = "first class only"
case "saved":
honks = getsavedhonks(userid)
templinfo["PageName"] = "saved"
templinfo["ServerMessage"] = "saved honks"
case "combo": case "combo":
c := r.FormValue("c") c := r.FormValue("c")
honks = gethonksbycombo(userid, c) honks = gethonksbycombo(userid, c)
@ -1689,6 +1719,7 @@ func serve() {
loggedin := mux.NewRoute().Subrouter() loggedin := mux.NewRoute().Subrouter()
loggedin.Use(login.Required) loggedin.Use(login.Required)
loggedin.HandleFunc("/first", homepage) loggedin.HandleFunc("/first", homepage)
loggedin.HandleFunc("/saved", homepage)
loggedin.HandleFunc("/account", accountpage) loggedin.HandleFunc("/account", accountpage)
loggedin.HandleFunc("/funzone", showfunzone) loggedin.HandleFunc("/funzone", showfunzone)
loggedin.HandleFunc("/chpass", dochpass) loggedin.HandleFunc("/chpass", dochpass)