some code towards enabling following a collection
This commit is contained in:
parent
4ee177e157
commit
58292a808c
59
activity.go
59
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
6
fun.go
6
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 {
|
||||
|
|
13
honk.go
13
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
|
||||
|
|
24
web.go
24
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue