take me off this list!!!

This commit is contained in:
Ted Unangst 2019-04-26 15:31:42 -04:00
parent 4da06786e9
commit 2a0c9e5082
3 changed files with 52 additions and 1 deletions

View File

@ -597,6 +597,33 @@ func rubadubdub(user *WhatAbout, req map[string]interface{}) {
stmtSaveDub.Exec(user.ID, actor, actor, "dub") 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) { func subsub(user *WhatAbout, xid string) {
j := NewJunk() j := NewJunk()
j["@context"] = itiswhatitis j["@context"] = itiswhatitis

25
honk.go
View File

@ -1017,6 +1017,29 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0) honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
if honkerid > 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) + " " combos = " " + strings.TrimSpace(combos) + " "
_, err := stmtUpdateHonker.Exec(combos, honkerid, u.UserID) _, err := stmtUpdateHonker.Exec(combos, honkerid, u.UserID)
if err != nil { if err != nil {
@ -1254,7 +1277,7 @@ func preparetodie(db *sql.DB, s string) *sql.Stmt {
} }
func prepareStatements(db *sql.DB) { 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 (?, ?, ?, ?, ?)") stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos) values (?, ?, ?, ?, ?)")
stmtUpdateHonker = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?") stmtUpdateHonker = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?")
stmtHasHonker = preparetodie(db, "select honkerid from honkers where xid = ? and userid = ?") stmtHasHonker = preparetodie(db, "select honkerid from honkers where xid = ? and userid = ?")

View File

@ -27,6 +27,7 @@
<input type="hidden" name="CSRF" value="{{ $honkercsrf }}"> <input type="hidden" name="CSRF" value="{{ $honkercsrf }}">
<input type="hidden" name="honkerid" value="{{ .ID }}"> <input type="hidden" name="honkerid" value="{{ .ID }}">
<p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}"> <p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}">
<p>depart: <input type="text" name="goodbye" value="" autocomplete=off> (say "goodbye")
<p><input type="submit" name="save" value="save"> <p><input type="submit" name="save" value="save">
</form> </form>
</div> </div>