From 7cc2e6f2da7b46e9ce107058083a79f4050be26f Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 13 Jun 2023 23:31:52 -0400 Subject: [PATCH] this does a better job on broken threads --- web.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/web.go b/web.go index d0c8a7a..78cecee 100644 --- a/web.go +++ b/web.go @@ -1019,13 +1019,13 @@ func trackback(xid string, r *http.Request) { } func threadsort(honks []*Honk) []*Honk { + sort.Slice(honks, func(i, j int) bool { + return honks[i].Date.Before(honks[j].Date) + }) honkx := make(map[string]*Honk) kids := make(map[string][]*Honk) for _, h := range honks { honkx[h.XID] = h - if h.RID == "" { - honkx[""] = h - } rid := h.RID kids[rid] = append(kids[rid], h) } @@ -1035,7 +1035,7 @@ func threadsort(honks []*Honk) []*Honk { level := 0 nextlevel = func(p *Honk) { levelup := level < 4 - if pp := honkx[p.RID]; pp != nil && p.Honker == pp.Honker { + if pp := honkx[p.RID]; p.RID == "" || (pp != nil && p.Honker == pp.Honker) { levelup = false } if levelup { @@ -1043,9 +1043,6 @@ func threadsort(honks []*Honk) []*Honk { } p.Style += fmt.Sprintf(" level%d", 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)