crawl up reply chain looking for oneups

This commit is contained in:
Ted Unangst 2019-04-25 13:23:18 -04:00
parent 02f1ae8221
commit a1445cb118
1 changed files with 135 additions and 98 deletions

View File

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