Use constants for NotifyProps keys. (#9901)

We have constants for (most) of the notify props keys. We should use
them consistently, instead of sometimes and other times having strings
scattered around the place.
Этот коммит содержится в:
George Goldberg
2018-11-28 16:11:41 +00:00
коммит произвёл Harrison Healey
родитель 1607d18e55
Коммит 09eae76c00
5 изменённых файлов: 50 добавлений и 47 удалений

Просмотреть файл

@@ -16,24 +16,27 @@ import (
)
const (
ME = "me"
USER_NOTIFY_ALL = "all"
USER_NOTIFY_MENTION = "mention"
USER_NOTIFY_NONE = "none"
DESKTOP_NOTIFY_PROP = "desktop"
DESKTOP_SOUND_NOTIFY_PROP = "desktop_sound"
MARK_UNREAD_NOTIFY_PROP = "mark_unread"
PUSH_NOTIFY_PROP = "push"
PUSH_STATUS_NOTIFY_PROP = "push_status"
EMAIL_NOTIFY_PROP = "email"
MOBILE_NOTIFY_PROP = "mobile"
MOBILE_PUSH_STATUS_NOTIFY_PROP = "mobile_push_status"
CHANNEL_MENTIONS_NOTIFY_PROP = "channel"
COMMENTS_NOTIFY_PROP = "comments"
MENTION_KEYS_NOTIFY_PROP = "mention_keys"
COMMENTS_NOTIFY_NEVER = "never"
COMMENTS_NOTIFY_ROOT = "root"
COMMENTS_NOTIFY_ANY = "any"
ME = "me"
USER_NOTIFY_ALL = "all"
USER_NOTIFY_MENTION = "mention"
USER_NOTIFY_NONE = "none"
DESKTOP_NOTIFY_PROP = "desktop"
DESKTOP_SOUND_NOTIFY_PROP = "desktop_sound"
MARK_UNREAD_NOTIFY_PROP = "mark_unread"
PUSH_NOTIFY_PROP = "push"
PUSH_STATUS_NOTIFY_PROP = "push_status"
EMAIL_NOTIFY_PROP = "email"
MOBILE_NOTIFY_PROP = "mobile"
MOBILE_PUSH_STATUS_NOTIFY_PROP = "mobile_push_status"
CHANNEL_MENTIONS_NOTIFY_PROP = "channel"
COMMENTS_NOTIFY_PROP = "comments"
MENTION_KEYS_NOTIFY_PROP = "mention_keys"
COMMENTS_NOTIFY_NEVER = "never"
COMMENTS_NOTIFY_ROOT = "root"
COMMENTS_NOTIFY_ANY = "any"
FIRST_NAME_NOTIFY_PROP = "first_name"
AUTO_RESPONDER_ACTIVE_NOTIFY_PROP = "auto_responder_active"
AUTO_RESPONDER_MESSAGE_NOTIFY_PROP = "auto_responder_message"
DEFAULT_LOCALE = "en"
USER_AUTH_SERVICE_EMAIL = "email"
@@ -249,44 +252,44 @@ func (u *User) PreUpdate() {
if u.NotifyProps == nil || len(u.NotifyProps) == 0 {
u.SetDefaultNotifications()
} else if _, ok := u.NotifyProps["mention_keys"]; ok {
} else if _, ok := u.NotifyProps[MENTION_KEYS_NOTIFY_PROP]; ok {
// Remove any blank mention keys
splitKeys := strings.Split(u.NotifyProps["mention_keys"], ",")
splitKeys := strings.Split(u.NotifyProps[MENTION_KEYS_NOTIFY_PROP], ",")
goodKeys := []string{}
for _, key := range splitKeys {
if len(key) > 0 {
goodKeys = append(goodKeys, strings.ToLower(key))
}
}
u.NotifyProps["mention_keys"] = strings.Join(goodKeys, ",")
u.NotifyProps[MENTION_KEYS_NOTIFY_PROP] = strings.Join(goodKeys, ",")
}
}
func (u *User) SetDefaultNotifications() {
u.NotifyProps = make(map[string]string)
u.NotifyProps["email"] = "true"
u.NotifyProps["push"] = USER_NOTIFY_MENTION
u.NotifyProps["desktop"] = USER_NOTIFY_MENTION
u.NotifyProps["desktop_sound"] = "true"
u.NotifyProps["mention_keys"] = u.Username + ",@" + u.Username
u.NotifyProps["channel"] = "true"
u.NotifyProps["push_status"] = STATUS_AWAY
u.NotifyProps["comments"] = "never"
u.NotifyProps["first_name"] = "false"
u.NotifyProps[EMAIL_NOTIFY_PROP] = "true"
u.NotifyProps[PUSH_NOTIFY_PROP] = USER_NOTIFY_MENTION
u.NotifyProps[DESKTOP_NOTIFY_PROP] = USER_NOTIFY_MENTION
u.NotifyProps[DESKTOP_SOUND_NOTIFY_PROP] = "true"
u.NotifyProps[MENTION_KEYS_NOTIFY_PROP] = u.Username + ",@" + u.Username
u.NotifyProps[CHANNEL_MENTIONS_NOTIFY_PROP] = "true"
u.NotifyProps[PUSH_STATUS_NOTIFY_PROP] = STATUS_AWAY
u.NotifyProps[COMMENTS_NOTIFY_PROP] = COMMENTS_NOTIFY_NEVER
u.NotifyProps[FIRST_NAME_NOTIFY_PROP] = "false"
}
func (user *User) UpdateMentionKeysFromUsername(oldUsername string) {
nonUsernameKeys := []string{}
splitKeys := strings.Split(user.NotifyProps["mention_keys"], ",")
splitKeys := strings.Split(user.NotifyProps[MENTION_KEYS_NOTIFY_PROP], ",")
for _, key := range splitKeys {
if key != oldUsername && key != "@"+oldUsername {
nonUsernameKeys = append(nonUsernameKeys, key)
}
}
user.NotifyProps["mention_keys"] = user.Username + ",@" + user.Username
user.NotifyProps[MENTION_KEYS_NOTIFY_PROP] = user.Username + ",@" + user.Username
if len(nonUsernameKeys) > 0 {
user.NotifyProps["mention_keys"] += "," + strings.Join(nonUsernameKeys, ",")
user.NotifyProps[MENTION_KEYS_NOTIFY_PROP] += "," + strings.Join(nonUsernameKeys, ",")
}
}