diff --git a/database.go b/database.go index cd1c2c4..ff12987 100644 --- a/database.go +++ b/database.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "log" + "sort" "strconv" "strings" "time" @@ -119,6 +120,33 @@ func getpublichonks() []*Honk { 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) whofore := 2 @@ -572,7 +600,7 @@ var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker 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 @@ func prepareStatements(db *sql.DB) { 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) diff --git a/views/header.html b/views/header.html index cbfe6ca..82a89ec 100644 --- a/views/header.html +++ b/views/header.html @@ -36,6 +36,7 @@
  • tags
  • about
  • front +
  • events
  • xzone
  • hfcs
  • funzone @@ -50,6 +51,7 @@

    {{ else }} home +events about {{ if .ShowRSS }} rss diff --git a/web.go b/web.go index bd2d31c..79d6620 100644 --- a/web.go +++ b/web.go @@ -83,18 +83,33 @@ func homepage(w http.ResponseWriter, r *http.Request) { 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 @@ func homepage(w http.ResponseWriter, r *http.Request) { templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) } - templinfo["ShowRSS"] = true - templinfo["ServerMessage"] = serverMsg honkpage(w, u, honks, templinfo) } @@ -1642,6 +1655,7 @@ func serve() { 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)