a little rework of the chonky bonk flow

This commit is contained in:
Ted Unangst 2023-08-01 16:17:45 -04:00
parent 2e82a931b9
commit 04cc94facd
1 changed files with 34 additions and 23 deletions

View File

@ -490,7 +490,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
maxdepth := 10 maxdepth := 10
currenttid := "" currenttid := ""
goingup := 0 goingup := 0
var xonkxonkfn func(item junk.Junk, origin string, isUpdate bool) *Honk var xonkxonkfn func(junk.Junk, string, bool, bool) *Honk
qutify := func(user *WhatAbout, content string) string { qutify := func(user *WhatAbout, content string) string {
if depth >= maxdepth { if depth >= maxdepth {
@ -522,7 +522,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
} }
prevdepth := depth prevdepth := depth
depth = maxdepth depth = maxdepth
xonkxonkfn(j, originate(m), false) xonkxonkfn(j, originate(m), false, false)
depth = prevdepth depth = prevdepth
} }
} }
@ -541,18 +541,22 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
ilog.Printf("error getting onemore: %s: %s", xid, err) ilog.Printf("error getting onemore: %s: %s", xid, err)
return return
} }
depth++ xonkxonkfn(obj, originate(xid), false, false)
xonkxonkfn(obj, originate(xid), false)
depth--
} }
xonkxonkfn = func(item junk.Junk, origin string, isUpdate bool) *Honk { xonkxonkfn = func(item junk.Junk, origin string, isUpdate bool, isAnnounce bool) *Honk {
id, _ := item.GetString("id") id, _ := item.GetString("id")
what := firstofmany(item, "type") what := firstofmany(item, "type")
dt, ok := item.GetString("published") dt, ok := item.GetString("published")
if !ok { if !ok {
dt = time.Now().Format(time.RFC3339) dt = time.Now().Format(time.RFC3339)
} }
if depth >= maxdepth+5 {
ilog.Printf("went too deep in xonkxonk")
return nil
}
depth++
defer func() { depth-- }()
var err error var err error
var xid, rid, url, convoy string var xid, rid, url, convoy string
@ -598,27 +602,26 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
case "Announce": case "Announce":
obj, ok = item.GetMap("object") obj, ok = item.GetMap("object")
if ok { if ok {
// at some point we should just recurse // peek ahead some
what, ok := obj.GetString("type") what, ok := obj.GetString("type")
if ok && (what == "Create" || what == "Update") { if ok && (what == "Create" || what == "Update") {
obj, ok = obj.GetMap("object")
if !ok {
ilog.Printf("lost object inside announce %s", id)
return nil
}
if what == "Update" { if what == "Update" {
isUpdate = true isUpdate = true
} }
what, _ = obj.GetString("type") inner, ok := obj.GetMap("object")
if ok {
obj = inner
} else {
xid, _ = obj.GetString("object")
}
} }
if what == "Page" { if xid == "" {
waspage = true xid, _ = obj.GetString("id")
} }
xid, _ = obj.GetString("id")
} else { } else {
xid, _ = item.GetString("object") xid, _ = item.GetString("object")
} }
if !needbonkid(user, xid) { if !isUpdate && !needbonkid(user, xid) {
return nil return nil
} }
origin = originate(xid) origin = originate(xid)
@ -631,7 +634,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
ilog.Printf("error getting bonk: %s: %s", xid, err) ilog.Printf("error getting bonk: %s: %s", xid, err)
} }
} }
what = "bonk" return xonkxonkfn(obj, origin, isUpdate, true)
case "Update": case "Update":
isUpdate = true isUpdate = true
fallthrough fallthrough
@ -653,7 +656,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
ilog.Printf("no object for creation %s", id) ilog.Printf("no object for creation %s", id)
return nil return nil
} }
return xonkxonkfn(obj, origin, isUpdate) return xonkxonkfn(obj, origin, isUpdate, isAnnounce)
case "Read": case "Read":
xid, ok = item.GetString("object") xid, ok = item.GetString("object")
if ok { if ok {
@ -666,7 +669,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
ilog.Printf("error getting read: %s", err) ilog.Printf("error getting read: %s", err)
return nil return nil
} }
return xonkxonkfn(obj, originate(xid), false) return xonkxonkfn(obj, originate(xid), false, false)
} }
return nil return nil
case "Add": case "Add":
@ -682,7 +685,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
ilog.Printf("error getting add: %s", err) ilog.Printf("error getting add: %s", err)
return nil return nil
} }
return xonkxonkfn(obj, originate(xid), false) return xonkxonkfn(obj, originate(xid), false, false)
} }
return nil return nil
case "Move": case "Move":
@ -711,6 +714,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
obj = item obj = item
what = "event" what = "event"
case "ChatMessage": case "ChatMessage":
isAnnounce = false
obj = item obj = item
what = "chonk" what = "chonk"
default: default:
@ -718,6 +722,9 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
dumpactivity(item) dumpactivity(item)
return nil return nil
} }
if isAnnounce {
what = "bonk"
}
if obj != nil { if obj != nil {
xid, _ = obj.GetString("id") xid, _ = obj.GetString("id")
@ -1054,11 +1061,15 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
imaginate(&xonk) imaginate(&xonk)
if what == "chonk" { if what == "chonk" {
target, _ := obj.GetString("to")
if target == user.URL {
target = xonk.Honker
}
ch := Chonk{ ch := Chonk{
UserID: xonk.UserID, UserID: xonk.UserID,
XID: xid, XID: xid,
Who: xonk.Honker, Who: xonk.Honker,
Target: xonk.Honker, Target: target,
Date: xonk.Date, Date: xonk.Date,
Noise: xonk.Noise, Noise: xonk.Noise,
Format: xonk.Format, Format: xonk.Format,
@ -1114,7 +1125,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
return &xonk return &xonk
} }
return xonkxonkfn(item, origin, false) return xonkxonkfn(item, origin, false, false)
} }
func dumpactivity(item junk.Junk) { func dumpactivity(item junk.Junk) {