diff options
author | JoramWilander <jwawilander@gmail.com> | 2015-06-29 10:24:45 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2015-06-29 10:24:45 -0400 |
commit | d00f90d10c60c82fb74444c3c1118b380d149118 (patch) | |
tree | 814c2032f7daf758a6cdb622dfcde6a8e0dba0cf /api/channel.go | |
parent | cebb4bef843e848531bdf3465f49bd0d995efa8e (diff) | |
download | chat-d00f90d10c60c82fb74444c3c1118b380d149118.tar.gz chat-d00f90d10c60c82fb74444c3c1118b380d149118.tar.bz2 chat-d00f90d10c60c82fb74444c3c1118b380d149118.zip |
new users now join off-topic defaultly
Diffstat (limited to 'api/channel.go')
-rw-r--r-- | api/channel.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/api/channel.go b/api/channel.go index 853a348ca..c0c2d1548 100644 --- a/api/channel.go +++ b/api/channel.go @@ -320,7 +320,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) channelId := params["id"] - JoinChannel(c, channelId) + JoinChannel(c, channelId, "") if c.Err != nil { return @@ -331,7 +331,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.MapToJson(result))) } -func JoinChannel(c *Context, channelId string) { +func JoinChannel(c *Context, channelId string, role string) { sc := Srv.Store.Channel().Get(channelId) uc := Srv.Store.User().Get(c.Session.UserId) @@ -357,7 +357,7 @@ func JoinChannel(c *Context, channelId string) { } if channel.Type == model.CHANNEL_OPEN { - cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, NotifyLevel: model.CHANNEL_NOTIFY_ALL} + cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: role} if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil { c.Err = cmresult.Err @@ -380,6 +380,32 @@ func JoinChannel(c *Context, channelId string) { } } +func JoinDefaultChannels(c *Context, user *model.User, channelRole string) *model.AppError { + // We don't call JoinChannel here since c.Session is not populated on user creation + + var err *model.AppError = nil + + if result := <-Srv.Store.Channel().GetByName(user.TeamId, "town-square"); result.Err != nil { + err = result.Err + } else { + cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole} + if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil { + err = cmResult.Err + } + } + + if result := <-Srv.Store.Channel().GetByName(user.TeamId, "off-topic"); result.Err != nil { + err = result.Err + } else { + cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole} + if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil { + err = cmResult.Err + } + } + + return err +} + func leaveChannel(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) |