From d76dc7bf98fc96b1400b4a173ba87d5533141af5 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 10 Jun 2019 23:57:03 -0400 Subject: [PATCH] rework all the follow stuff a bit --- activity.go | 46 ++++++++++++++-------------------------------- honk.go | 15 ++++++--------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/activity.go b/activity.go index b2fdddf..2d497fb 100644 --- a/activity.go +++ b/activity.go @@ -648,32 +648,24 @@ func xonkxonk(user *WhatAbout, item interface{}, origin string) *Honk { func rubadubdub(user *WhatAbout, req map[string]interface{}) { xid, _ := jsongetstring(req, "id") - reqactor, _ := jsongetstring(req, "actor") + actor, _ := jsongetstring(req, "actor") j := NewJunk() j["@context"] = itiswhatitis j["id"] = user.URL + "/dub/" + xid j["type"] = "Accept" j["actor"] = user.URL - j["to"] = reqactor + j["to"] = actor j["published"] = time.Now().UTC().Format(time.RFC3339) j["object"] = req - actor, _ := jsongetstring(req, "actor") - box, err := getboxes(actor) - if err != nil { - log.Printf("can't get dub box: %s", err) - return - } - keyname, key := ziggy(user.Name) - err = PostJunk(keyname, key, box.In, j) - if err != nil { - log.Printf("can't rub a dub: %s", err) - return - } - stmtSaveDub.Exec(user.ID, actor, actor, "dub") + var buf bytes.Buffer + WriteJunk(&buf, j) + msg := buf.Bytes() + + deliverate(0, user.Name, actor, msg) } -func itakeitallback(user *WhatAbout, xid string) error { +func itakeitallback(user *WhatAbout, xid string) { j := NewJunk() j["@context"] = itiswhatitis j["id"] = user.URL + "/unsub/" + xid @@ -688,16 +680,11 @@ func itakeitallback(user *WhatAbout, xid string) error { j["object"] = f j["published"] = time.Now().UTC().Format(time.RFC3339) - box, err := getboxes(xid) - if err != nil { - return err - } - keyname, key := ziggy(user.Name) - err = PostJunk(keyname, key, box.In, j) - if err != nil { - return err - } - return nil + var buf bytes.Buffer + WriteJunk(&buf, j) + msg := buf.Bytes() + + deliverate(0, user.Name, xid, msg) } func subsub(user *WhatAbout, xid string) { @@ -710,16 +697,11 @@ func subsub(user *WhatAbout, xid string) { j["object"] = xid j["published"] = time.Now().UTC().Format(time.RFC3339) - a := xid - box, _ := getboxes(xid) - if box != nil { - a = "%" + box.In - } var buf bytes.Buffer WriteJunk(&buf, j) msg := buf.Bytes() - deliverate(0, user.Name, a, msg) + deliverate(0, user.Name, xid, msg) } func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]interface{}) { diff --git a/honk.go b/honk.go index e8bf09b..3ab02bd 100644 --- a/honk.go +++ b/honk.go @@ -328,7 +328,8 @@ func inbox(w http.ResponseWriter, r *http.Request) { obj, _ := jsongetstring(j, "object") if obj == user.URL { log.Printf("updating honker follow: %s", who) - rubadubdub(user, j) + stmtSaveDub.Exec(user.ID, who, who, "dub") + go rubadubdub(user, j) } else { log.Printf("can't follow %s", obj) } @@ -1052,15 +1053,11 @@ func savehonker(w http.ResponseWriter, r *http.Request) { } log.Printf("unsubscribing from %s", xid) user, _ := butwhatabout(u.Username) - err = itakeitallback(user, xid) + go itakeitallback(user, xid) + _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub") if err != nil { - log.Printf("can't take it back: %s", err) - } else { - _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub") - if err != nil { - log.Printf("error updating honker: %s", err) - return - } + log.Printf("error updating honker: %s", err) + return } http.Redirect(w, r, "/honkers", http.StatusSeeOther)