all repos — honk @ d5d1e19de1cd44b2de7efe60a525d317206a5acf

my fork of honk

translate known actors to shortnames
Ted Unangst tedu@tedunangst.com
Sat, 12 Oct 2019 10:34:23 -0400
commit

d5d1e19de1cd44b2de7efe60a525d317206a5acf

parent

e5e0a306fa1dfbcfb10c586cac46085ec94b02b3

2 files changed, 27 insertions(+), 3 deletions(-)

jump to
M fun.gofun.go

@@ -70,9 +70,14 @@ }

h.Username, h.Handle = handles(h.Honker) } else { _, h.Handle = handles(h.Honker) - h.Username = h.Handle - if len(h.Username) > 20 { - h.Username = h.Username[:20] + ".." + short := shortname(userid, h.Honker) + if short != "" { + h.Username = short + } else { + h.Username = h.Handle + if len(h.Username) > 20 { + h.Username = h.Username[:20] + ".." + } } if h.URL == "" { h.URL = h.XID

@@ -358,6 +363,24 @@ return prefix + m + " "

}) } return s +} + +var shortnames = cacheNew(cacheOptions{Filler: func(userid int64) (map[string]string, bool) { + honkers := gethonkers(userid) + m := make(map[string]string) + for _, h := range honkers { + m[h.XID] = h.Name + } + return m, true +}}) + +func shortname(userid int64, xid string) string { + var m map[string]string + ok := shortnames.Get(userid, &m) + if ok { + return m[xid] + } + return "" } func mentionize(s string) string {
M web.goweb.go

@@ -1271,6 +1271,7 @@ combos = " " + combos + " "

honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0) defer combocache.Clear(u.UserID) + defer shortnames.Clear(u.UserID) if honkerid > 0 { goodbye := r.FormValue("goodbye")