save obfuscated guesses

This commit is contained in:
Ted Unangst 2022-02-12 14:58:57 -05:00
parent f8c862275e
commit bbadb7e5a0
5 changed files with 17 additions and 2 deletions

View File

@ -480,6 +480,8 @@ func donksforhonks(honks []*Honk) {
} }
case "wonkles": case "wonkles":
h.Wonkles = j h.Wonkles = j
case "guesses":
h.Guesses = template.HTML(j)
case "oldrev": case "oldrev":
default: default:
elog.Printf("unknown meta genus: %s", genus) elog.Printf("unknown meta genus: %s", genus)
@ -896,6 +898,13 @@ func saveextras(tx *sql.Tx, h *Honk) error {
return err return err
} }
} }
if g := h.Guesses; g != "" {
_, err := tx.Stmt(stmtSaveMeta).Exec(h.ID, "guesses", g)
if err != nil {
elog.Printf("error saving guesses: %s", err)
return err
}
}
return nil return nil
} }

View File

@ -100,6 +100,7 @@ type Honk struct {
Mentions []Mention Mentions []Mention
Badonks []Badonk Badonks []Badonk
Wonkles string Wonkles string
Guesses template.HTML
} }
type Badonk struct { type Badonk struct {

View File

@ -92,7 +92,8 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
{{ if eq .Honk.What "wonked" }} {{ if eq .Honk.What "wonked" }}
<p> <p>
{{ if and $bonkcsrf .Honk.IsWonked }} {{ if and $bonkcsrf .Honk.IsWonked }}
{{ .Honk.Noise }} {{ .Honk.Guesses }}
<p>{{ .Honk.Noise }}
{{ else }} {{ else }}
<button onclick="return playit(this, '{{ .Honk.Noise }}', '{{ .Honk.Wonkles }}', '{{ .Honk.XID }}')">it's play time!</button> <button onclick="return playit(this, '{{ .Honk.Noise }}', '{{ .Honk.Wonkles }}', '{{ .Honk.XID }}')">it's play time!</button>
{{ end }} {{ end }}

View File

@ -74,7 +74,7 @@ export function makeaguess(btn) {
} }
div.innerHTML = mess div.innerHTML = mess
if (typeof(csrftoken) != "undefined") if (typeof(csrftoken) != "undefined")
post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "wonk", "what": host.xid})) post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "wonk", "guesses": host.guesses.join("<p>"), "what": host.xid}))
} else { } else {
div.innerHTML = "<p><input> <button onclick='return makeaguess(this)'>guess</button>" div.innerHTML = "<p><input> <button onclick='return makeaguess(this)'>guess</button>"
} }

4
web.go
View File

@ -1304,6 +1304,10 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
xonk := getxonk(userinfo.UserID, what) xonk := getxonk(userinfo.UserID, what)
if xonk != nil { if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsWonked, xonk.ID) _, err := stmtUpdateFlags.Exec(flagIsWonked, xonk.ID)
if err == nil {
guesses := r.FormValue("guesses")
_, err = stmtSaveMeta.Exec(xonk.ID, "guesses", guesses)
}
if err != nil { if err != nil {
elog.Printf("error saving: %s", err) elog.Printf("error saving: %s", err)
} }