all repos — honk @ b0e8e2aa0717201b7b13dbe7d4d41b046ef528f1

my fork of honk

fix refreshing pages with reversed order
Ted Unangst tedu@tedunangst.com
Tue, 08 Oct 2019 00:58:42 -0400
commit

b0e8e2aa0717201b7b13dbe7d4d41b046ef528f1

parent

8c83d43769dcc56c595892bb38d338267492ce8e

4 files changed, 33 insertions(+), 10 deletions(-)

jump to
M activity.goactivity.go

@@ -1109,6 +1109,7 @@ return nil, true

} 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)
M database.godatabase.go

@@ -159,9 +159,6 @@ }

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 {

@@ -174,6 +171,12 @@ func gethonksbyontology(userid int64, name string) []*Honk {

rows, err := stmtHonksByOntology.Query(name, userid, userid) honks := getsomehonks(rows, err) 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 {
M views/honkpage.jsviews/honkpage.js

@@ -76,11 +76,21 @@ srvel.children[0].remove()

} 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)
M web.goweb.go

@@ -455,7 +455,7 @@ log.Print(err)

} } -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 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 @@ name = html.EscapeString(name)

msg := fmt.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, 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 @@ honks := gethonksbycombo(u.UserID, name)

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 @@ c := r.FormValue("c")

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 @@ q := r.FormValue("q")

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 @@ honkpage(w, u, []*Honk{honk}, templinfo)

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 @@ w.Header().Set("Cache-Control", "max-age=60")

} 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)