Commit cebb4bef authored by JoramWilander's avatar JoramWilander

move default channel creation to seperate func and add off-topic

parent 0792eb18
......@@ -57,7 +57,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if sc, err := CreateChannel(c, channel, r.URL.Path, true); err != nil {
if sc, err := CreateChannel(c, channel, true); err != nil {
c.Err = err
return
} else {
......@@ -65,7 +65,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
func CreateChannel(c *Context, channel *model.Channel, path string, addMember bool) (*model.Channel, *model.AppError) {
func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
return nil, result.Err
} else {
......@@ -100,7 +100,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if sc, err := CreateDirectChannel(c, userId, r.URL.Path); err != nil {
if sc, err := CreateDirectChannel(c, userId); err != nil {
c.Err = err
return
} else {
......@@ -108,7 +108,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
func CreateDirectChannel(c *Context, otherUserId string, path string) (*model.Channel, *model.AppError) {
func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model.AppError) {
if len(otherUserId) != 26 {
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
}
......@@ -132,7 +132,7 @@ func CreateDirectChannel(c *Context, otherUserId string, path string) (*model.Ch
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
}
if sc, err := CreateChannel(c, channel, path, true); err != nil {
if sc, err := CreateChannel(c, channel, true); err != nil {
return nil, err
} else {
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId,
......@@ -146,6 +146,23 @@ func CreateDirectChannel(c *Context, otherUserId string, path string) (*model.Ch
}
}
func CreateDefaultChannels(c *Context, teamId string) ([]*model.Channel, *model.AppError) {
townSquare := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: teamId}
if _, err := CreateChannel(c, townSquare, false); err != nil {
return nil, err
}
offTopic := &model.Channel{DisplayName: "Off-Topic", Name: "off-topic", Type: model.CHANNEL_OPEN, TeamId: teamId}
if _, err := CreateChannel(c, offTopic, false); err != nil {
return nil, err
}
channels := []*model.Channel{townSquare, offTopic}
return channels, nil
}
func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
channel := model.ChannelFromJson(r.Body)
......@@ -303,7 +320,7 @@ func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelId := params["id"]
JoinChannel(c, channelId, r.URL.Path)
JoinChannel(c, channelId)
if c.Err != nil {
return
......@@ -314,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, path string) {
func JoinChannel(c *Context, channelId string) {
sc := Srv.Store.Channel().Get(channelId)
uc := Srv.Store.User().Get(c.Session.UserId)
......
......@@ -197,7 +197,7 @@ func joinCommand(c *Context, command *model.Command) bool {
return false
}
JoinChannel(c, v.Id, "/command")
JoinChannel(c, v.Id)
if c.Err != nil {
return false
......
......@@ -146,12 +146,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
rteam := result.Data.(*model.Team)
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: rteam.Id}
if _, err := CreateChannel(c, channel, r.URL.Path, false); err != nil {
c.Err = err
return
}
CreateDefaultChannels(c, rteam.Id)
teamSignup.User.TeamId = rteam.Id
teamSignup.User.EmailVerified = true
......@@ -197,12 +192,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
rteam := result.Data.(*model.Team)
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: rteam.Id}
if _, err := CreateChannel(c, channel, r.URL.Path, false); err != nil {
c.Err = err
return
}
CreateDefaultChannels(c, rteam.Id)
if rteam.AllowValet {
CreateValet(c, rteam)
......
......@@ -78,7 +78,7 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
createdTeam := result.Data.(*model.Team)
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: createdTeam.Id}
if _, err := api.CreateChannel(c, channel, r.URL.Path, false); err != nil {
if _, err := api.CreateChannel(c, channel, false); err != nil {
c.Err = err
return
}
......
......@@ -285,7 +285,7 @@ func getChannel(c *api.Context, w http.ResponseWriter, r *http.Request) {
otherUserId = ids[0]
}
if sc, err := api.CreateDirectChannel(c, otherUserId, r.URL.Path); err != nil {
if sc, err := api.CreateDirectChannel(c, otherUserId); err != nil {
api.Handle404(w, r)
return
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment