Move the RegExp compilation into the package

This commit is contained in:
Alexander PapaTutuWawa
2020-04-15 23:28:13 +02:00
parent ba4b2ecfff
commit 089d00b47e

View File

@@ -6,12 +6,13 @@ import (
"github.com/42wim/matterbridge/bridge/config"
)
var pathRegex = regexp.MustCompile("[^a-zA-Z0-9]+")
// GetAvatar constructs a URL for a given user-avatar if it is available in the cache.
func getAvatar(av map[string]string, userid string, general *config.Protocol) string {
if hash, ok := av[userid]; ok {
// NOTE: This does not happen in bridge/helper/helper.go but messes up XMPP
reg := regexp.MustCompile("[^a-zA-Z0-9]+")
id := reg.ReplaceAllString(userid, "_")
id := pathRegex.ReplaceAllString(userid, "_")
return general.MediaServerDownload + "/" + hash + "/" + id + ".png"
}
return ""