experiment with nested thread sorting
Ted Unangst tedu@tedunangst.com
Tue, 13 Jun 2023 16:29:27 -0400
2 files changed,
79 insertions(+),
3 deletions(-)
M
views/style.css
→
views/style.css
@@ -175,7 +175,6 @@
.glow { box-shadow: 0px 0px 16px var(--hl); } - .honk { margin: auto; background: var(--bg-dark);@@ -186,6 +185,35 @@ padding-left: 1em;
padding-right: 1em; padding-top: 0; overflow: hidden; +} + +.level1 { + margin-left: 0.5em; +} +.level1::before { + position: absolute; + content: ">"; +} +.level2 { + margin-left: 1.0em; +} +.level2::before { + position: absolute; + content: ">>"; +} +.level3 { + margin-left: 1.5em; +} +.level3::before { + position: absolute; + content: ">>>"; +} +.level4 { + margin-left: 2.0em; +} +.level4::before { + position: absolute; + content: ">>>>"; } .chat {
M
web.go
→
web.go
@@ -779,7 +779,8 @@ if len(honks) > 0 {
templinfo["TopHID"] = honks[0].ID } honks = osmosis(honks, u.UserID, false) - reversehonks(honks) + //reversehonks(honks) + honks = threadsort(honks) templinfo["PageName"] = "convoy" templinfo["PageArg"] = c templinfo["ServerMessage"] = "honks in convoy: " + c@@ -1017,6 +1018,50 @@ trackchan <- Track{xid: xid, who: who}
} } +func threadsort(honks []*Honk) []*Honk { + kids := make(map[string][]*Honk) + for _, h := range honks { + kids[h.RID] = append(kids[h.RID], h) + } + done := make(map[*Honk]bool) + var thread []*Honk + var grabkids func(p *Honk) + level := 0 + grabkids = func(p *Honk) { + if level > 4 { + p.Style += fmt.Sprintf(" level%d", 4) + } else { + p.Style += fmt.Sprintf(" level%d", level) + } + level++ + childs := kids[p.XID] + sort.Slice(childs, func(i, j int) bool { + return childs[i].Date.Before(childs[j].Date) + }) + for _, h := range childs { + done[h] = true + thread = append(thread, h) + grabkids(h) + } + level-- + } + for _, h := range honks { + if h.RID == "" { + done[h] = true + thread = append(thread, h) + grabkids(h) + } + } + for _, h := range honks { + if !done[h] { + done[h] = true + thread = append(thread, h) + grabkids(h) + } + } + return thread +} + func honkology(honk *Honk) template.HTML { var user *WhatAbout ok := somenumberedusers.Get(honk.UserID, &user)@@ -1095,7 +1140,8 @@ }
templinfo := getInfo(r) rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0) - reversehonks(rawhonks) + //reversehonks(rawhonks) + rawhonks = threadsort(rawhonks) var honks []*Honk for _, h := range rawhonks { if h.XID == xid {@@ -2327,6 +2373,8 @@ case "convoy":
c := r.FormValue("c") honks = gethonksbyconvoy(userid, c, wanted) honks = osmosis(honks, userid, false) + honks = threadsort(honks) + reversehonks(honks) hydra.Srvmsg = templates.Sprintf("honks in convoy: %s", c) case "honker": xid := r.FormValue("xid")