From 2a0c9e508259cb13eb1d3c2ee9a8438e364b59c4 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 26 Apr 2019 15:31:42 -0400 Subject: [PATCH] take me off this list!!! --- activity.go | 27 +++++++++++++++++++++++++++ honk.go | 25 ++++++++++++++++++++++++- views/honkers.html | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/activity.go b/activity.go index 4783a0b..b5713b2 100644 --- a/activity.go +++ b/activity.go @@ -597,6 +597,33 @@ func rubadubdub(user *WhatAbout, req map[string]interface{}) { stmtSaveDub.Exec(user.ID, actor, actor, "dub") } +func itakeitallback(user *WhatAbout, xid string) error { + j := NewJunk() + j["@context"] = itiswhatitis + j["id"] = user.URL + "/unsub/" + xid + j["type"] = "Undo" + j["actor"] = user.URL + j["to"] = xid + f := NewJunk() + f["id"] = user.URL + "/sub/" + xid + f["type"] = "Follow" + f["actor"] = user.URL + f["to"] = xid + 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 +} + func subsub(user *WhatAbout, xid string) { j := NewJunk() j["@context"] = itiswhatitis diff --git a/honk.go b/honk.go index 5110dfc..5e56db9 100644 --- a/honk.go +++ b/honk.go @@ -1017,6 +1017,29 @@ func savehonker(w http.ResponseWriter, r *http.Request) { honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0) if honkerid > 0 { + goodbye := r.FormValue("goodbye") + if goodbye == "goodbye" { + db := opendatabase() + row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", + honkerid, u.UserID) + var xid string + err := row.Scan(&xid) + if err != nil { + log.Printf("can't get honker xid: %s", err) + return + } + log.Printf("unsubscribing from %s", xid) + user, _ := butwhatabout(u.Username) + err = itakeitallback(user, xid) + if err != nil { + log.Printf("can't take it back: %s", err) + } else { + db.Exec("update honkers set flavor = 'unsub' where honkerid = ?", honkerid) + } + + http.Redirect(w, r, "/honkers", http.StatusSeeOther) + return + } combos = " " + strings.TrimSpace(combos) + " " _, err := stmtUpdateHonker.Exec(combos, honkerid, u.UserID) if err != nil { @@ -1254,7 +1277,7 @@ func preparetodie(db *sql.DB, s string) *sql.Stmt { } func prepareStatements(db *sql.DB) { - stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos from honkers where userid = ? and flavor = 'sub' or flavor = 'peep'") + stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'unsub') order by name") stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos) values (?, ?, ?, ?, ?)") stmtUpdateHonker = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?") stmtHasHonker = preparetodie(db, "select honkerid from honkers where xid = ? and userid = ?") diff --git a/views/honkers.html b/views/honkers.html index b9a105f..2b01500 100644 --- a/views/honkers.html +++ b/views/honkers.html @@ -27,6 +27,7 @@

combos: +

depart: (say "goodbye")