Reuse mention regex

This makes the app less error-prone by avoiding a regexp.MustCompile()
call in the ActivityObject() method, saves CPU work, and reuses code.
pull/282/head
Matt Baer 5 years ago
parent 97aec9c158
commit ac522ed600
  1. 3
      posts.go

@ -1175,8 +1175,7 @@ func (p *PublicPost) ActivityObject(app *App) *activitystreams.Object {
stripper := bluemonday.StrictPolicy()
content := stripper.Sanitize(p.Content)
mentionRegex := regexp.MustCompile(`@[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\b`)
mentions := mentionRegex.FindAllString(content, -1)
mentions := mentionReg.FindAllString(content, -1)
for _, handle := range mentions {
actorIRI, err := app.db.GetProfilePageFromHandle(app, handle)

Loading…
Cancel
Save