allow tagging outside of content

This commit is contained in:
Ted Unangst 2023-07-30 20:31:00 -04:00
parent d3bf2b7bc8
commit c57a52a90c
4 changed files with 45 additions and 2 deletions

View File

@ -1242,6 +1242,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
if !h.Public {
jo["directMessage"] = true
}
h.Noise = re_retag.ReplaceAllString(h.Noise, "")
translate(h)
redoimages(h)
if h.Precis != "" {

40
fun.go
View File

@ -82,6 +82,7 @@ func reverbolate(userid int64, honks []*Honk) {
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,11 +125,27 @@ func reverbolate(userid int64, honks []*Honk) {
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 @@ func translate(honk *Honk) {
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) {
@ -475,6 +493,24 @@ func memetize(honk *Honk) {
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:;.,']|$)")
func quickrename(s string, userid int64) string {

View File

@ -144,6 +144,11 @@ func (mention *Mention) IsPresent(noise string) bool {
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

1
web.go
View File

@ -1743,6 +1743,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
honk.Noise = noise
precipitate(honk)
noise = honk.Noise
recategorize(honk)
translate(honk)
if rid != "" {