Now possible to @ someone

This commit is contained in:
m15o 2022-02-24 15:44:58 +01:00
parent e79e1fdf45
commit a3fdc78c5c

View file

@ -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("<a href=\"%s\" target=\"_blank\">%s</a>", 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("<a href=\"https://status.cafe/users/%s\" target=\"_blank\">%s</a>", m[1], m[0]), 1)
}
}
return content
}