M cli.go +1 -1
@@ 152,7 152,7 @@ var commands = map[string]cmd{
errx("user not found")
}
- honkerid, err := gethonker(user.ID, args[2])
+ honkerid, err := findhonkerid(user.ID, args[2])
if err != nil {
errx("sorry couldn't find them")
}
M database.go +1 -1
@@ 103,7 103,7 @@ func getserveruser() *WhatAbout {
return user
}
-func gethonker(userid UserID, xid string) (int64, error) {
+func findhonkerid(userid UserID, xid string) (int64, error) {
row := opendatabase().
QueryRow("select honkerid from honkers where xid = ? and userid = ? and flavor in ('sub')", xid, userid)
var honkerid int64
M docs/changelog.txt +4 -0
@@ 1,5 1,9 @@
changelog
+### next
+
++ Add dehonk button.
+
### 1.4.1 Antiquated Automaton
+ Add back a scriptable init function.
M fun.go +11 -5
@@ 582,20 582,26 @@ func quickrename(s string, userid UserID
return s
}
-var shortnames = gencache.New(gencache.Options[UserID, map[string]string]{Fill: func(userid UserID) (map[string]string, bool) {
+var honkerdirectory = gencache.New(gencache.Options[UserID, map[string]*Honker]{Fill: func(userid UserID) (map[string]*Honker, bool) {
honkers := gethonkers(userid)
- m := make(map[string]string)
+ m := make(map[string]*Honker)
for _, h := range honkers {
- m[h.XID] = h.Name
+ m[h.XID] = h
}
return m, true
}, Invalidator: &honkerinvalidator})
-func shortname(userid UserID, xid string) string {
- m, ok := shortnames.Get(userid)
+func gethonker(userid UserID, xid string) *Honker {
+ m, ok := honkerdirectory.Get(userid)
if ok {
return m[xid]
}
+ return nil
+}
+func shortname(userid UserID, xid string) string {
+ if h := gethonker(userid, xid); h != nil {
+ return h.Name
+ }
return ""
}
M views/honkers.html +1 -1
@@ 35,7 35,7 @@
<section class="honk">
<header>
<img alt="avatar" src="/a?a={{ .XID }}" loading="lazy">
-<p class="font18em"><a href="/h/{{ .Name }}">{{ .Name }}</a>
+<p class="font18em"><a href="/h?xid={{ .XID }}">{{ .Name }}</a>
</header>
<p>
<details>
M web.go +30 -22
@@ 949,25 949,39 @@ func showuser(w http.ResponseWriter, r *
honkpage(w, u, honks, templinfo)
}
+func honkerhat(userid UserID, xid string, r *http.Request) template.HTML {
+ var miniform template.HTML
+ sname := shortname(userid, xid)
+ if sname == "" {
+ sname = xid
+ miniform = templates.Sprintf(`<form action="/submithonker" method="POST">
+ <input type="hidden" name="CSRF" value="%s">
+ <input type="hidden" name="url" value="%s">
+ <button tabindex=1 name="add honker" value="add honker">add honker</button>
+ </form>`, login.GetCSRF("submithonker", r), xid)
+ } else {
+ honker := gethonker(userid, xid)
+ miniform = templates.Sprintf(`<form action="/submithonker" method="POST">
+ <input type="hidden" name="CSRF" value="%s">
+ <input type="hidden" name="honkerid" value="%d">
+ <input type="hidden" name="name" value="%s">
+ <input type="hidden" name="notes" value="%s">
+ <button tabindex=1 name="unsub" value="unsub">dehonk</button>
+ </form>`, login.GetCSRF("submithonker", r), honker.ID, honker.Name, honker.Meta.Notes)
+ }
+ msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>%s`, xid, sname, miniform)
+ return msg
+}
+
func showhonker(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
- name := mux.Vars(r)["name"]
- var honks []*Honk
- if name == "" {
- name = r.FormValue("xid")
- honks = gethonksbyxonker(UserID(u.UserID), name, 0)
- } else {
- honks = gethonksbyhonker(UserID(u.UserID), name, 0)
- }
- miniform := templates.Sprintf(`<form action="/submithonker" method="POST">
-<input type="hidden" name="CSRF" value="%s">
-<input type="hidden" name="url" value="%s">
-<button tabindex=1 name="add honker" value="add honker">add honker</button>
-</form>`, login.GetCSRF("submithonker", r), name)
- msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>%s`, name, name, miniform)
+ var userid = UserID(u.UserID)
+ xid := r.FormValue("xid")
+ honks := gethonksbyxonker(userid, xid, 0)
+ msg := honkerhat(userid, xid, r)
templinfo := getInfo(r)
templinfo["PageName"] = "honker"
- templinfo["PageArg"] = name
+ templinfo["PageArg"] = xid
templinfo["ServerMessage"] = msg
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
@@ 2881,13 2895,7 @@ func webhydra(w http.ResponseWriter, r *
case "honker":
xid := r.FormValue("xid")
honks = gethonksbyxonker(userid, xid, wanted)
- miniform := templates.Sprintf(`<form action="/submithonker" method="POST">
- <input type="hidden" name="CSRF" value="%s">
- <input type="hidden" name="url" value="%s">
- <button tabindex=1 name="add honker" value="add honker">add honker</button>
- </form>`, login.GetCSRF("submithonker", r), xid)
- msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>%s`, xid, xid, miniform)
- hydra.Srvmsg = msg
+ hydra.Srvmsg = honkerhat(userid, xid, r)
case "user":
uname := r.FormValue("uname")
honks = gethonksbyuser(uname, u != nil && u.Username == uname, wanted)