From 4dd8bae5c91fa4aef09d865d8fef1acd84f90925 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 17 Oct 2021 00:47:22 +0200 Subject: Update dependencies (#1610) * Update dependencies * Update module to go 1.17 --- .../mattermost/mattermost-server/v5/model/emoji.go | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/emoji.go') 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) } -- cgit v1.2.3