allow saving honks for later
This commit is contained in:
parent
ed02a0dd72
commit
ba8270e97c
13
database.go
13
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)
|
||||
|
|
5
honk.go
5
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
|
||||
|
|
|
@ -33,11 +33,11 @@
|
|||
</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 @@
|
|||
<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>
|
||||
|
|
|
@ -102,9 +102,14 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
|||
<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="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 }}
|
||||
<button><a href="/edit?xid={{ .Honk.XID }}">edit</a></button>
|
||||
</div>
|
||||
|
|
|
@ -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", "")
|
||||
|
|
31
web.go
31
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)
|
||||
|
|
Loading…
Reference in New Issue