diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-10-05 12:45:15 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-10-13 09:42:25 -0400 |
commit | a11421c74b338eee6eedb4f4260a75f38aa3fd4c (patch) | |
tree | 9d2f3110eb88b28c7ad11f00a415319508eca8b3 /api/user.go | |
parent | 599644fb2fa75d1760420806c8c821959fc6b645 (diff) | |
download | chat-a11421c74b338eee6eedb4f4260a75f38aa3fd4c.tar.gz chat-a11421c74b338eee6eedb4f4260a75f38aa3fd4c.tar.bz2 chat-a11421c74b338eee6eedb4f4260a75f38aa3fd4c.zip |
Added default direct channels for previously existing users
Diffstat (limited to 'api/user.go')
-rw-r--r-- | api/user.go | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/api/user.go b/api/user.go index b769a2912..204f00dcd 100644 --- a/api/user.go +++ b/api/user.go @@ -222,42 +222,49 @@ func CreateUser(c *Context, team *model.Team, user *model.User) *model.User { func fireAndForgetAddDirectChannels(user *model.User, team *model.Team) { go func() { - var profiles map[string]*model.User - if result := <-Srv.Store.User().GetProfiles(team.Id); result.Err != nil { - l4g.Error("Failed to add direct channel preferences for new user user_id=%s, team_id=%s, err=%v", user.Id, team.Id, result.Err.Error()) - return - } else { - profiles = result.Data.(map[string]*model.User) - } + AddDirectChannels(user.Id, team.Id) + }() +} - count := 10 +func AddDirectChannels(userId, teamId string) []*model.Preference { + var profiles map[string]*model.User + if result := <-Srv.Store.User().GetProfiles(teamId); result.Err != nil { + l4g.Error("Failed to add direct channel preferences for user user_id=%s, team_id=%s, err=%v", userId, teamId, result.Err.Error()) + return []*model.Preference{} + } else { + profiles = result.Data.(map[string]*model.User) + } - for id := range profiles { - if id == user.Id { - continue - } + var preferences []*model.Preference - profile := profiles[id] + for id := range profiles { + if id == userId { + continue + } - preference := &model.Preference{ - UserId: user.Id, - Category: model.PREFERENCE_CATEGORY_DIRECT_CHANNELS, - Name: model.PREFERENCE_NAME_SHOW, - AltId: profile.Id, - Value: "true", - } + profile := profiles[id] - if result := <-Srv.Store.Preference().Save(preference); result.Err != nil { - l4g.Error("Failed to add direct channel preferences for new user user_id=%s, alt_id=%s, team_id=%s, err=%v", user.Id, profile.Id, team.Id, result.Err.Error()) - } + preference := &model.Preference{ + UserId: userId, + Category: model.PREFERENCE_CATEGORY_DIRECT_CHANNELS, + Name: model.PREFERENCE_NAME_SHOW, + AltId: profile.Id, + Value: "true", + } - count -= 1 + if result := <-Srv.Store.Preference().Save(preference); result.Err != nil { + l4g.Error("Failed to add direct channel preferences for user user_id=%s, alt_id=%s, team_id=%s, err=%v", userId, profile.Id, teamId, result.Err.Error()) + continue + } - if count == 0 { - break - } + preferences = append(preferences, preference) + + if len(preferences) >= 10 { + break } - }() + } + + return preferences } func fireAndForgetWelcomeEmail(email, teamDisplayName, siteURL, teamURL string) { |