d652b081516c — Ted Unangst 2 months ago
need to preserve more info when dehonking
4 files changed, 14 insertions(+), 11 deletions(-)

M cli.go
M database.go
M fun.go
M web.go
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 fun.go +7 -6
@@ 595,22 595,23 @@ 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) {
+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]int64)
+	m := make(map[string]*Honker)
 	for _, h := range honkers {
-		m[h.XID] = h.ID
+		m[h.XID] = h
 	}
 	return m, true
 }, Invalidator: &honkerinvalidator})
 
-func evenshortername(userid UserID, xid string) int64 {
-	m, ok := evenshorternames.Get(userid)
+func gethonker(userid UserID, xid string) *Honker {
+	m, ok := honkerdirectory.Get(userid)
 	if ok {
 		return m[xid]
 	}
-	return 0
+	return nil
 }
+
 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)

          
M web.go +5 -3
@@ 948,7 948,7 @@ func showuser(w http.ResponseWriter, r *
 
 func honkerhat(userid UserID, xid string, r *http.Request) template.HTML {
 	var miniform template.HTML
-	sname := shortname(userid, xid); 
+	sname := shortname(userid, xid)
 	if sname == "" {
 		sname = xid
 		miniform = templates.Sprintf(`<form action="/submithonker" method="POST">

          
@@ 957,12 957,14 @@ func honkerhat(userid UserID, xid string
 		<button tabindex=1 name="add honker" value="add honker">add honker</button>
 		</form>`, login.GetCSRF("submithonker", r), xid)
 	} else {
-		honkerid := evenshortername(userid, xid)
+		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), honkerid)
+		</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