From a3fdc78c5c31830465e619056c420c59142510f0 Mon Sep 17 00:00:00 2001 From: m15o Date: Thu, 24 Feb 2022 15:44:58 +0100 Subject: [PATCH] Now possible to @ someone --- model/status.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/model/status.go b/model/status.go index a178027..244c9d0 100644 --- a/model/status.go +++ b/model/status.go @@ -19,6 +19,7 @@ type Status struct { } var urlRegexp = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`) +var userRegexp = regexp.MustCompile(`@([a-z0-9-_]+)\b`) func (s Status) ContentDisplay() string { content := html.EscapeString(s.Content) @@ -29,6 +30,12 @@ func (s Status) ContentDisplay() string { content = strings.Replace(content, url, fmt.Sprintf("%s", url, url), 1) } } + if userRegexp.MatchString(s.Content) { + matches := userRegexp.FindAllStringSubmatch(s.Content, -1) + for _, m := range matches { + content = strings.Replace(content, m[0], fmt.Sprintf("%s", m[1], m[0]), 1) + } + } return content }