allow tagging outside of content
Ted Unangst tedu@tedunangst.com
Sun, 30 Jul 2023 20:31:00 -0400
4 files changed,
45 insertions(+),
2 deletions(-)
M
activity.go
→
activity.go
@@ -1242,6 +1242,7 @@ }
if !h.Public { jo["directMessage"] = true } + h.Noise = re_retag.ReplaceAllString(h.Noise, "") translate(h) redoimages(h) if h.Precis != "" {
M
fun.go
→
fun.go
@@ -82,6 +82,7 @@ if h.Whofore == 2 || h.Whofore == 3 {
local = true } if local && h.What != "bonked" { + h.Noise = re_retag.ReplaceAllString(h.Noise, "") h.Noise = re_memes.ReplaceAllString(h.Noise, "") } h.Username, h.Handle = handles(h.Honker)@@ -124,10 +125,26 @@ }
h.Precis = demoji(h.Precis) h.Noise = demoji(h.Noise) h.Open = "open" + var misto string for _, m := range h.Mentions { if m.Where != h.Honker && !m.IsPresent(h.Noise) { - h.Noise = "(" + m.Who + ")" + h.Noise + misto += "(" + m.Who + ")" + } + } + var mistag string + for _, o := range h.Onts { + if !OntIsPresent(o, h.Noise) { + mistag += "(" + o + ")" } + } + if len(misto) > 0 || len(mistag) > 0 { + if len(misto) > 0 { + misto = misto + "<p>" + } + if len(mistag) > 0 { + mistag = "<p>" + mistag + } + h.Noise = misto + h.Noise + mistag } zap := make(map[string]bool)@@ -329,7 +346,7 @@ marker.AtLinker = attoreplacer
noise = strings.TrimSpace(noise) noise = marker.Mark(noise) honk.Noise = noise - honk.Onts = oneofakind(marker.HashTags) + honk.Onts = oneofakind(append(honk.Onts, marker.HashTags...)) honk.Mentions = bunchofgrapes(marker.Mentions) }@@ -438,6 +455,7 @@ var re_memes = regexp.MustCompile("meme: ?([^\n]+)")
var re_avatar = regexp.MustCompile("avatar: ?([^\n]+)") var re_banner = regexp.MustCompile("banner: ?([^\n]+)") var re_convoy = regexp.MustCompile("convoy: ?([^\n]+)") +var re_retag = regexp.MustCompile("tags: ?([^\n]+)") var re_convalidate = regexp.MustCompile("^(https?|tag|data):") func memetize(honk *Honk) {@@ -473,6 +491,24 @@ honk.Donks = append(honk.Donks, d)
return "" } honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl) +} + +func recategorize(honk *Honk) { + repl := func(x string) string { + x = x[5:] + for _, t := range strings.Split(x, " ") { + if t == "" { + continue + } + if t[0] != '#' { + t = "#" + t + } + dlog.Printf("hashtag: %s", t) + honk.Onts = append(honk.Onts, t) + } + return "" + } + honk.Noise = re_retag.ReplaceAllStringFunc(honk.Noise, repl) } var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]_]+([ \n:;.,']|$)")
M
honk.go
→
honk.go
@@ -144,6 +144,11 @@ }
return strings.Contains(noise, ">@"+nick) || strings.Contains(noise, "@<span>"+nick) } +func OntIsPresent(ont, noise string) bool { + ont = ont[1:] + return strings.Contains(noise, ">#"+ont) || strings.Contains(noise, "#<span>"+ont) +} + type OldRevision struct { Precis string Noise string