summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--model/user.go23
-rw-r--r--model/user_test.go27
-rw-r--r--store/sql_user_store.go9
-rw-r--r--webapp/utils/text_formatting.jsx1
4 files changed, 47 insertions, 13 deletions
diff --git a/model/user.go b/model/user.go
index f43fc2089..7563de8ae 100644
--- a/model/user.go
+++ b/model/user.go
@@ -186,13 +186,28 @@ func (u *User) SetDefaultNotifications() {
u.NotifyProps["desktop"] = USER_NOTIFY_ALL
u.NotifyProps["desktop_sound"] = "true"
u.NotifyProps["mention_keys"] = u.Username + ",@" + u.Username
- u.NotifyProps["first_name"] = "false"
u.NotifyProps["all"] = "true"
u.NotifyProps["channel"] = "true"
- splitName := strings.Split(u.Nickname, " ")
- if len(splitName) > 0 && splitName[0] != "" {
+
+ if u.FirstName == "" {
+ u.NotifyProps["first_name"] = "false"
+ } else {
u.NotifyProps["first_name"] = "true"
- u.NotifyProps["mention_keys"] += "," + splitName[0]
+ }
+}
+
+func (user *User) UpdateMentionKeysFromUsername(oldUsername string) {
+ nonUsernameKeys := []string{}
+ splitKeys := strings.Split(user.NotifyProps["mention_keys"], ",")
+ for _, key := range splitKeys {
+ if key != oldUsername && key != "@"+oldUsername {
+ nonUsernameKeys = append(nonUsernameKeys, key)
+ }
+ }
+
+ user.NotifyProps["mention_keys"] = user.Username + ",@" + user.Username
+ if len(nonUsernameKeys) > 0 {
+ user.NotifyProps["mention_keys"] += "," + strings.Join(nonUsernameKeys, ",")
}
}
diff --git a/model/user_test.go b/model/user_test.go
index 286c92a66..c6f7dfecc 100644
--- a/model/user_test.go
+++ b/model/user_test.go
@@ -41,6 +41,33 @@ func TestUserPreUpdate(t *testing.T) {
user.PreUpdate()
}
+func TestUserUpdateMentionKeysFromUsername(t *testing.T) {
+ user := User{Username: "user"}
+ user.SetDefaultNotifications()
+
+ if user.NotifyProps["mention_keys"] != "user,@user" {
+ t.Fatal("default mention keys are invalid: %v", user.NotifyProps["mention_keys"])
+ }
+
+ user.Username = "person"
+ user.UpdateMentionKeysFromUsername("user")
+ if user.NotifyProps["mention_keys"] != "person,@person" {
+ t.Fatal("mention keys are invalid after changing username: %v", user.NotifyProps["mention_keys"])
+ }
+
+ user.NotifyProps["mention_keys"] += ",mention"
+ user.UpdateMentionKeysFromUsername("person")
+ if user.NotifyProps["mention_keys"] != "person,@person,mention" {
+ t.Fatal("mention keys are invalid after adding extra mention keyword: %v", user.NotifyProps["mention_keys"])
+ }
+
+ user.Username = "user"
+ user.UpdateMentionKeysFromUsername("person")
+ if user.NotifyProps["mention_keys"] != "user,@user,mention" {
+ t.Fatal("mention keys are invalid after changing username with extra mention keyword: %v", user.NotifyProps["mention_keys"])
+ }
+}
+
func TestUserIsValid(t *testing.T) {
user := User{}
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index ea83458e9..636400ce9 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -141,14 +141,7 @@ func (us SqlUserStore) Update(user *model.User, allowActiveUpdate bool) StoreCha
}
if user.Username != oldUser.Username {
- nonUsernameKeys := []string{}
- splitKeys := strings.Split(user.NotifyProps["mention_keys"], ",")
- for _, key := range splitKeys {
- if key != oldUser.Username && key != "@"+oldUser.Username {
- nonUsernameKeys = append(nonUsernameKeys, key)
- }
- }
- user.NotifyProps["mention_keys"] = strings.Join(nonUsernameKeys, ",") + "," + user.Username + ",@" + user.Username
+ user.UpdateMentionKeysFromUsername(oldUser.Username)
}
if count, err := us.GetMaster().Update(user); err != nil {
diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx
index 3aa82ccdc..88dc412ca 100644
--- a/webapp/utils/text_formatting.jsx
+++ b/webapp/utils/text_formatting.jsx
@@ -214,7 +214,6 @@ function highlightCurrentMentions(text, tokens) {
}
for (const mention of UserStore.getCurrentMentionKeys()) {
- // occasionally we get an empty mention which matches a bunch of empty strings
if (!mention) {
continue;
}