@@ 595,6 595,22 @@ func shortname(userid UserID, xid string
return ""
}
+var evenshorternames = gencache.New(gencache.Options[UserID, map[string]int64]{Fill: func(userid UserID) (map[string]int64, bool) {
+ honkers := gethonkers(userid)
+ m := make(map[string]int64)
+ for _, h := range honkers {
+ m[h.XID] = h.ID
+ }
+ return m, true
+}, Invalidator: &honkerinvalidator})
+
+func evenshortername(userid UserID, xid string) int64 {
+ m, ok := evenshorternames.Get(userid)
+ if ok {
+ return m[xid]
+ }
+ return 0
+}
var fullnames = gencache.New(gencache.Options[UserID, map[string]string]{Fill: func(userid UserID) (map[string]string, bool) {
honkers := gethonkers(userid)
m := make(map[string]string)
@@ 946,25 946,37 @@ 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 {
+ honkerid := evenshortername(userid, xid)
+ miniform = templates.Sprintf(`<form action="/submithonker" method="POST">
+ <input type="hidden" name="CSRF" value="%s">
+ <input type="hidden" name="honkerid" value="%d">
+ <button tabindex=1 name="unsub" value="unsub">dehonk</button>
+ </form>`, login.GetCSRF("submithonker", r), honkerid)
+ }
+ 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)
@@ 2731,13 2743,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)