better handle AP usernames. don't require manual entry
This commit is contained in:
parent
988f16aca8
commit
617cdd5fd8
16
activity.go
16
activity.go
|
@ -990,26 +990,28 @@ func isactor(t string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func investigate(name string) string {
|
func investigate(name string) *Honker {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
if name[0] == '@' {
|
if name[0] == '@' {
|
||||||
name = gofish(name)
|
name = gofish(name)
|
||||||
}
|
}
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Printf("digging up some info on %s", name)
|
||||||
obj, err := GetJunkFast(name)
|
obj, err := GetJunkFast(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error investigating honker: %s", err)
|
log.Printf("error investigating honker: %s", err)
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
t, _ := obj.GetString("type")
|
t, _ := obj.GetString("type")
|
||||||
if !isactor(t) {
|
if !isactor(t) {
|
||||||
log.Printf("it's not a person! %s", name)
|
log.Printf("it's not a person! %s", name)
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
id, _ := obj.GetString("id")
|
xid, _ := obj.GetString("id")
|
||||||
return id
|
handle, _ := obj.GetString("preferredUsername")
|
||||||
|
return &Honker{XID: xid, Handle: handle}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ changelog
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
|
|
||||||
|
+ Better understanding of ActivityPub Persons. No need to enter names!
|
||||||
|
|
||||||
+ More robust retries for fetching objects.
|
+ More robust retries for fetching objects.
|
||||||
|
|
||||||
+ Don't decode excessively large images and run out of memory.
|
+ Don't decode excessively large images and run out of memory.
|
||||||
|
|
25
fun.go
25
fun.go
|
@ -52,9 +52,9 @@ func reverbolate(userid int64, honks []*Honk) {
|
||||||
bloat_counterhtml(h)
|
bloat_counterhtml(h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.Username, h.Handle = honkerhandle(h.Honker)
|
h.Username, h.Handle = handles(h.Honker)
|
||||||
} else {
|
} else {
|
||||||
_, h.Handle = honkerhandle(h.Honker)
|
_, h.Handle = handles(h.Honker)
|
||||||
h.Username = h.Handle
|
h.Username = h.Handle
|
||||||
if len(h.Username) > 20 {
|
if len(h.Username) > 20 {
|
||||||
h.Username = h.Username[:20] + ".."
|
h.Username = h.Username[:20] + ".."
|
||||||
|
@ -64,7 +64,7 @@ func reverbolate(userid int64, honks []*Honk) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if h.Oonker != "" {
|
if h.Oonker != "" {
|
||||||
_, h.Oondle = honkerhandle(h.Oonker)
|
_, h.Oondle = handles(h.Oonker)
|
||||||
}
|
}
|
||||||
zap := make(map[*Donk]bool)
|
zap := make(map[*Donk]bool)
|
||||||
h.Noise = unpucker(h.Noise)
|
h.Noise = unpucker(h.Noise)
|
||||||
|
@ -374,12 +374,21 @@ func originate(u string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func honkerhandle(h string) (string, string) {
|
// handle, handle@host
|
||||||
m := re_unurl.FindStringSubmatch(h)
|
func handles(xid string) (string, string) {
|
||||||
if len(m) > 2 {
|
row := stmtGetXonker.QueryRow(xid, "handle")
|
||||||
return m[2], fmt.Sprintf("%s@%s", m[2], m[1])
|
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 {
|
func prepend(s string, x []string) []string {
|
||||||
|
|
16
honk.go
16
honk.go
|
@ -92,6 +92,7 @@ type Honker struct {
|
||||||
UserID int64
|
UserID int64
|
||||||
Name string
|
Name string
|
||||||
XID string
|
XID string
|
||||||
|
Handle string
|
||||||
Flavor string
|
Flavor string
|
||||||
Combos []string
|
Combos []string
|
||||||
}
|
}
|
||||||
|
@ -436,9 +437,9 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func ximport(w http.ResponseWriter, r *http.Request) {
|
func ximport(w http.ResponseWriter, r *http.Request) {
|
||||||
xid := r.FormValue("xid")
|
xid := r.FormValue("xid")
|
||||||
x := investigate(xid)
|
p := investigate(xid)
|
||||||
if x != "" {
|
if p != nil {
|
||||||
xid = x
|
xid = p.XID
|
||||||
}
|
}
|
||||||
j, err := GetJunk(xid)
|
j, err := GetJunk(xid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1232,10 +1233,15 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
|
||||||
if peep == "peep" {
|
if peep == "peep" {
|
||||||
flavor = "peep"
|
flavor = "peep"
|
||||||
}
|
}
|
||||||
url = investigate(url)
|
p := investigate(url)
|
||||||
if url == "" {
|
if p == nil {
|
||||||
|
log.Printf("failed to investigate honker")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
url = p.XID
|
||||||
|
if name == "" {
|
||||||
|
name = p.Handle
|
||||||
|
}
|
||||||
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
|
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
<form action="/savehonker" method="POST">
|
<form action="/savehonker" method="POST">
|
||||||
<span class="title">add new honker</span>
|
<span class="title">add new honker</span>
|
||||||
<input type="hidden" name="CSRF" value="{{ .HonkerCSRF }}">
|
<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="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>
|
<p><span><label for="peep">just peeping:</label>
|
||||||
<input tabindex=1 type="checkbox" id="peep" name="peep" value="peep"><span></span></span>
|
<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">
|
<p><input tabindex=1 type="submit" name="add honker" value="add honker">
|
||||||
|
|
Loading…
Reference in New Issue