Merge pull request #725 from adamantike/misc/migrate-mailer-emoji-json-to-map
Convert mailer_emoji JSON file to map
This commit is contained in:
commit
5b7c500ca8
3 changed files with 1868 additions and 19 deletions
File diff suppressed because one or more lines are too long
1857
server/mailer_emoji_map.json
Normal file
1857
server/mailer_emoji_map.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,14 +4,15 @@ import (
|
||||||
_ "embed" // required by go:embed
|
_ "embed" // required by go:embed
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"heckel.io/ntfy/log"
|
|
||||||
"heckel.io/ntfy/util"
|
|
||||||
"mime"
|
"mime"
|
||||||
"net"
|
"net"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"heckel.io/ntfy/log"
|
||||||
|
"heckel.io/ntfy/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mailer interface {
|
type mailer interface {
|
||||||
|
@ -131,31 +132,23 @@ This message was sent by {ip} at {time} via {topicURL}`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed "mailer_emoji.json"
|
//go:embed "mailer_emoji_map.json"
|
||||||
emojisJSON string
|
emojisJSON string
|
||||||
)
|
)
|
||||||
|
|
||||||
type emoji struct {
|
|
||||||
Emoji string `json:"emoji"`
|
|
||||||
Aliases []string `json:"aliases"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func toEmojis(tags []string) (emojisOut []string, tagsOut []string, err error) {
|
func toEmojis(tags []string) (emojisOut []string, tagsOut []string, err error) {
|
||||||
var emojis []emoji
|
var emojiMap map[string]string
|
||||||
if err = json.Unmarshal([]byte(emojisJSON), &emojis); err != nil {
|
if err = json.Unmarshal([]byte(emojisJSON), &emojiMap); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
tagsOut = make([]string, 0)
|
tagsOut = make([]string, 0)
|
||||||
emojisOut = make([]string, 0)
|
emojisOut = make([]string, 0)
|
||||||
nextTag:
|
for _, t := range tags {
|
||||||
for _, t := range tags { // TODO Super inefficient; we should just create a .json file with a map
|
if emoji, ok := emojiMap[t]; ok {
|
||||||
for _, e := range emojis {
|
emojisOut = append(emojisOut, emoji)
|
||||||
if util.Contains(e.Aliases, t) {
|
} else {
|
||||||
emojisOut = append(emojisOut, e.Emoji)
|
|
||||||
continue nextTag
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tagsOut = append(tagsOut, t)
|
tagsOut = append(tagsOut, t)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue