allow resubscribing
Ted Unangst tedu@tedunangst.com
Sun, 06 Oct 2019 21:33:10 -0400
3 files changed,
37 insertions(+),
6 deletions(-)
M
activity.go
→
activity.go
@@ -922,6 +922,10 @@ deliverate(0, user.Name, xid, msg)
} func subsub(user *WhatAbout, xid string) { + if xid == "" { + log.Printf("can't subscribe to empty") + return + } j := junk.New() j["@context"] = itiswhatitis j["id"] = user.URL + "/sub/" + url.QueryEscape(xid)
M
views/honkers.html
→
views/honkers.html
@@ -39,7 +39,11 @@ <form action="/submithonker" method="POST">
<input type="hidden" name="CSRF" value="{{ $honkercsrf }}"> <input type="hidden" name="honkerid" value="{{ .ID }}"> <p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}"> -<p>depart: <input type="text" name="goodbye" placeholder="press F" value="" autocomplete=off> +{{ if eq .Flavor "sub" }} +<p>unsub: <input type="text" name="goodbye" placeholder="press F" value="" autocomplete=off> +{{ else }} +<p>resub: <input type="text" name="goodbye" placeholder="press X" value="" autocomplete=off> +{{ end }} <p><button name="save" value="save">save</button> </form> </details>
M
web.go
→
web.go
@@ -1183,20 +1183,43 @@ if goodbye == "F" {
db := opendatabase() row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", honkerid, u.UserID) - var xid string - err := row.Scan(&xid) + err := row.Scan(&url) + if err != nil { + log.Printf("can't get honker xid: %s", err) + return + } + log.Printf("unsubscribing from %s", url) + user, _ := butwhatabout(u.Username) + _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, "sub") + if err != nil { + log.Printf("error updating honker: %s", err) + return + } + go itakeitallback(user, url) + + http.Redirect(w, r, "/honkers", http.StatusSeeOther) + return + } + if goodbye == "X" { + db := opendatabase() + row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", + honkerid, u.UserID) + err := row.Scan(&url) if err != nil { log.Printf("can't get honker xid: %s", err) return } - log.Printf("unsubscribing from %s", xid) + log.Printf("resubscribing to %s", url) user, _ := butwhatabout(u.Username) - go itakeitallback(user, xid) - _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub") + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, "unsub") + if err == nil { + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, "peep") + } if err != nil { log.Printf("error updating honker: %s", err) return } + go subsub(user, url) http.Redirect(w, r, "/honkers", http.StatusSeeOther) return