From f472979b2dfc3bd6955dd4949c912db7e2285e70 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 12 Apr 2019 15:02:56 -0400 Subject: [PATCH] custom emus --- README | 2 ++ activity.go | 45 ++++++++++++++++++++++++++++++++++++--------- honk.go | 41 ++++++++++++++++++++++++++++++++++++++++- views/style.css | 6 ++++++ 4 files changed, 84 insertions(+), 10 deletions(-) diff --git a/README b/README index 23606f6..977cd50 100644 --- a/README +++ b/README @@ -8,6 +8,8 @@ evil empire. 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". diff --git a/activity.go b/activity.go index 7c09503..52fba2b 100644 --- a/activity.go +++ b/activity.go @@ -433,6 +433,20 @@ func xonkxonk(item interface{}) *Honk { } } } + 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 @@ func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]inte 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{} diff --git a/honk.go b/honk.go index 24a727c..5805a81 100644 --- a/honk.go +++ b/honk.go @@ -156,7 +156,23 @@ func reverbolate(honks []*Honk) { 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(``, 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 @@ func bunchofgrapes(s string) []Mention { 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 savehonker(w http.ResponseWriter, r *http.Request) { 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) } @@ -1089,6 +1122,11 @@ func servehtml(w http.ResponseWriter, r *http.Request) { 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) { xid := mux.Vars(r)["xid"] @@ -1145,6 +1183,7 @@ func serve() { 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) diff --git a/views/style.css b/views/style.css index d3aaa29..64fe496 100644 --- a/views/style.css +++ b/views/style.css @@ -144,3 +144,9 @@ button a { img { max-width: 100% } +img.emu { + width: 1em; + height: 1em; + vertical-align: middle; + margin: -2px; +}