all repos — honk @ ecde389a3ea23f4a45f1a3ab36d0ceaae3989f0b

my fork of honk

custom emus
Ted Unangst tedu@tedunangst.com
Fri, 12 Apr 2019 15:02:56 -0400
commit

ecde389a3ea23f4a45f1a3ab36d0ceaae3989f0b

parent

fd700453c2a28d7b4df6e971a956404ea7ae6bab

4 files changed, 84 insertions(+), 10 deletions(-)

jump to
M READMEREADME

@@ -8,6 +8,8 @@

Send honks. Receive honks. And not just honks. Bonk, donk, tonk, all your favorite activities are here. +Custom emus. + Purple color scheme. The button to submit a new honk says "it's gonna be honked".
M activity.goactivity.go

@@ -433,6 +433,20 @@ }

} } } + tags, _ := jsongetarray(obj, "tag") + for _, tag := range tags { + tt, _ := jsongetstring(tag, "type") + name, _ := jsongetstring(tag, "name") + if tt == "Emoji" { + icon, _ := jsongetmap(tag, "icon") + mt, _ := jsongetstring(icon, "mediaType") + u, _ := jsongetstring(icon, "url") + donk := savedonk(u, name, mt) + if donk != nil { + xonk.Donks = append(xonk.Donks, donk) + } + } + } } audience = append(audience, who)

@@ -534,16 +548,29 @@ if len(h.Audience) > 1 {

jo["cc"] = h.Audience[1:] } jo["content"] = h.Noise + var tags []interface{} g := bunchofgrapes(h.Noise) - if len(g) > 0 { - var tags []interface{} - for _, m := range g { - t := NewJunk() - t["type"] = "Mention" - t["name"] = m.who - t["href"] = m.where - tags = append(tags, t) - } + for _, m := range g { + t := NewJunk() + t["type"] = "Mention" + t["name"] = m.who + t["href"] = m.where + tags = append(tags, t) + } + herd := herdofemus(h.Noise) + for _, e := range herd { + t := NewJunk() + t["id"] = e.ID + t["type"] = "Emoji" + t["name"] = e.Name + i := NewJunk() + i["type"] = "Image" + i["mediaType"] = "image/png" + i["url"] = e.ID + t["icon"] = i + tags = append(tags, t) + } + if len(tags) > 0 { jo["tag"] = tags } var atts []interface{}
M honk.gohonk.go

@@ -156,7 +156,23 @@ if h.URL == "" {

h.URL = h.XID } } + zap := make(map[*Donk]bool) h.HTML = cleanstring(h.Noise) + emuxifier := func(e string) string { + for _, d := range h.Donks { + if d.Name == e { + zap[d] = true + return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID) + } + } + return e + } + h.HTML = template.HTML(re_emus.ReplaceAllStringFunc(string(h.HTML), emuxifier)) + for i := 0; i < len(h.Donks); i++ { + if zap[h.Donks[i]] { + h.Donks = append(h.Donks[0:i], h.Donks[i+1:]...) + } + } } }

@@ -798,7 +814,24 @@ }

return mentions } +type Emu struct { + ID string + Name string +} + var re_link = regexp.MustCompile(`https?://[^\s"]+[\w/)]`) +var re_emus = regexp.MustCompile(`:[[:alnum:]_]+:`) + +func herdofemus(noise string) []Emu { + m := re_emus.FindAllString(noise, -1) + var emus []Emu + for _, e := range m { + fname := e[1 : len(e)-1] + url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) + emus = append(emus, Emu{ID: url, Name: e}) + } + return emus +} func obfusbreak(s string) string { s = strings.TrimSpace(s)

@@ -1074,7 +1107,7 @@

func avatate(w http.ResponseWriter, r *http.Request) { n := r.FormValue("a") a := avatar(n) - w.Header().Set("Cache-Control", "max-age=76000") + w.Header().Set("Cache-Control", "max-age=432000") w.Write(a) }

@@ -1088,6 +1121,11 @@ err := readviews.ExecuteTemplate(w, r.URL.Path[1:]+".html", templinfo)

if err != nil { log.Print(err) } +} +func serveemu(w http.ResponseWriter, r *http.Request) { + xid := mux.Vars(r)["xid"] + w.Header().Set("Cache-Control", "max-age=432000") + http.ServeFile(w, r, "emus/"+xid) } func servefile(w http.ResponseWriter, r *http.Request) {

@@ -1145,6 +1183,7 @@ posters.HandleFunc("/u/{name:[[:alnum:]]+}/inbox", inbox)

getters.HandleFunc("/u/{name:[[:alnum:]]+}/outbox", outbox) getters.HandleFunc("/a", avatate) getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile) + getters.HandleFunc("/emu/{xid:[[:alnum:].]+}", serveemu) getters.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker) getters.HandleFunc("/.well-known/webfinger", fingerlicker)
M views/style.cssviews/style.css

@@ -144,3 +144,9 @@ }

img { max-width: 100% } +img.emu { + width: 1em; + height: 1em; + vertical-align: middle; + margin: -2px; +}