stepping stone for unbonk

This commit is contained in:
Ted Unangst 2019-08-23 20:43:30 -04:00
parent a9f0fad050
commit 9f9facba97
3 changed files with 29 additions and 5 deletions

23
honk.go
View File

@ -81,12 +81,17 @@ type Honk struct {
const (
flagIsAcked = 1
flagIsBonked = 2
)
func (honk *Honk) IsAcked() bool {
return honk.Flags&flagIsAcked != 0
}
func (honk *Honk) IsBonked() bool {
return honk.Flags&flagIsBonked != 0
}
type Donk struct {
FileID int64
XID string
@ -911,6 +916,11 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
}
donksforhonks([]*Honk{xonk})
_, err := stmtUpdateFlags.Exec(flagIsBonked, xonk.XID, userinfo.UserID)
if err != nil {
log.Printf("error acking bonk: %s", err)
}
oonker := xonk.Oonker
if oonker == "" {
oonker = xonk.Honker
@ -970,7 +980,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
user, _ := butwhatabout(userinfo.Username)
if wherefore == "ack" {
_, err := stmtUpdateFlags.Exec(flagIsAcked, what)
_, err := stmtUpdateFlags.Exec(flagIsAcked, what, userinfo.UserID)
if err != nil {
log.Printf("error acking: %s", err)
}
@ -982,7 +992,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
}
if wherefore == "deack" {
_, err := stmtClearFlags.Exec(flagIsAcked, what)
_, err := stmtClearFlags.Exec(flagIsAcked, what, userinfo.UserID)
if err != nil {
log.Printf("error deacking: %s", err)
}
@ -993,6 +1003,11 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
return
}
if wherefore == "unbonk" {
// todo
return
}
log.Printf("zonking %s %s", wherefore, what)
if wherefore == "zonk" {
xonk := getxonk(userinfo.UserID, what)
@ -1705,8 +1720,8 @@ func prepareStatements(db *sql.DB) {
stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)")
stmtDeleteXonker = preparetodie(db, "delete from xonkers where name = ? and flavor = ?")
stmtRecentHonkers = preparetodie(db, "select distinct(honker) from honks where userid = ? and honker not in (select xid from honkers where userid = ? and flavor = 'sub') order by honkid desc limit 100")
stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where xid = ?")
stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where xid = ?")
stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where xid = ? and userid = ?")
stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where xid = ? and userid = ?")
}
func ElaborateUnitTests() {

View File

@ -71,7 +71,11 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
<div>
<p>
{{ if .Honk.Public }}
{{ if .Honk.IsBonked }}
<button onclick="unbonk(this, '{{ .Honk.XID }}');">unbonk</button>
{{ else }}
<button onclick="bonk(this, '{{ .Honk.XID }}');">bonk</button>
{{ end }}
{{ else }}
<button disabled>nope</button>
{{ end }}

View File

@ -68,6 +68,11 @@ function bonk(el, xid) {
el.disabled = true
post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
}
function bonk(el, xid) {
el.innerHTML = "unbonked"
el.disabled = true
post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=unbonk&what=" + escape(xid))
}
function muteit(el, convoy) {
el.innerHTML = "muted"
el.disabled = true