From 4dc2ada9443db330ca62faaa24b8946879e8c483 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 10 Oct 2019 18:48:03 -0400 Subject: [PATCH] we may need to expand short mentions more than once --- fun.go | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/fun.go b/fun.go index 72e6046..37e5a9b 100644 --- a/fun.go +++ b/fun.go @@ -329,27 +329,34 @@ func memetize(honk *Honk) { var re_quickmention = regexp.MustCompile("(^| )@[[:alnum:]]+ ") func quickrename(s string, userid int64) string { - return re_quickmention.ReplaceAllStringFunc(s, func(m string) string { - prefix := "" - if m[0] == ' ' { - prefix = " " - m = m[1:] - } - prefix += "@" - m = m[1:] - m = m[:len(m)-1] - - row := stmtOneHonker.QueryRow(m, userid) - var xid string - err := row.Scan(&xid) - if err == nil { - _, name := handles(xid) - if name != "" { - m = name + nonstop := true + for nonstop { + nonstop = false + s = re_quickmention.ReplaceAllStringFunc(s, func(m string) string { + log.Printf("m: %s", m) + prefix := "" + if m[0] == ' ' { + prefix = " " + m = m[1:] } - } - return prefix + m + " " - }) + prefix += "@" + m = m[1:] + m = m[:len(m)-1] + + row := stmtOneHonker.QueryRow(m, userid) + var xid string + err := row.Scan(&xid) + if err == nil { + _, name := handles(xid) + if name != "" { + nonstop = true + m = name + } + } + return prefix + m + " " + }) + } + return s } func mentionize(s string) string {