all repos — honk @ 2d48a59984723cb4480a013b05eef3a79f3cd428

my fork of honk

better handle AP usernames. don't require manual entry
Ted Unangst tedu@tedunangst.com
Thu, 15 Aug 2019 23:27:55 -0400
commit

2d48a59984723cb4480a013b05eef3a79f3cd428

parent

192aa222512284c16f8077fb4d42791f6ee2a015

5 files changed, 40 insertions(+), 21 deletions(-)

jump to
M activity.goactivity.go

@@ -990,26 +990,28 @@ }

return true } -func investigate(name string) string { +func investigate(name string) *Honker { if name == "" { - return "" + return nil } if name[0] == '@' { name = gofish(name) } if name == "" { - return "" + return nil } + log.Printf("digging up some info on %s", name) obj, err := GetJunkFast(name) if err != nil { log.Printf("error investigating honker: %s", err) - return "" + return nil } t, _ := obj.GetString("type") if !isactor(t) { log.Printf("it's not a person! %s", name) - return "" + return nil } - id, _ := obj.GetString("id") - return id + xid, _ := obj.GetString("id") + handle, _ := obj.GetString("preferredUsername") + return &Honker{XID: xid, Handle: handle} }
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++ Better understanding of ActivityPub Persons. No need to enter names! + + More robust retries for fetching objects. + Don't decode excessively large images and run out of memory.
M fun.gofun.go

@@ -52,9 +52,9 @@ if bloat_iscounter(h) {

bloat_counterhtml(h) } } - h.Username, h.Handle = honkerhandle(h.Honker) + h.Username, h.Handle = handles(h.Honker) } else { - _, h.Handle = honkerhandle(h.Honker) + _, h.Handle = handles(h.Honker) h.Username = h.Handle if len(h.Username) > 20 { h.Username = h.Username[:20] + ".."

@@ -64,7 +64,7 @@ h.URL = h.XID

} } if h.Oonker != "" { - _, h.Oondle = honkerhandle(h.Oonker) + _, h.Oondle = handles(h.Oonker) } zap := make(map[*Donk]bool) h.Noise = unpucker(h.Noise)

@@ -374,12 +374,21 @@ }

return "" } -func honkerhandle(h string) (string, string) { - m := re_unurl.FindStringSubmatch(h) - if len(m) > 2 { - return m[2], fmt.Sprintf("%s@%s", m[2], m[1]) +// handle, handle@host +func handles(xid string) (string, string) { + row := stmtGetXonker.QueryRow(xid, "handle") + var handle string + err := row.Scan(&handle) + if err == nil { + return handle, handle + "@" + originate(xid) + } + p := investigate(xid) + if p == nil { + return xid, xid } - return h, h + handle = p.Handle + stmtSaveXonker.Exec(xid, handle, "handle") + return handle, handle + "@" + originate(xid) } func prepend(s string, x []string) []string {
M honk.gohonk.go

@@ -92,6 +92,7 @@ ID int64

UserID int64 Name string XID string + Handle string Flavor string Combos []string }

@@ -436,9 +437,9 @@ }

func ximport(w http.ResponseWriter, r *http.Request) { xid := r.FormValue("xid") - x := investigate(xid) - if x != "" { - xid = x + p := investigate(xid) + if p != nil { + xid = p.XID } j, err := GetJunk(xid) if err != nil {

@@ -1232,9 +1233,14 @@ flavor := "presub"

if peep == "peep" { flavor = "peep" } - url = investigate(url) - if url == "" { + p := investigate(url) + if p == nil { + log.Printf("failed to investigate honker") return + } + url = p.XID + if name == "" { + name = p.Handle } _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) if err != nil {
M views/honkers.htmlviews/honkers.html

@@ -5,8 +5,8 @@ <p>

<form action="/savehonker" method="POST"> <span class="title">add new honker</span> <input type="hidden" name="CSRF" value="{{ .HonkerCSRF }}"> -<p><input tabindex=1 type="text" name="name" value="" autocomplete=off> - name <p><input tabindex=1 type="text" name="url" value="" autocomplete=off> - url +<p><input tabindex=1 type="text" name="name" value="" placeholder="optional" autocomplete=off> - name <p><span><label for="peep">just peeping:</label> <input tabindex=1 type="checkbox" id="peep" name="peep" value="peep"><span></span></span> <p><input tabindex=1 type="submit" name="add honker" value="add honker">