allow resubscribing

This commit is contained in:
Ted Unangst 2019-10-06 21:33:10 -04:00
parent 029287af30
commit d5b99e2b9a
3 changed files with 37 additions and 6 deletions

View File

@ -922,6 +922,10 @@ func itakeitallback(user *WhatAbout, xid string) {
} }
func subsub(user *WhatAbout, xid string) { func subsub(user *WhatAbout, xid string) {
if xid == "" {
log.Printf("can't subscribe to empty")
return
}
j := junk.New() j := junk.New()
j["@context"] = itiswhatitis j["@context"] = itiswhatitis
j["id"] = user.URL + "/sub/" + url.QueryEscape(xid) j["id"] = user.URL + "/sub/" + url.QueryEscape(xid)

View File

@ -39,7 +39,11 @@ function expandstuff() {
<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" 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> <p><button name="save" value="save">save</button>
</form> </form>
</details> </details>

33
web.go
View File

@ -1183,20 +1183,43 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
db := opendatabase() db := opendatabase()
row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?",
honkerid, u.UserID) honkerid, u.UserID)
var xid string err := row.Scan(&url)
err := row.Scan(&xid)
if err != nil { if err != nil {
log.Printf("can't get honker xid: %s", err) log.Printf("can't get honker xid: %s", err)
return return
} }
log.Printf("unsubscribing from %s", xid) log.Printf("unsubscribing from %s", url)
user, _ := butwhatabout(u.Username) user, _ := butwhatabout(u.Username)
go itakeitallback(user, xid) _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, "sub")
_, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub")
if err != nil { if err != nil {
log.Printf("error updating honker: %s", err) log.Printf("error updating honker: %s", err)
return 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("resubscribing to %s", url)
user, _ := butwhatabout(u.Username)
_, 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) http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return return