rework how sub/unsub works, and add delete to honkers

This commit is contained in:
Ted Unangst 2020-11-25 22:03:46 -05:00
parent 7eaa6e3519
commit a176bbb2f0
3 changed files with 13 additions and 11 deletions

View File

@ -901,6 +901,7 @@ func cleanupdb(arg string) {
} }
var stmtHonkers, stmtDubbers, stmtNamedDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker *sql.Stmt var stmtHonkers, stmtDubbers, stmtNamedDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker *sql.Stmt
var stmtDeleteHonker *sql.Stmt
var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt
var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt
var stmtHonksFromLongAgo *sql.Stmt var stmtHonksFromLongAgo *sql.Stmt
@ -931,6 +932,7 @@ func prepareStatements(db *sql.DB) {
stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, ?, ?, ?, '')") stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, ?, ?, ?, '')")
stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ?, folxid = ? where userid = ? and name = ? and xid = ? and flavor = ?") stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ?, folxid = ? where userid = ? and name = ? and xid = ? and flavor = ?")
stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ?, meta = ? where honkerid = ? and userid = ?") stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ?, meta = ? where honkerid = ? and userid = ?")
stmtDeleteHonker = preparetodie(db, "delete from honkers where honkerid = ?")
stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?") stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?")
stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'")
stmtNamedDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and name = ? and flavor = 'dub'") stmtNamedDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and name = ? and flavor = 'dub'")

View File

@ -48,12 +48,11 @@ function expandstuff() {
<p><label for="notes">notes:</label><br> <p><label for="notes">notes:</label><br>
<textarea name="notes">{{ .Meta.Notes }}</textarea> <textarea name="notes">{{ .Meta.Notes }}</textarea>
<p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}"> <p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}">
{{ if eq .Flavor "sub" }} <p>
<p>unsub: <input type="text" name="goodbye" placeholder="press F" value="" autocomplete=off> <button name="save" value="save">save</button>
{{ else }} <button name="sub" value="sub">(re)sub</button>
<p>(re)sub: <input type="text" name="goodbye" placeholder="press X" value="" autocomplete=off> <button name="unsub" value="unsub">unsub</button>
{{ end }} <button name="delete" value="delete">delete</button>
<p><button name="save" value="save">save</button>
</form> </form>
</details> </details>
<p> <p>

11
web.go
View File

@ -1852,16 +1852,17 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
defer honkerinvalidator.Clear(u.UserID) defer honkerinvalidator.Clear(u.UserID)
if honkerid > 0 { if honkerid > 0 {
goodbye := r.FormValue("goodbye") if r.FormValue("delete") == "delete" {
if goodbye == "F" {
unfollowyou(user, honkerid) unfollowyou(user, honkerid)
stmtDeleteHonker.Exec(honkerid)
http.Redirect(w, r, "/honkers", http.StatusSeeOther) http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return return
} }
if goodbye == "X" { if r.FormValue("unsub") == "unsub" {
unfollowyou(user, honkerid)
}
if r.FormValue("sub") == "sub" {
followyou(user, honkerid) followyou(user, honkerid)
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return
} }
_, err := stmtUpdateHonker.Exec(name, combos, mj, honkerid, u.UserID) _, err := stmtUpdateHonker.Exec(name, combos, mj, honkerid, u.UserID)
if err != nil { if err != nil {