From 617cdd5fd8cb71dac67f7e7e5870dfbaba9f7373 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 15 Aug 2019 23:27:55 -0400 Subject: [PATCH] better handle AP usernames. don't require manual entry --- activity.go | 16 +++++++++------- docs/changelog.txt | 2 ++ fun.go | 25 +++++++++++++++++-------- honk.go | 16 +++++++++++----- views/honkers.html | 2 +- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/activity.go b/activity.go index 90bc680..cd68edc 100644 --- a/activity.go +++ b/activity.go @@ -990,26 +990,28 @@ func isactor(t string) bool { 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} } diff --git a/docs/changelog.txt b/docs/changelog.txt index 75a50e3..1b83b83 100644 --- a/docs/changelog.txt +++ b/docs/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. diff --git a/fun.go b/fun.go index 54ceda8..b813f77 100644 --- a/fun.go +++ b/fun.go @@ -52,9 +52,9 @@ func reverbolate(userid int64, honks []*Honk) { 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 @@ func reverbolate(userid int64, honks []*Honk) { } } 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 @@ func originate(u string) string { 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) } - return h, h + p := investigate(xid) + if p == nil { + return xid, xid + } + handle = p.Handle + stmtSaveXonker.Exec(xid, handle, "handle") + return handle, handle + "@" + originate(xid) } func prepend(s string, x []string) []string { diff --git a/honk.go b/honk.go index 2e6d435..632c83e 100644 --- a/honk.go +++ b/honk.go @@ -92,6 +92,7 @@ type Honker struct { UserID int64 Name string XID string + Handle string Flavor string Combos []string } @@ -436,9 +437,9 @@ func inbox(w http.ResponseWriter, r *http.Request) { 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,10 +1233,15 @@ func savehonker(w http.ResponseWriter, r *http.Request) { 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 { log.Print(err) diff --git a/views/honkers.html b/views/honkers.html index de34fb9..0170d01 100644 --- a/views/honkers.html +++ b/views/honkers.html @@ -5,8 +5,8 @@
add new honker -

- name

- url +

- name