all repos — honk @ a77d1a0786995ef808687f57d82ad004522431d5

my fork of honk

move mentions to mz module
Ted Unangst tedu@tedunangst.com
Mon, 20 Jul 2020 23:28:42 -0400
commit

a77d1a0786995ef808687f57d82ad004522431d5

parent

2dc7f9e7c627e1a2ae973ad9d429a993747d6543

3 files changed, 15 insertions(+), 36 deletions(-)

jump to
M activity.goactivity.go

@@ -1099,12 +1099,6 @@ }

if !h.Public { jo["directMessage"] = true } - var mentions []Mention - if len(h.Mentions) > 0 { - mentions = h.Mentions - } else { - mentions = bunchofgrapes(h.Noise) - } translate(h) redoimages(h) if h.Precis != "" {

@@ -1124,7 +1118,7 @@ jo["replies"] = jr

} var tags []junk.Junk - for _, m := range mentions { + for _, m := range h.Mentions { t := junk.New() t["type"] = "Mention" t["name"] = m.Who
M fun.gofun.go

@@ -33,8 +33,8 @@ "golang.org/x/net/html"

"humungus.tedunangst.com/r/webs/cache" "humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/httpsig" - "humungus.tedunangst.com/r/webs/templates" "humungus.tedunangst.com/r/webs/mz" + "humungus.tedunangst.com/r/webs/templates" ) var allowedclasses = make(map[string]bool)

@@ -68,7 +68,6 @@ local = true

} if local && h.What != "bonked" { h.Noise = re_memes.ReplaceAllString(h.Noise, "") - h.Noise = mentionize(h.Noise) } h.Username, h.Handle = handles(h.Honker) if !local {

@@ -238,10 +237,12 @@ honk.Precis = markitzero(strings.TrimSpace(honk.Precis))

var marker mz.Marker marker.HashLinker = ontoreplacer + marker.AtLinker = attoreplacer noise = strings.TrimSpace(noise) noise = marker.Mark(noise) honk.Noise = noise honk.Onts = oneofakind(marker.HashTags) + honk.Mentions = bunchofgrapes(marker.Mentions) } func redoimages(honk *Honk) {

@@ -265,7 +266,6 @@ }

honk.Donks = honk.Donks[:j] honk.Noise = re_memes.ReplaceAllString(honk.Noise, "") - honk.Noise = mentionize(honk.Noise) honk.Noise = strings.Replace(honk.Noise, "<a href=", "<a class=\"mention u-url\" href=", -1) }

@@ -290,9 +290,6 @@ rand.Read(b[:])

return xcelerate(b[:]) } -var re_mentions = regexp.MustCompile(`@[[:alnum:]._-]+@[[:alnum:].-]*[[:alnum:]]`) -var re_urltions = regexp.MustCompile(`@https://\S+`) - func grapevine(mentions []Mention) []string { var s []string for _, m := range mentions {

@@ -301,18 +298,13 @@ }

return s } -func bunchofgrapes(s string) []Mention { - m := re_mentions.FindAllString(s, -1) +func bunchofgrapes(m []string) []Mention { var mentions []Mention for i := range m { where := gofish(m[i]) if where != "" { mentions = append(mentions, Mention{Who: m[i], Where: where}) } - } - m = re_urltions.FindAllString(s, -1) - for i := range m { - mentions = append(mentions, Mention{Who: m[i][1:], Where: m[i][1:]}) } return mentions }

@@ -459,25 +451,19 @@ }

return "" } -func mentionize(s string) string { +func attoreplacer(m string) string { fill := `<span class="h-card"><a class="u-url mention" href="%s">%s</a></span>` - s = re_mentions.ReplaceAllStringFunc(s, func(m string) string { - where := gofish(m) - if where == "" { - return m - } - who := m[0 : 1+strings.IndexByte(m[1:], '@')] - return fmt.Sprintf(fill, html.EscapeString(where), html.EscapeString(who)) - }) - s = re_urltions.ReplaceAllStringFunc(s, func(m string) string { - return fmt.Sprintf(fill, html.EscapeString(m[1:]), html.EscapeString(m)) - }) - return s + where := gofish(m) + if where == "" { + return m + } + who := m[0 : 1+strings.IndexByte(m[1:], '@')] + return fmt.Sprintf(fill, html.EscapeString(where), html.EscapeString(who)) } func ontoreplacer(h string) string { return fmt.Sprintf(`<a href="https://%s/o/%s">%s</a>`, serverName, - strings.ToLower(h[1:]), h) + strings.ToLower(h[1:]), h) } var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)")
M web.goweb.go

@@ -1600,7 +1600,6 @@

noise = strings.Replace(noise, "\r", "", -1) noise = quickrename(noise, userinfo.UserID) noise = hooterize(noise) - honk.Mentions = bunchofgrapes(noise) honk.Noise = noise translate(honk)

@@ -1632,9 +1631,9 @@ } else {

honk.Audience = []string{thewholeworld} } if honk.Noise != "" && honk.Noise[0] == '@' { - honk.Audience = append(grapevine(bunchofgrapes(honk.Noise)), honk.Audience...) + honk.Audience = append(grapevine(honk.Mentions), honk.Audience...) } else { - honk.Audience = append(honk.Audience, grapevine(bunchofgrapes(honk.Noise))...) + honk.Audience = append(honk.Audience, grapevine(honk.Mentions)...) } if convoy == "" {