Fixed MM-33249 issue (#17475)
* Added logic to detect and set unicode emoji in the custom status slash command * Replaced strings.split with strings.Fields * Added logic to handle empty string as message in custom status slash command * Changed custom status slash command empty message behavior to set def… (#14) * Changed custom status slash command empty message behavior to set default emoji * Code refactoring * Added unit tests and refactored some code * WIP: Unit tests and refactoring for detecting unicode emoji in custom status slash commands * Complete unit testing for Get custom status * Fixed lint * Added logic for removing skin tone from unicode emoji (#16) * Added logic for removing skin tone from unicode emoji Made a reverse system emojis map of string vs []string and stored the emojiNames in sorted order Added the logic for detecting and replacing/removing skin tone in unicode emoji with variation selector Added new unit tests with different skin tone emojis * Refactored removeSkinTone logic to a separate function * Added check for emoji before removing skin tone in custom status slash command * Fixed custom status slash command unit test and refactored some code Chanded the return type of GetEmojiNameFromUnicode from bool to int Changed the logic for checking presence of emoji without removing skin tone Fixed the unit tests * Review fixes: Indentation changes
Этот коммит содержится в:
@@ -5,6 +5,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -39,6 +40,10 @@ func CustomStatusFromJson(data io.Reader) *CustomStatus {
|
||||
return cs
|
||||
}
|
||||
|
||||
func RuneToHexadecimalString(r rune) string {
|
||||
return fmt.Sprintf("%04x", r)
|
||||
}
|
||||
|
||||
type RecentCustomStatuses []CustomStatus
|
||||
|
||||
func (rcs *RecentCustomStatuses) Contains(cs *CustomStatus) bool {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,6 +24,8 @@ var EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_-]+:`)
|
||||
// TODO: Merge ALL_EMOJI_PATTERN with EMOJI_PATTERN after updating custom emoji help texts
|
||||
var ALL_EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_+-]+:`)
|
||||
|
||||
var ReverseSystemEmojisMap = makeReverseEmojiMap()
|
||||
|
||||
type Emoji struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
@@ -42,6 +45,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)
|
||||
|
||||
Ссылка в новой задаче
Block a user