all repos — honk @ 5202b8a97c238f4b3e971d8c32b3df2d1a840ecc

my fork of honk

crawl up reply chain looking for oneups
Ted Unangst tedu@tedunangst.com
Thu, 25 Apr 2019 13:23:18 -0400
commit

5202b8a97c238f4b3e971d8c32b3df2d1a840ecc

parent

1ae28c75a94d118c92afa0da7e01e915ab99b2bf

1 files changed, 131 insertions(+), 94 deletions(-)

jump to
M activity.goactivity.go

@@ -409,82 +409,131 @@ return a

} func xonkxonk(user *WhatAbout, item interface{}) *Honk { - // id, _ := jsongetstring(item, "id") - what, _ := jsongetstring(item, "type") - dt, _ := jsongetstring(item, "published") + depth := 0 + maxdepth := 4 + var xonkxonkfn func(item interface{}) *Honk + + saveoneup := func(xid string) { + log.Printf("getting oneup: %s", xid) + if depth >= maxdepth { + log.Printf("in too deep") + return + } + obj, err := GetJunk(xid) + if err != nil { + log.Printf("error getting oneup: %s", err) + return + } + depth++ + xonk := xonkxonkfn(obj) + if needxonk(user, xonk) { + xonk.UserID = user.ID + savexonk(user, xonk) + } + depth-- + } + + xonkxonkfn = func(item interface{}) *Honk { + // id, _ := jsongetstring(item, "id") + what, _ := jsongetstring(item, "type") + dt, _ := jsongetstring(item, "published") - var audience []string - var err error - var xid, rid, url, content, convoy string - var obj map[string]interface{} - var ok bool - switch what { - case "Announce": - xid, ok = jsongetstring(item, "object") - if ok { - if !needxonkid(user, xid) { - return nil + var audience []string + var err error + var xid, rid, url, content, convoy string + var obj map[string]interface{} + var ok bool + switch what { + case "Announce": + xid, ok = jsongetstring(item, "object") + if ok { + if !needxonkid(user, xid) { + return nil + } + log.Printf("getting bonk: %s", xid) + obj, err = GetJunk(xid) + if err != nil { + log.Printf("error regetting: %s", err) + } + } else { + obj, _ = jsongetmap(item, "object") } - log.Printf("getting bonk: %s", xid) - obj, err = GetJunk(xid) - if err != nil { - log.Printf("error regetting: %s", err) - } - } else { + what = "bonk" + case "Create": obj, _ = jsongetmap(item, "object") + what = "honk" + case "Note": + obj = item.(map[string]interface{}) + what = "honk" + case "Delete": + obj, _ = jsongetmap(item, "object") + rid, _ = jsongetstring(item, "object") + what = "eradicate" + default: + log.Printf("unknown activity: %s", what) + return nil } - what = "bonk" - case "Create": - obj, _ = jsongetmap(item, "object") - what = "honk" - case "Delete": - obj, _ = jsongetmap(item, "object") - rid, _ = jsongetstring(item, "object") - what = "eradicate" - default: - log.Printf("unknown activity: %s", what) - return nil - } - who, _ := jsongetstring(item, "actor") - var xonk Honk - if obj != nil { - ot, _ := jsongetstring(obj, "type") - url, _ = jsongetstring(obj, "url") - if ot == "Note" || ot == "Article" { - audience = newphone(audience, obj) - xid, _ = jsongetstring(obj, "id") - content, _ = jsongetstring(obj, "content") - summary, _ := jsongetstring(obj, "summary") - if !strings.HasPrefix(content, "<p>") { - content = "<p>" + content + var xonk Honk + who, _ := jsongetstring(item, "actor") + if obj != nil { + if who == "" { + who, _ = jsongetstring(obj, "attributedTo") } - if summary != "" { - content = "<p>summary: " + summary + content + ot, _ := jsongetstring(obj, "type") + url, _ = jsongetstring(obj, "url") + if ot == "Note" || ot == "Article" { + audience = newphone(audience, obj) + xid, _ = jsongetstring(obj, "id") + content, _ = jsongetstring(obj, "content") + summary, _ := jsongetstring(obj, "summary") + if !strings.HasPrefix(content, "<p>") { + content = "<p>" + content + } + if summary != "" { + content = "<p>summary: " + summary + content + } + rid, _ = jsongetstring(obj, "inReplyTo") + convoy, _ = jsongetstring(obj, "context") + if convoy == "" { + convoy, _ = jsongetstring(obj, "conversation") + } + if what == "honk" && rid != "" { + what = "tonk" + if needxonkid(user, rid) { + saveoneup(rid) + } + } } - rid, _ = jsongetstring(obj, "inReplyTo") - convoy, _ = jsongetstring(obj, "context") - if convoy == "" { - convoy, _ = jsongetstring(obj, "conversation") + if ot == "Tombstone" { + rid, _ = jsongetstring(obj, "id") } - if what == "honk" && rid != "" { - what = "tonk" + atts, _ := jsongetarray(obj, "attachment") + for _, att := range atts { + at, _ := jsongetstring(att, "type") + mt, _ := jsongetstring(att, "mediaType") + u, _ := jsongetstring(att, "url") + name, _ := jsongetstring(att, "name") + if at == "Document" { + mt = strings.ToLower(mt) + log.Printf("attachment: %s %s", mt, u) + if mt == "image/jpeg" || mt == "image/png" || + mt == "image/gif" || mt == "text/plain" { + donk := savedonk(u, name, mt) + if donk != nil { + xonk.Donks = append(xonk.Donks, donk) + } + } + } } - } - if ot == "Tombstone" { - rid, _ = jsongetstring(obj, "id") - } - atts, _ := jsongetarray(obj, "attachment") - for _, att := range atts { - at, _ := jsongetstring(att, "type") - mt, _ := jsongetstring(att, "mediaType") - u, _ := jsongetstring(att, "url") - name, _ := jsongetstring(att, "name") - if at == "Document" { - mt = strings.ToLower(mt) - log.Printf("attachment: %s %s", mt, u) - if mt == "image/jpeg" || mt == "image/png" || - mt == "image/gif" || mt == "text/plain" { + tags, _ := jsongetarray(obj, "tag") + for _, tag := range tags { + tt, _ := jsongetstring(tag, "type") + name, _ := jsongetstring(tag, "name") + if tt == "Emoji" { + icon, _ := jsongetmap(tag, "icon") + mt, _ := jsongetstring(icon, "mediaType") + u, _ := jsongetstring(icon, "url") donk := savedonk(u, name, mt) if donk != nil { xonk.Donks = append(xonk.Donks, donk)

@@ -492,36 +541,24 @@ }

} } } - tags, _ := jsongetarray(obj, "tag") - for _, tag := range tags { - tt, _ := jsongetstring(tag, "type") - name, _ := jsongetstring(tag, "name") - if tt == "Emoji" { - icon, _ := jsongetmap(tag, "icon") - mt, _ := jsongetstring(icon, "mediaType") - u, _ := jsongetstring(icon, "url") - donk := savedonk(u, name, mt) - if donk != nil { - xonk.Donks = append(xonk.Donks, donk) - } - } - } - } - audience = append(audience, who) + audience = append(audience, who) - audience = oneofakind(audience) + audience = oneofakind(audience) - xonk.What = what - xonk.Honker = who - xonk.XID = xid - xonk.RID = rid - xonk.Date, _ = time.Parse(time.RFC3339, dt) - xonk.URL = url - xonk.Noise = content - xonk.Audience = audience - xonk.Convoy = convoy + xonk.What = what + xonk.Honker = who + xonk.XID = xid + xonk.RID = rid + xonk.Date, _ = time.Parse(time.RFC3339, dt) + xonk.URL = url + xonk.Noise = content + xonk.Audience = audience + xonk.Convoy = convoy - return &xonk + return &xonk + } + + return xonkxonkfn(item) } func rubadubdub(user *WhatAbout, req map[string]interface{}) {