From 5916ae68ab0eaddbfe30153f49a23190eca10914 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 8 Oct 2019 00:58:42 -0400 Subject: [PATCH] fix refreshing pages with reversed order --- activity.go | 1 + database.go | 9 ++++++--- views/honkpage.js | 14 +++++++++++--- web.go | 19 +++++++++++++++---- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/activity.go b/activity.go index 0169169..0dc9745 100644 --- a/activity.go +++ b/activity.go @@ -1109,6 +1109,7 @@ var oldjonks = cacheNew(cacheOptions{Filler: func(xid string) ([]byte, bool) { } user, _ := butwhatabout(honk.Username) rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) + reversehonks(rawhonks) for _, h := range rawhonks { if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) { honk.Replies = append(honk.Replies, h) diff --git a/database.go b/database.go index 4787670..24af100 100644 --- a/database.go +++ b/database.go @@ -159,9 +159,6 @@ func gethonksbycombo(userid int64, combo string) []*Honk { func gethonksbyconvoy(userid int64, convoy string) []*Honk { rows, err := stmtHonksByConvoy.Query(userid, userid, convoy) honks := getsomehonks(rows, err) - for i, j := 0, len(honks)-1; i < j; i, j = i+1, j-1 { - honks[i], honks[j] = honks[j], honks[i] - } return honks } func gethonksbysearch(userid int64, q string) []*Honk { @@ -176,6 +173,12 @@ func gethonksbyontology(userid int64, name string) []*Honk { return honks } +func reversehonks(honks []*Honk) { + for i, j := 0, len(honks)-1; i < j; i, j = i+1, j-1 { + honks[i], honks[j] = honks[j], honks[i] + } +} + func getsomehonks(rows *sql.Rows, err error) []*Honk { if err != nil { log.Printf("error querying honks: %s", err) diff --git a/views/honkpage.js b/views/honkpage.js index e46c160..d14d095 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -76,11 +76,21 @@ function fillinhonks(xhr) { } srvel.prepend(srvmsg) + var frontload = true + if (curpagestate.name == "convoy") { + frontload = false + } + var honksonpage = document.getElementById("honksonpage") var holder = honksonpage.children[0] var lenhonks = honks.length for (var i = honks.length; i > 0; i--) { - holder.prepend(honks[i-1]) + if (frontload) { + holder.prepend(honks[i-1]) + } else { + holder.append(honks[i-1]) + } + } relinklinks() return lenhonks @@ -157,9 +167,7 @@ function pageswitcher(name, arg) { return function(evt) { var topmenu = document.getElementById("topmenu") topmenu.open = false - console.log("switching to", name +":"+arg) if (name == curpagestate.name && arg == curpagestate.arg) { - console.log("skipping nav") return false } switchtopage(name, arg) diff --git a/web.go b/web.go index 821cff8..4241509 100644 --- a/web.go +++ b/web.go @@ -455,7 +455,7 @@ func xzone(w http.ResponseWriter, r *http.Request) { } } -var oldoutbox = cacheNew(cacheOptions{ Filler: func(name string) ([]byte, bool) { +var oldoutbox = cacheNew(cacheOptions{Filler: func(name string) ([]byte, bool) { user, err := butwhatabout(name) if err != nil { return nil, false @@ -481,7 +481,7 @@ var oldoutbox = cacheNew(cacheOptions{ Filler: func(name string) ([]byte, bool) var buf bytes.Buffer j.Write(&buf) return buf.Bytes(), true -}, Duration: 1*time.Minute}) +}, Duration: 1 * time.Minute}) func outbox(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] @@ -579,6 +579,7 @@ func showhonker(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf(`honks by honker: %s`, name, name) templinfo := getInfo(r) templinfo["PageName"] = "honker" + templinfo["PageArg"] = name templinfo["ServerMessage"] = template.HTML(msg) templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) honkpage(w, u, honks, templinfo) @@ -591,7 +592,7 @@ func showcombo(w http.ResponseWriter, r *http.Request) { honks = osmosis(honks, u.UserID) templinfo := getInfo(r) templinfo["PageName"] = "combo" - templinfo["PageArg"] = "name" + templinfo["PageArg"] = name templinfo["ServerMessage"] = "honks by combo: " + name templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) honkpage(w, u, honks, templinfo) @@ -601,6 +602,12 @@ func showconvoy(w http.ResponseWriter, r *http.Request) { u := login.GetUserInfo(r) honks := gethonksbyconvoy(u.UserID, c) templinfo := getInfo(r) + if len(honks) > 0 { + templinfo["TopXID"] = honks[0].XID + } + reversehonks(honks) + templinfo["PageName"] = "convoy" + templinfo["PageArg"] = c templinfo["ServerMessage"] = "honks in convoy: " + c templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) honkpage(w, u, honks, templinfo) @@ -610,6 +617,8 @@ func showsearch(w http.ResponseWriter, r *http.Request) { u := login.GetUserInfo(r) honks := gethonksbysearch(u.UserID, q) templinfo := getInfo(r) + templinfo["PageName"] = "search" + templinfo["PageArg"] = q templinfo["ServerMessage"] = "honks for search: " + q templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) honkpage(w, u, honks, templinfo) @@ -706,6 +715,7 @@ func showhonk(w http.ResponseWriter, r *http.Request) { return } rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) + reversehonks(rawhonks) var honks []*Honk for _, h := range rawhonks { if h.Public && (h.Whofore == 2 || h.IsAcked()) { @@ -729,7 +739,8 @@ func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo } reverbolate(userid, honks) templinfo["Honks"] = honks - if len(honks) > 0 { + if templinfo["TopXID"] == nil && len(honks) > 0 { + log.Printf("setting topxid") templinfo["TopXID"] = honks[0].XID } err := readviews.Execute(w, "honkpage.html", templinfo)