diff --git a/activity.go b/activity.go index 3953842..4992abd 100644 --- a/activity.go +++ b/activity.go @@ -1035,8 +1035,6 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { } translate(h) redoimages(h) - jo["summary"] = html.EscapeString(h.Precis) - jo["content"] = h.Noise if h.Precis != "" { jo["sensitive"] = true } @@ -1081,6 +1079,18 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { t["icon"] = i tags = append(tags, t) } + for _, e := range bloat_fixupflags(h) { + t := junk.New() + t["id"] = e.ID + t["type"] = "Emoji" + t["name"] = e.Name + i := junk.New() + 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 } @@ -1123,6 +1133,8 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { if len(atts) > 0 { jo["attachment"] = atts } + jo["summary"] = html.EscapeString(h.Precis) + jo["content"] = h.Noise j["object"] = jo case "bonk": j["type"] = "Announce" diff --git a/bloat.go b/bloat.go index e89675f..e927a27 100644 --- a/bloat.go +++ b/bloat.go @@ -14,3 +14,68 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. package main + +import ( + "fmt" + "regexp" + "image" + "image/png" + "net/http" + "strconv" + "strings" + + "github.com/gorilla/mux" +) + +func bloat_showflag(writer http.ResponseWriter, req *http.Request) { + code := mux.Vars(req)["code"] + colors := strings.Split(code, ",") + numcolors := len(colors) + h := (128 / numcolors) * numcolors + w := h * 3 / 2 + img := image.NewRGBA(image.Rect(0, 0, w, h)) + for i := 0; i < h; i++ { + hex := colors[i*numcolors/h] + if len(hex) == 3 { + hex = fmt.Sprintf("%c%c%c%c%c%c", + hex[0], hex[0], hex[1], hex[1], hex[2], hex[2]) + } + c, _ := strconv.ParseUint(hex, 16, 32) + r := byte(c >> 16 & 0xff) + g := byte(c >> 8 & 0xff) + b := byte(c >> 0 & 0xff) + for j := 0; j < w; j++ { + p := i*img.Stride + j*4 + img.Pix[p+0] = r + img.Pix[p+1] = g + img.Pix[p+2] = b + img.Pix[p+3] = 255 + } + } + png.Encode(writer, img) +} + +var re_flags = regexp.MustCompile("flag:[[:alnum:],]+") + +func bloat_fixupflags(h *Honk) []Emu { + var emus []Emu + count := 0 + h.Noise = re_flags.ReplaceAllStringFunc(h.Noise, func(m string) string { + count++ + var e Emu + e.Name = fmt.Sprintf(":flag%d:", count) + e.ID = fmt.Sprintf("https://%s/flag/%s", serverName, m[5:]) + emus = append(emus, e) + return e.Name + }) + return emus +} + +func bloat_renderflags(h *Honk) { + h.Noise = re_flags.ReplaceAllStringFunc(h.Noise, func(m string) string { + code := m[5:] + src := fmt.Sprintf("https://%s/flag/%s", serverName, code) + return fmt.Sprintf(``, "flag", src) + }) +} + diff --git a/fun.go b/fun.go index 2ec4d99..40ba38e 100644 --- a/fun.go +++ b/fun.go @@ -139,6 +139,7 @@ func reverbolate(userid int64, honks []*Honk) { } return e } + bloat_renderflags(h) h.Precis = re_emus.ReplaceAllStringFunc(h.Precis, emuxifier) h.Noise = re_emus.ReplaceAllStringFunc(h.Noise, emuxifier) diff --git a/web.go b/web.go index c5ad083..84def27 100644 --- a/web.go +++ b/web.go @@ -2418,6 +2418,8 @@ func serve() { getters.HandleFunc("/meme/{meme:[^.]*[^/]+}", servememe) getters.HandleFunc("/.well-known/webfinger", fingerlicker) + getters.HandleFunc("/flag/{code:.+}", bloat_showflag) + getters.HandleFunc("/server", serveractor) posters.HandleFunc("/server/inbox", serverinbox) posters.HandleFunc("/inbox", serverinbox)