add events page
Ted Unangst tedu@tedunangst.com
Thu, 10 Oct 2019 20:37:03 -0400
3 files changed,
53 insertions(+),
8 deletions(-)
M
database.go
→
database.go
@@ -21,6 +21,7 @@ "database/sql"
"encoding/json" "fmt" "log" + "sort" "strconv" "strings" "time"@@ -118,6 +119,33 @@ func getpublichonks() []*Honk {
dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) rows, err := stmtPublicHonks.Query(dt) return getsomehonks(rows, err) +} +func geteventhonks(userid int64) []*Honk { + rows, err := stmtEventHonks.Query(userid) + honks := getsomehonks(rows, err) + sort.Slice(honks, func(i, j int) bool { + var t1, t2 time.Time + if honks[i].Time == nil { + t1 = honks[i].Date + } else { + t1 = honks[i].Time.StartTime + } + if honks[j].Time == nil { + t2 = honks[j].Date + } else { + t2 = honks[j].Time.StartTime + } + return t1.After(t2) + }) + now := time.Now().Add(-24 * time.Hour) + for i, h := range honks { + if h.Time.StartTime.Before(now) { + honks = honks[:i] + break + } + } + reversehonks(honks) + return honks } func gethonksbyuser(name string, includeprivate bool) []*Honk { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat)@@ -572,7 +600,7 @@ var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker *sql.Stmt
var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtWhatAbout *sql.Stmt -var stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt +var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt@@ -604,6 +632,7 @@ stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")
stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc") stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2") stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit) + stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+limit) stmtUserHonks = preparetodie(db, selecthonks+"where (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit) stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit) stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and (what <> 'tonk') and honker in (select xid from honkers where userid = ? and flavor = 'sub' and combos not like '% - %')"+butnotthose+limit)
M
views/header.html
→
views/header.html
@@ -36,6 +36,7 @@ </details>
<li><a href="/o">tags</a> <li><a href="/about">about</a> <li><a href="/front">front</a> +<li><a href="/events">events</a> <li><a href="/xzone">xzone</a> <li><a href="/hfcs">hfcs</a> <li><a href="/funzone">funzone</a>@@ -50,6 +51,7 @@ </details>
<p></p> {{ else }} <span><a id="homelink" href="/">home</a></span> +<span><a href="/events">events</a></span> <span><a href="/about">about</a></span> {{ if .ShowRSS }} <span><a href="/rss">rss</a></span>
M
web.go
→
web.go
@@ -83,18 +83,33 @@ templinfo := getInfo(r)
u := login.GetUserInfo(r) var honks []*Honk var userid int64 = -1 - if r.URL.Path == "/front" || u == nil { - honks = getpublichonks() + + templinfo["ServerMessage"] = serverMsg + if u == nil { + switch r.URL.Path { + case "/events": + honks = geteventhonks(userid) + templinfo["ServerMessage"] = "some recent and upcoming events" + default: + templinfo["ShowRSS"] = true + honks = getpublichonks() + } } else { userid = u.UserID - if r.URL.Path == "/atme" { + switch r.URL.Path { + case "/atme": templinfo["PageName"] = "atme" honks = gethonksforme(userid) - } else if r.URL.Path == "/first" { + case "/events": + templinfo["ServerMessage"] = "some recent and upcoming events" + templinfo["PageName"] = "events" + honks = geteventhonks(userid) + honks = osmosis(honks, userid) + case "/first": templinfo["PageName"] = "first" honks = gethonksforuser(userid) honks = osmosis(honks, userid) - } else { + default: templinfo["PageName"] = "home" honks = gethonksforuser(userid) honks = osmosis(honks, userid)@@ -102,8 +117,6 @@ }
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) } - templinfo["ShowRSS"] = true - templinfo["ServerMessage"] = serverMsg honkpage(w, u, honks, templinfo) }@@ -1642,6 +1655,7 @@
getters.HandleFunc("/", homepage) getters.HandleFunc("/home", homepage) getters.HandleFunc("/front", homepage) + getters.HandleFunc("/events", homepage) getters.HandleFunc("/robots.txt", nomoroboto) getters.HandleFunc("/rss", showrss) getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)