fix refreshing pages with reversed order
This commit is contained in:
parent
75fdc3a5f4
commit
5916ae68ab
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
19
web.go
19
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: <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 @@ 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)
|
||||
|
|
Loading…
Reference in New Issue