some code towards enabling following a collection
Ted Unangst tedu@tedunangst.com
Sat, 26 Oct 2019 18:31:42 -0400
4 files changed,
66 insertions(+),
36 deletions(-)
M
activity.go
→
activity.go
@@ -946,7 +946,7 @@
deliverate(0, user.ID, xid, j.ToBytes()) } -func subsub(user *WhatAbout, xid string) { +func subsub(user *WhatAbout, xid string, owner string) { if xid == "" { log.Printf("can't subscribe to empty") return@@ -956,15 +956,11 @@ j["@context"] = itiswhatitis
j["id"] = user.URL + "/sub/" + url.QueryEscape(xid) j["type"] = "Follow" j["actor"] = user.URL - j["to"] = xid + j["to"] = owner j["object"] = xid j["published"] = time.Now().UTC().Format(time.RFC3339) - var buf bytes.Buffer - j.Write(&buf) - msg := buf.Bytes() - - deliverate(0, user.ID, xid, msg) + deliverate(0, user.ID, owner, j.ToBytes()) } // returns activity, object@@ -1335,19 +1331,7 @@ handfull.Get(name, &href)
return href } -func isactor(t string) bool { - switch t { - case "Person": - case "Organization": - case "Application": - case "Service": - default: - return false - } - return true -} - -func investigate(name string) (*Honker, error) { +func investigate(name string) (*SomeThing, error) { if name == "" { return nil, fmt.Errorf("no name") }@@ -1361,11 +1345,36 @@ obj, err := GetJunkFast(name)
if err != nil { return nil, err } + return somethingabout(obj) +} + +func somethingabout(obj junk.Junk) (*SomeThing, error) { + info := new(SomeThing) t, _ := obj.GetString("type") - if !isactor(t) { - return nil, fmt.Errorf("not a person") + switch t { + case "Person": + fallthrough + case "Organization": + fallthrough + case "Application": + fallthrough + case "Service": + info.What = SomeActor + case "OrderedCollection": + fallthrough + case "Collection": + info.What = SomeCollection + default: + return nil, fmt.Errorf("unknown object type") } - xid, _ := obj.GetString("id") - handle, _ := obj.GetString("preferredUsername") - return &Honker{XID: xid, Handle: handle}, nil + info.XID, _ = obj.GetString("id") + info.Name, _ = obj.GetString("preferredUsername") + if info.Name == "" { + info.Name, _ = obj.GetString("name") + } + info.Owner, _ = obj.GetString("attributedTo") + if info.Owner == "" { + info.Owner = info.XID + } + return info, nil }
M
fun.go
→
fun.go
@@ -514,8 +514,8 @@ row := stmtGetXonker.QueryRow(xid, "handle")
var handle string err := row.Scan(&handle) if err != nil { - p, _ := investigate(xid) - if p == nil { + info, _ := investigate(xid) + if info == nil { m := re_unurl.FindStringSubmatch(xid) if len(m) > 2 { handle = m[2]@@ -523,7 +523,7 @@ } else {
handle = xid } } else { - handle = p.Handle + handle = info.Name } _, err = stmtSaveXonker.Exec(xid, handle, "handle") if err != nil {
M
web.go
→
web.go
@@ -538,14 +538,19 @@ }
log.Printf("importing %s", xid) user, _ := butwhatabout(u.Username) - what, _ := j.GetString("type") - if isactor(what) { + info, _ := somethingabout(j) + if info == nil { + xonk = xonksaver(user, j, originate(xid)) + } else if info.What == SomeActor { outbox, _ := j.GetString("outbox") gimmexonks(user, outbox) http.Redirect(w, r, "/h?xid="+url.QueryEscape(xid), http.StatusSeeOther) return + } else if info.What == SomeCollection { + gimmexonks(user, xid) + http.Redirect(w, r, "/xzone", http.StatusSeeOther) + return } - xonk = xonksaver(user, j, originate(xid)) } convoy := "" if xonk != nil {@@ -770,6 +775,7 @@
j := junk.New() j["@context"] = itiswhatitis j["id"] = fmt.Sprintf("https://%s/o/%s", serverName, name) + j["name"] = name j["attributedTo"] = user.URL j["type"] = "OrderedCollection" j["totalItems"] = len(xids)@@ -1501,7 +1507,9 @@ if err != nil {
log.Printf("error updating honker: %s", err) return } - go subsub(user, url) + // incomplete + owner := url + go subsub(user, url, owner) http.Redirect(w, r, "/honkers", http.StatusSeeOther) return@@ -1519,13 +1527,13 @@ flavor := "presub"
if peep == "peep" { flavor = "peep" } - p, err := investigate(url) + info, err := investigate(url) if err != nil { http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError) log.Printf("failed to investigate honker: %s", err) return } - url = p.XID + url = info.XID db := opendatabase() row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID)@@ -1540,7 +1548,7 @@ return
} if name == "" { - name = p.Handle + name = info.Name } _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) if err != nil {@@ -1549,7 +1557,7 @@ return
} if flavor == "presub" { user, _ := butwhatabout(u.Username) - go subsub(user, url) + go subsub(user, url, info.Owner) } http.Redirect(w, r, "/honkers", http.StatusSeeOther) }