# HG changeset patch # User Ted Unangst # Date 1728502357 14400 # Wed Oct 09 15:32:37 2024 -0400 # Node ID e78db3c308d5a000a0ad98700f2ccd3bbbf1d32d # Parent 17d9d1fbbc8e74f439d67e4d32f760cf423eaee0 add a dehonk button on honker page diff --git a/docs/changelog.txt b/docs/changelog.txt --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,5 +1,9 @@ changelog +### next + ++ Add dehonk button. + ### 1.4.1 Antiquated Automaton + Add back a scriptable init function. diff --git a/fun.go b/fun.go --- a/fun.go +++ b/fun.go @@ -595,6 +595,22 @@ 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) diff --git a/views/honkers.html b/views/honkers.html --- a/views/honkers.html +++ b/views/honkers.html @@ -35,7 +35,7 @@
avatar -

{{ .Name }} +

{{ .Name }}

diff --git a/web.go b/web.go --- a/web.go +++ b/web.go @@ -946,25 +946,37 @@ 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(`
+ + + +
`, login.GetCSRF("submithonker", r), xid) + } else { + honkerid := evenshortername(userid, xid) + miniform = templates.Sprintf(`
+ + + +
`, login.GetCSRF("submithonker", r), honkerid) + } + msg := templates.Sprintf(`honks by honker: %s%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(`
- - - -
`, login.GetCSRF("submithonker", r), name) - msg := templates.Sprintf(`honks by honker: %s%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 @@ case "honker": xid := r.FormValue("xid") honks = gethonksbyxonker(userid, xid, wanted) - miniform := templates.Sprintf(`
- - - -
`, login.GetCSRF("submithonker", r), xid) - msg := templates.Sprintf(`honks by honker: %s%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)