diff options
author | Joram Wilander <jwawilander@gmail.com> | 2015-08-21 07:47:46 -0400 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2015-08-21 07:47:46 -0400 |
commit | 0db01894f95d5dd85cdded9bd9af170c0a496ec3 (patch) | |
tree | dd73647bf9fc261a02bfc30ef28ba20e684d052b /store | |
parent | 08941cf554bc88ca95f933cd2831fd6c6f2d49e9 (diff) | |
parent | 8e8cc302e6c863ef7d3cdedb94e1cb0d6af772ec (diff) | |
download | chat-0db01894f95d5dd85cdded9bd9af170c0a496ec3.tar.gz chat-0db01894f95d5dd85cdded9bd9af170c0a496ec3.tar.bz2 chat-0db01894f95d5dd85cdded9bd9af170c0a496ec3.zip |
Merge pull request #429 from nickago/MM-1859
MM-1859 Added updating of username based mentions on username change
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_user_store.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index cd25b488b..4b1189c2e 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -5,6 +5,7 @@ package store import ( "fmt" + "strings" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -163,6 +164,17 @@ func (us SqlUserStore) Update(user *model.User, allowActiveUpdate bool) StoreCha user.EmailVerified = false } + 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 + } + if count, err := us.GetMaster().Update(user); err != nil { if IsUniqueConstraintError(err.Error(), "Email", "users_email_teamid_key") { result.Err = model.NewAppError("SqlUserStore.Update", "This email is already taken. Please choose another", "user_id="+user.Id+", "+err.Error()) |