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.
This commit is contained in:
Matt Baer 2020-03-17 13:43:25 -04:00
parent 97aec9c158
commit ac522ed600
1 changed files with 1 additions and 2 deletions

View File

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