allow import the most recent honks for a xonker

This commit is contained in:
Ted Unangst 2019-06-16 22:36:52 -04:00
parent 2ac28709ea
commit 50f0222eb1
2 changed files with 54 additions and 32 deletions

View File

@ -311,6 +311,50 @@ func getboxes(ident string) (*Box, error) {
return b, nil return b, nil
} }
func gimmexonks(user *WhatAbout, outbox string) {
log.Printf("getting outbox: %s", outbox)
j, err := GetJunk(outbox)
if err != nil {
log.Printf("error getting outbox: %s", err)
return
}
t, _ := j.GetString("type")
origin := originate(outbox)
if t == "OrderedCollection" {
items, _ := j.GetArray("orderedItems")
if items == nil {
obj, ok := j.GetMap("first")
if ok {
items, _ = obj.GetArray("orderedItems")
} else {
page1, _ := j.GetString("first")
j, err = GetJunk(page1)
if err != nil {
log.Printf("error gettings page1: %s", err)
return
}
items, _ = j.GetArray("orderedItems")
}
}
if len(items) > 20 {
items = items[0:20]
}
for i, j := 0, len(items)-1; i < j; i, j = i+1, j-1 {
items[i], items[j] = items[j], items[i]
}
for _, item := range items {
obj, ok := item.(junk.Junk)
if !ok {
continue
}
xonk := xonkxonk(user, obj, origin)
if xonk != nil {
savexonk(user, xonk)
}
}
}
}
func peeppeep() { func peeppeep() {
user, _ := butwhatabout("htest") user, _ := butwhatabout("htest")
honkers := gethonkers(user.ID) honkers := gethonkers(user.ID)
@ -324,40 +368,9 @@ func peeppeep() {
log.Printf("error getting outbox: %s", err) log.Printf("error getting outbox: %s", err)
continue continue
} }
log.Printf("getting outbox") gimmexonks(user, box.Out)
j, err := GetJunk(box.Out)
if err != nil {
log.Printf("err: %s", err)
continue
}
t, _ := j.GetString("type")
origin := originate(f.XID)
if t == "OrderedCollection" {
items, _ := j.GetArray("orderedItems")
if items == nil {
page1, _ := j.GetString("first")
j, err = GetJunk(page1)
if err != nil {
log.Printf("err: %s", err)
continue
}
items, _ = j.GetArray("orderedItems")
}
for _, item := range items {
obj, ok := item.(junk.Junk)
if !ok {
continue
}
xonk := xonkxonk(user, obj, origin)
if xonk != nil {
savexonk(user, xonk)
}
}
}
} }
} }
func whosthere(xid string) ([]string, string) { func whosthere(xid string) ([]string, string) {
obj, err := GetJunk(xid) obj, err := GetJunk(xid)
if err != nil { if err != nil {

View File

@ -372,8 +372,17 @@ func ximport(w http.ResponseWriter, r *http.Request) {
log.Printf("error getting external object: %s", err) log.Printf("error getting external object: %s", err)
return return
} }
log.Printf("importing %s", xid)
u := login.GetUserInfo(r) u := login.GetUserInfo(r)
user, _ := butwhatabout(u.Username) user, _ := butwhatabout(u.Username)
what, _ := j.GetString("type")
if what == "Person" {
outbox, _ := j.GetString("outbox")
gimmexonks(user, outbox)
http.Redirect(w, r, "/h?xid="+url.QueryEscape(xid), http.StatusSeeOther)
return
}
xonk := xonkxonk(user, j, originate(xid)) xonk := xonkxonk(user, j, originate(xid))
convoy := "" convoy := ""
if xonk != nil { if xonk != nil {