func join(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) channelId := params["channel_id"] channelName := params["channel_name"] var channel *model.Channel var err *model.AppError if channelId != "" { channel, err = app.GetChannel(channelId) } else if channelName != "" { channel, err = app.GetChannelByName(channelName, c.TeamId) } else { c.SetInvalidParam("join", "channel_id, channel_name") return } if err != nil { c.Err = err return } if channel.Type == model.CHANNEL_OPEN { if !HasPermissionToTeamContext(c, channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) { return } } if err = app.JoinChannel(channel, c.Session.UserId); err != nil { c.Err = err return } w.Write([]byte(channel.ToJson())) }
func getPermalinkTmp(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) postId := params["post_id"] if len(postId) != 26 { c.SetInvalidParam("getPermalinkTmp", "postId") return } if result := <-app.Srv.Store.Post().Get(postId); result.Err != nil { c.Err = result.Err return } else { list := result.Data.(*model.PostList) if len(list.Order) != 1 { c.Err = model.NewLocAppError("getPermalinkTmp", "api.post_get_post_by_id.get.app_error", nil, "") return } post := list.Posts[list.Order[0]] var channel *model.Channel var err *model.AppError if channel, err = app.GetChannel(post.ChannelId); err != nil { c.Err = err return } if !HasPermissionToTeamContext(c, channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) { return } if err = app.JoinChannel(channel, c.Session.UserId); err != nil { c.Err = err return } if HandleEtag(list.Etag(), "Get Permalink TMP", w, r) { return } w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag()) w.Write([]byte(list.ToJson())) } }
func (me *JoinProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse { if result := <-app.Srv.Store.Channel().GetByName(c.TeamId, message); result.Err != nil { return &model.CommandResponse{Text: c.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } else { channel := result.Data.(*model.Channel) if channel.Name == message { if channel.Type != model.CHANNEL_OPEN { return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } if err := app.JoinChannel(channel, c.Session.UserId); err != nil { return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + channel.Name, Text: c.T("api.command_join.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } } return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_join.missing.app_error")} }