diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-04-03 14:12:50 +0200 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-04-03 08:12:50 -0400 |
commit | 88b8df314673ceae08a37a6472296448e83d7442 (patch) | |
tree | ca1e646bbc3daf4f47cb8404d35305a74230f2e6 /app/command.go | |
parent | 67a8770118a7e8902efe537c4257b7442cb651fd (diff) | |
download | chat-88b8df314673ceae08a37a6472296448e83d7442.tar.gz chat-88b8df314673ceae08a37a6472296448e83d7442.tar.bz2 chat-88b8df314673ceae08a37a6472296448e83d7442.zip |
implement GET /commands (#5865)
Diffstat (limited to 'app/command.go')
-rw-r--r-- | app/command.go | 33 |
1 files changed, 32 insertions, 1 deletions
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:] |