summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go')
-rw-r--r--vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go b/vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go
index aeee9b38..f990c670 100644
--- a/vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go
+++ b/vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go
@@ -8,6 +8,7 @@ import (
"io"
"net/http"
"regexp"
+ "sort"
)
const (
@@ -15,7 +16,9 @@ const (
EMOJI_SORT_BY_NAME = "name"
)
-var EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_-]+:`)
+var EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_+-]+:`)
+
+var ReverseSystemEmojisMap = makeReverseEmojiMap()
type Emoji struct {
Id string `json:"id"`
@@ -36,6 +39,26 @@ func GetSystemEmojiId(emojiName string) (string, bool) {
return id, found
}
+func makeReverseEmojiMap() map[string][]string {
+ reverseEmojiMap := make(map[string][]string)
+ for key, value := range SystemEmojis {
+ emojiNames := reverseEmojiMap[value]
+ emojiNames = append(emojiNames, key)
+ sort.Strings(emojiNames)
+ reverseEmojiMap[value] = emojiNames
+ }
+
+ return reverseEmojiMap
+}
+
+func GetEmojiNameFromUnicode(unicode string) (emojiName string, count int) {
+ if emojiNames, found := ReverseSystemEmojisMap[unicode]; found {
+ return emojiNames[0], len(emojiNames)
+ }
+
+ return "", 0
+}
+
func (emoji *Emoji) IsValid() *AppError {
if !IsValidId(emoji.Id) {
return NewAppError("Emoji.IsValid", "model.emoji.id.app_error", nil, "", http.StatusBadRequest)
@@ -57,7 +80,7 @@ func (emoji *Emoji) IsValid() *AppError {
}
func IsValidEmojiName(name string) *AppError {
- if len(name) == 0 || len(name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(name, false) || inSystemEmoji(name) {
+ if name == "" || len(name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscorePlus(name) || inSystemEmoji(name) {
return NewAppError("Emoji.IsValid", "model.emoji.name.app_error", nil, "", http.StatusBadRequest)
}