From e89bff3051822c8b4cfb65449d4085cc47c8df4b Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 30 Sep 2019 23:32:10 -0400 Subject: [PATCH] rework save code to gobble up replies --- activity.go | 49 +++++++++++++++++-------------------------------- web.go | 7 +++---- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/activity.go b/activity.go index 7d382cb..cda8f28 100644 --- a/activity.go +++ b/activity.go @@ -343,10 +343,7 @@ func gimmexonks(user *WhatAbout, outbox string) { if !ok { continue } - xonk := xonkxonk(user, obj, origin) - if xonk != nil { - savexonk(xonk) - } + xonksaver(user, obj, origin) } } } @@ -423,35 +420,25 @@ func extractattrto(obj junk.Junk) string { return "" } -func consumeactivity(user *WhatAbout, j junk.Junk, origin string) { - xonk := xonkxonk(user, j, origin) - if xonk != nil { - savexonk(xonk) - } -} - -func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { +func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { depth := 0 maxdepth := 10 currenttid := "" var xonkxonkfn func(item junk.Junk, origin string) *Honk - saveoneup := func(xid string) { - log.Printf("getting oneup: %s", xid) + saveonemore := func(xid string) { + log.Printf("getting onemore: %s", xid) if depth >= maxdepth { log.Printf("in too deep") return } obj, err := GetJunkHardMode(xid) if err != nil { - log.Printf("error getting oneup: %s: %s", xid, err) + log.Printf("error getting onemore: %s: %s", xid, err) return } depth++ - xonk := xonkxonkfn(obj, originate(xid)) - if xonk != nil { - savexonk(xonk) - } + xonkxonkfn(obj, originate(xid)) depth-- } @@ -754,6 +741,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { xonk.Noise = content xonk.Precis = precis xonk.Format = "html" + xonk.Convoy = convoy if isUpdate { log.Printf("something has changed! %s", xonk.XID) @@ -769,13 +757,10 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { prev.Onts = xonk.Onts prev.Place = xonk.Place updatehonk(prev) - return nil - } - - if needxonk(user, &xonk) { + } else if needxonk(user, &xonk) { if rid != "" { if needxonkid(user, rid) { - saveoneup(rid) + saveonemore(rid) } if convoy == "" { xx := getxonk(user.ID, rid) @@ -787,15 +772,15 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { if convoy == "" { convoy = currenttid } - xonk.Convoy = convoy - for _, replid := range replies { - if needxonkid(user, replid) { - log.Printf("missing a reply: %s", replid) - } - } - return &xonk + savexonk(&xonk) } - return nil + for _, replid := range replies { + if needxonkid(user, replid) { + log.Printf("missing a reply: %s", replid) + saveonemore(replid) + } + } + return &xonk } return xonkxonkfn(item, origin) diff --git a/web.go b/web.go index 0b8d817..002e8fd 100644 --- a/web.go +++ b/web.go @@ -336,7 +336,7 @@ func inbox(w http.ResponseWriter, r *http.Request) { case "Question": return case "Note": - go consumeactivity(user, j, origin) + go xonksaver(user, j, origin) return } } @@ -369,7 +369,7 @@ func inbox(w http.ResponseWriter, r *http.Request) { } } default: - go consumeactivity(user, j, origin) + go xonksaver(user, j, origin) } } @@ -396,11 +396,10 @@ func ximport(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/h?xid="+url.QueryEscape(xid), http.StatusSeeOther) return } - xonk := xonkxonk(user, j, originate(xid)) + xonk := xonksaver(user, j, originate(xid)) convoy := "" if xonk != nil { convoy = xonk.Convoy - savexonk(xonk) } http.Redirect(w, r, "/t?c="+url.QueryEscape(convoy), http.StatusSeeOther) }