From 88b8df314673ceae08a37a6472296448e83d7442 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Mon, 3 Apr 2017 14:12:50 +0200 Subject: implement GET /commands (#5865) --- app/command.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'app/command.go') diff --git a/app/command.go b/app/command.go index 4583cf81b..44e846a81 100644 --- a/app/command.go +++ b/app/command.go @@ -61,7 +61,8 @@ func CreateCommandPost(post *model.Post, teamId string, response *model.CommandR return post, nil } -func ListCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { +// previous ListCommands now ListAutocompleteCommands +func ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { commands := make([]*model.Command, 0, 32) seen := make(map[string]bool) for _, value := range commandProviders { @@ -103,6 +104,36 @@ func ListTeamCommands(teamId string) ([]*model.Command, *model.AppError) { } } +func ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) { + commands := make([]*model.Command, 0, 32) + seen := make(map[string]bool) + for _, value := range commandProviders { + cpy := *value.GetCommand(T) + if cpy.AutoComplete && !seen[cpy.Id] { + cpy.Sanitize() + seen[cpy.Trigger] = true + commands = append(commands, &cpy) + } + } + + if *utils.Cfg.ServiceSettings.EnableCommands { + if result := <-Srv.Store.Command().GetByTeam(teamId); result.Err != nil { + return nil, result.Err + } else { + teamCmds := result.Data.([]*model.Command) + for _, cmd := range teamCmds { + if !seen[cmd.Id] { + cmd.Sanitize() + seen[cmd.Trigger] = true + commands = append(commands, cmd) + } + } + } + } + + return commands, nil +} + func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) { parts := strings.Split(args.Command, " ") trigger := parts[0][1:] -- cgit v1.2.3-1-g7c22