diff --git a/activity.go b/activity.go index 68bc726..68d6485 100644 --- a/activity.go +++ b/activity.go @@ -946,7 +946,7 @@ func itakeitallback(user *WhatAbout, xid string) { 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 @@ func subsub(user *WhatAbout, xid string) { 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 @@ func gofish(name string) string { 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 @@ func investigate(name string) (*Honker, error) { if err != nil { return nil, err } - t, _ := obj.GetString("type") - if !isactor(t) { - return nil, fmt.Errorf("not a person") - } - xid, _ := obj.GetString("id") - handle, _ := obj.GetString("preferredUsername") - return &Honker{XID: xid, Handle: handle}, nil + return somethingabout(obj) +} + +func somethingabout(obj junk.Junk) (*SomeThing, error) { + info := new(SomeThing) + t, _ := obj.GetString("type") + 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") + } + 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 } diff --git a/fun.go b/fun.go index d956cfc..6783173 100644 --- a/fun.go +++ b/fun.go @@ -514,8 +514,8 @@ func findhandle(xid string) string { 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 @@ func findhandle(xid string) string { handle = xid } } else { - handle = p.Handle + handle = info.Name } _, err = stmtSaveXonker.Exec(xid, handle, "handle") if err != nil { diff --git a/honk.go b/honk.go index 19ba382..b147ef5 100644 --- a/honk.go +++ b/honk.go @@ -156,6 +156,19 @@ type Honker struct { Combos []string } +type SomeThing struct { + What int + XID string + Owner string + Name string +} + +const ( + SomeNothing int = iota + SomeActor + SomeCollection +) + var serverName string var iconName = "icon.png" var serverMsg template.HTML diff --git a/web.go b/web.go index f636341..961ef7e 100644 --- a/web.go +++ b/web.go @@ -538,14 +538,19 @@ func ximport(w http.ResponseWriter, r *http.Request) { 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 @@ func showontology(w http.ResponseWriter, r *http.Request) { 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 @@ func submithonker(w http.ResponseWriter, r *http.Request) { 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 @@ func submithonker(w http.ResponseWriter, r *http.Request) { 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 @@ func submithonker(w http.ResponseWriter, r *http.Request) { } if name == "" { - name = p.Handle + name = info.Name } _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) if err != nil { @@ -1549,7 +1557,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) { } if flavor == "presub" { user, _ := butwhatabout(u.Username) - go subsub(user, url) + go subsub(user, url, info.Owner) } http.Redirect(w, r, "/honkers", http.StatusSeeOther) }