summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYusuke Nemoto <kaakaa@users.noreply.github.com>2016-12-10 13:35:16 +0900
committerJoram Wilander <jwawilander@gmail.com>2016-12-09 23:35:16 -0500
commitddacfa58ba25002a7c3c35a1fe89898bb6e78c0a (patch)
treeab2855d58eba639a6cefef6ff6299eee3d0f802d
parentcb870c83d1f3135b2b339f3444cfa7c632c4d5bd (diff)
downloadchat-ddacfa58ba25002a7c3c35a1fe89898bb6e78c0a.tar.gz
chat-ddacfa58ba25002a7c3c35a1fe89898bb6e78c0a.tar.bz2
chat-ddacfa58ba25002a7c3c35a1fe89898bb6e78c0a.zip
PLT-1598 Slash command works in RHS (#4367)
* PLT-1598 Slash command works in RHS * fix UserProfile in the reply for Slash Command * fix some problem about the system messages in RHS * system message in RHS isn't displayed as comment for root message * remove status indicator for system message in RHS * system message in RHS is colored to grey * system messages don't count as commented post * fix bug about cleaning draft in RHS * remove unnecessary function * implement new model for executing command
-rw-r--r--api/command.go32
-rw-r--r--api/command_away.go2
-rw-r--r--api/command_echo.go6
-rw-r--r--api/command_echo_test.go2
-rw-r--r--api/command_expand_collapse.go4
-rw-r--r--api/command_expand_collapse_test.go4
-rw-r--r--api/command_invite_people.go2
-rw-r--r--api/command_invite_people_test.go6
-rw-r--r--api/command_join.go2
-rw-r--r--api/command_join_test.go4
-rw-r--r--api/command_loadtest.go3
-rw-r--r--api/command_loadtest_test.go10
-rw-r--r--api/command_logout.go2
-rw-r--r--api/command_logout_test.go2
-rw-r--r--api/command_me.go2
-rw-r--r--api/command_me_test.go2
-rw-r--r--api/command_msg.go2
-rw-r--r--api/command_msg_test.go6
-rw-r--r--api/command_offline.go2
-rw-r--r--api/command_online.go2
-rw-r--r--api/command_shortcuts.go2
-rw-r--r--api/command_shortcuts_test.go4
-rw-r--r--api/command_shrug.go2
-rw-r--r--api/command_shrug_test.go2
-rw-r--r--api/command_statuses_test.go2
-rw-r--r--api/command_test.go4
-rw-r--r--model/client.go9
-rw-r--r--model/command_args.go36
-rw-r--r--webapp/actions/channel_actions.jsx5
-rw-r--r--webapp/client/client.jsx4
-rw-r--r--webapp/components/create_comment.jsx36
-rw-r--r--webapp/components/create_post.jsx12
-rw-r--r--webapp/components/post_view/components/post_list.jsx2
-rw-r--r--webapp/components/rhs_comment.jsx43
-rw-r--r--webapp/tests/client_command.test.jsx5
35 files changed, 186 insertions, 79 deletions
diff --git a/api/command.go b/api/command.go
index 3ae379819..a6c3ea201 100644
--- a/api/command.go
+++ b/api/command.go
@@ -20,7 +20,7 @@ import (
type CommandProvider interface {
GetTrigger() string
GetCommand(c *Context) *model.Command
- DoCommand(c *Context, channelId string, message string) *model.CommandResponse
+ DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse
}
var commandProviders = make(map[string]CommandProvider)
@@ -88,30 +88,28 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
}
func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
- props := model.MapFromJson(r.Body)
- command := strings.TrimSpace(props["command"])
- channelId := strings.TrimSpace(props["channelId"])
+ commandArgs := model.CommandArgsFromJson(r.Body)
- if len(command) <= 1 || strings.Index(command, "/") != 0 {
+ if len(commandArgs.Command) <= 1 || strings.Index(commandArgs.Command, "/") != 0 {
c.Err = model.NewLocAppError("executeCommand", "api.command.execute_command.start.app_error", nil, "")
return
}
- if len(channelId) > 0 {
- if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_USE_SLASH_COMMANDS) {
+ if len(commandArgs.ChannelId) > 0 {
+ if !HasPermissionToChannelContext(c, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) {
return
}
}
- parts := strings.Split(command, " ")
+ parts := strings.Split(commandArgs.Command, " ")
trigger := parts[0][1:]
trigger = strings.ToLower(trigger)
message := strings.Join(parts[1:], " ")
provider := GetCommandProvider(trigger)
if provider != nil {
- response := provider.DoCommand(c, channelId, message)
- handleResponse(c, w, response, channelId, provider.GetCommand(c), true)
+ response := provider.DoCommand(c, commandArgs, message)
+ handleResponse(c, w, response, commandArgs, provider.GetCommand(c), true)
return
} else {
@@ -121,7 +119,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- chanChan := Srv.Store.Channel().Get(channelId)
+ chanChan := Srv.Store.Channel().Get(commandArgs.ChannelId)
teamChan := Srv.Store.Team().Get(c.TeamId)
userChan := Srv.Store.User().Get(c.Session.UserId)
@@ -166,7 +164,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
p.Set("team_id", cmd.TeamId)
p.Set("team_domain", team.Name)
- p.Set("channel_id", channelId)
+ p.Set("channel_id", commandArgs.ChannelId)
p.Set("channel_name", channel.Name)
p.Set("user_id", c.Session.UserId)
@@ -200,7 +198,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
if response == nil {
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "")
} else {
- handleResponse(c, w, response, channelId, cmd, false)
+ handleResponse(c, w, response, commandArgs, cmd, false)
}
} else {
defer resp.Body.Close()
@@ -219,10 +217,11 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = model.NewLocAppError("command", "api.command.execute_command.not_found.app_error", map[string]interface{}{"Trigger": trigger}, "")
}
-func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, channelId string, cmd *model.Command, builtIn bool) {
-
+func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, commandArgs *model.CommandArgs, cmd *model.Command, builtIn bool) {
post := &model.Post{}
- post.ChannelId = channelId
+ post.ChannelId = commandArgs.ChannelId
+ post.RootId = commandArgs.RootId
+ post.ParentId = commandArgs.ParentId
if !builtIn {
post.AddProp("from_webhook", "true")
@@ -258,6 +257,7 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe
post.Message = response.Text
post.CreateAt = model.GetMillis()
post.UserId = c.Session.UserId
+ post.ParentId = ""
SendEphemeralPost(
c.TeamId,
c.Session.UserId,
diff --git a/api/command_away.go b/api/command_away.go
index 55ce7846e..6d6540320 100644
--- a/api/command_away.go
+++ b/api/command_away.go
@@ -31,7 +31,7 @@ func (me *AwayProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *AwayProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *AwayProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := c.T("api.command_away.success")
if len(message) > 0 {
rmsg = message + " " + rmsg
diff --git a/api/command_echo.go b/api/command_echo.go
index 997ee0751..4f6f6e33a 100644
--- a/api/command_echo.go
+++ b/api/command_echo.go
@@ -39,7 +39,7 @@ func (me *EchoProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *EchoProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *EchoProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
maxThreads := 100
delay := 0
@@ -75,7 +75,9 @@ func (me *EchoProvider) DoCommand(c *Context, channelId string, message string)
go func() {
defer func() { <-echoSem }()
post := &model.Post{}
- post.ChannelId = channelId
+ post.ChannelId = args.ChannelId
+ post.RootId = args.RootId
+ post.ParentId = args.ParentId
post.Message = message
post.UserId = c.Session.UserId
diff --git a/api/command_echo_test.go b/api/command_echo_test.go
index 26fba007c..71a378242 100644
--- a/api/command_echo_test.go
+++ b/api/command_echo_test.go
@@ -17,7 +17,7 @@ func TestEchoCommand(t *testing.T) {
echoTestString := "/echo test"
- r1 := Client.Must(Client.Command(channel1.Id, echoTestString, false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel1.Id, echoTestString)).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Echo command failed to execute")
}
diff --git a/api/command_expand_collapse.go b/api/command_expand_collapse.go
index ee018cf8f..afd17a6fc 100644
--- a/api/command_expand_collapse.go
+++ b/api/command_expand_collapse.go
@@ -49,11 +49,11 @@ func (me *CollapseProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *ExpandProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *ExpandProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(c, "false")
}
-func (me *CollapseProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *CollapseProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(c, "true")
}
diff --git a/api/command_expand_collapse_test.go b/api/command_expand_collapse_test.go
index 2303b2fed..bad5ef6c4 100644
--- a/api/command_expand_collapse_test.go
+++ b/api/command_expand_collapse_test.go
@@ -15,7 +15,7 @@ func TestExpandCommand(t *testing.T) {
Client := th.BasicClient
channel := th.BasicChannel
- r1 := Client.Must(Client.Command(channel.Id, "/expand", false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel.Id, "/expand")).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Command failed to execute")
}
@@ -33,7 +33,7 @@ func TestCollapseCommand(t *testing.T) {
Client := th.BasicClient
channel := th.BasicChannel
- r1 := Client.Must(Client.Command(channel.Id, "/collapse", false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel.Id, "/collapse")).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Command failed to execute")
}
diff --git a/api/command_invite_people.go b/api/command_invite_people.go
index 93f8f85eb..ca2a2633a 100644
--- a/api/command_invite_people.go
+++ b/api/command_invite_people.go
@@ -35,7 +35,7 @@ func (me *InvitePeopleProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *InvitePeopleProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *InvitePeopleProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
if !utils.Cfg.EmailSettings.SendEmailNotifications {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command.invite_people.email_off")}
}
diff --git a/api/command_invite_people_test.go b/api/command_invite_people_test.go
index 3efc87e60..d4f579c4d 100644
--- a/api/command_invite_people_test.go
+++ b/api/command_invite_people_test.go
@@ -14,17 +14,17 @@ func TestInvitePeopleCommand(t *testing.T) {
Client := th.BasicClient
channel := th.BasicChannel
- r1 := Client.Must(Client.Command(channel.Id, "/invite_people test@example.com", false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel.Id, "/invite_people test@example.com")).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Command failed to execute")
}
- r2 := Client.Must(Client.Command(channel.Id, "/invite_people test1@example.com test2@example.com", false)).Data.(*model.CommandResponse)
+ r2 := Client.Must(Client.Command(channel.Id, "/invite_people test1@example.com test2@example.com")).Data.(*model.CommandResponse)
if r2 == nil {
t.Fatal("Command failed to execute")
}
- r3 := Client.Must(Client.Command(channel.Id, "/invite_people", false)).Data.(*model.CommandResponse)
+ r3 := Client.Must(Client.Command(channel.Id, "/invite_people")).Data.(*model.CommandResponse)
if r3 == nil {
t.Fatal("Command failed to execute")
}
diff --git a/api/command_join.go b/api/command_join.go
index 0499d503d..3c997dffd 100644
--- a/api/command_join.go
+++ b/api/command_join.go
@@ -32,7 +32,7 @@ func (me *JoinProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *JoinProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *JoinProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
if result := <-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 {
diff --git a/api/command_join_test.go b/api/command_join_test.go
index a1dbace41..cce837ceb 100644
--- a/api/command_join_test.go
+++ b/api/command_join_test.go
@@ -29,12 +29,12 @@ func TestJoinCommands(t *testing.T) {
channel3 := Client.Must(Client.CreateDirectChannel(user2.Id)).Data.(*model.Channel)
- rs5 := Client.Must(Client.Command(channel0.Id, "/join "+channel2.Name, false)).Data.(*model.CommandResponse)
+ rs5 := Client.Must(Client.Command(channel0.Id, "/join "+channel2.Name)).Data.(*model.CommandResponse)
if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) {
t.Fatal("failed to join channel")
}
- rs6 := Client.Must(Client.Command(channel0.Id, "/join "+channel3.Name, false)).Data.(*model.CommandResponse)
+ rs6 := Client.Must(Client.Command(channel0.Id, "/join "+channel3.Name)).Data.(*model.CommandResponse)
if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) {
t.Fatal("should not have joined direct message channel")
}
diff --git a/api/command_loadtest.go b/api/command_loadtest.go
index 8f5163a66..ed3fc37ba 100644
--- a/api/command_loadtest.go
+++ b/api/command_loadtest.go
@@ -84,7 +84,8 @@ func (me *LoadTestProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *LoadTestProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *LoadTestProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
+ channelId := args.ChannelId
//This command is only available when EnableTesting is true
if !utils.Cfg.ServiceSettings.EnableTesting {
diff --git a/api/command_loadtest_test.go b/api/command_loadtest_test.go
index 9371e5960..091e05831 100644
--- a/api/command_loadtest_test.go
+++ b/api/command_loadtest_test.go
@@ -25,7 +25,7 @@ func TestLoadTestHelpCommands(t *testing.T) {
utils.Cfg.ServiceSettings.EnableTesting = true
- rs := Client.Must(Client.Command(channel.Id, "/loadtest help", false)).Data.(*model.CommandResponse)
+ rs := Client.Must(Client.Command(channel.Id, "/loadtest help")).Data.(*model.CommandResponse)
if !strings.Contains(rs.Text, "Mattermost load testing commands to help") {
t.Fatal(rs.Text)
}
@@ -46,7 +46,7 @@ func TestLoadTestSetupCommands(t *testing.T) {
utils.Cfg.ServiceSettings.EnableTesting = true
- rs := Client.Must(Client.Command(channel.Id, "/loadtest setup fuzz 1 1 1", false)).Data.(*model.CommandResponse)
+ rs := Client.Must(Client.Command(channel.Id, "/loadtest setup fuzz 1 1 1")).Data.(*model.CommandResponse)
if rs.Text != "Created enviroment" {
t.Fatal(rs.Text)
}
@@ -67,7 +67,7 @@ func TestLoadTestUsersCommands(t *testing.T) {
utils.Cfg.ServiceSettings.EnableTesting = true
- rs := Client.Must(Client.Command(channel.Id, "/loadtest users fuzz 1 2", false)).Data.(*model.CommandResponse)
+ rs := Client.Must(Client.Command(channel.Id, "/loadtest users fuzz 1 2")).Data.(*model.CommandResponse)
if rs.Text != "Added users" {
t.Fatal(rs.Text)
}
@@ -88,7 +88,7 @@ func TestLoadTestChannelsCommands(t *testing.T) {
utils.Cfg.ServiceSettings.EnableTesting = true
- rs := Client.Must(Client.Command(channel.Id, "/loadtest channels fuzz 1 2", false)).Data.(*model.CommandResponse)
+ rs := Client.Must(Client.Command(channel.Id, "/loadtest channels fuzz 1 2")).Data.(*model.CommandResponse)
if rs.Text != "Added channels" {
t.Fatal(rs.Text)
}
@@ -109,7 +109,7 @@ func TestLoadTestPostsCommands(t *testing.T) {
utils.Cfg.ServiceSettings.EnableTesting = true
- rs := Client.Must(Client.Command(channel.Id, "/loadtest posts fuzz 2 3 2", false)).Data.(*model.CommandResponse)
+ rs := Client.Must(Client.Command(channel.Id, "/loadtest posts fuzz 2 3 2")).Data.(*model.CommandResponse)
if rs.Text != "Added posts" {
t.Fatal(rs.Text)
}
diff --git a/api/command_logout.go b/api/command_logout.go
index 9fff4e2d5..474f0b58e 100644
--- a/api/command_logout.go
+++ b/api/command_logout.go
@@ -32,7 +32,7 @@ func (me *LogoutProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *LogoutProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *LogoutProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.fail_message")}
SUCCESS := &model.CommandResponse{GotoLocation: "/", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
diff --git a/api/command_logout_test.go b/api/command_logout_test.go
index 6d74549af..d61b30633 100644
--- a/api/command_logout_test.go
+++ b/api/command_logout_test.go
@@ -10,5 +10,5 @@ import (
func TestLogoutTestCommand(t *testing.T) {
th := Setup().InitBasic()
- th.BasicClient.Must(th.BasicClient.Command(th.BasicChannel.Id, "/logout", false))
+ th.BasicClient.Must(th.BasicClient.Command(th.BasicChannel.Id, "/logout"))
}
diff --git a/api/command_me.go b/api/command_me.go
index c6147278b..a3cda472a 100644
--- a/api/command_me.go
+++ b/api/command_me.go
@@ -32,6 +32,6 @@ func (me *MeProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *MeProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *MeProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: "*" + message + "*"}
}
diff --git a/api/command_me_test.go b/api/command_me_test.go
index f466f5764..0250cfb0f 100644
--- a/api/command_me_test.go
+++ b/api/command_me_test.go
@@ -17,7 +17,7 @@ func TestMeCommand(t *testing.T) {
testString := "/me hello"
- r1 := Client.Must(Client.Command(channel.Id, testString, false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel.Id, testString)).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Command failed to execute")
}
diff --git a/api/command_msg.go b/api/command_msg.go
index 2e0e25397..8a9949544 100644
--- a/api/command_msg.go
+++ b/api/command_msg.go
@@ -34,7 +34,7 @@ func (me *msgProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *msgProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *msgProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
splitMessage := strings.SplitN(message, " ", 2)
diff --git a/api/command_msg_test.go b/api/command_msg_test.go
index f11fce091..ad1c8d5ce 100644
--- a/api/command_msg_test.go
+++ b/api/command_msg_test.go
@@ -21,12 +21,12 @@ func TestMsgCommands(t *testing.T) {
Client.Must(Client.CreateDirectChannel(user2.Id))
Client.Must(Client.CreateDirectChannel(user3.Id))
- rs1 := Client.Must(Client.Command("", "/msg "+user2.Username, false)).Data.(*model.CommandResponse)
+ rs1 := Client.Must(Client.Command("", "/msg "+user2.Username)).Data.(*model.CommandResponse)
if !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) && !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id) {
t.Fatal("failed to create direct channel")
}
- rs2 := Client.Must(Client.Command("", "/msg "+user3.Username+" foobar", false)).Data.(*model.CommandResponse)
+ rs2 := Client.Must(Client.Command("", "/msg "+user3.Username+" foobar")).Data.(*model.CommandResponse)
if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user3.Id) && !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user3.Id+"__"+user1.Id) {
t.Fatal("failed to create second direct channel")
}
@@ -34,7 +34,7 @@ func TestMsgCommands(t *testing.T) {
t.Fatalf("post did not get sent to direct message")
}
- rs3 := Client.Must(Client.Command("", "/msg "+user2.Username, false)).Data.(*model.CommandResponse)
+ rs3 := Client.Must(Client.Command("", "/msg "+user2.Username)).Data.(*model.CommandResponse)
if !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) && !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id) {
t.Fatal("failed to go back to existing direct channel")
}
diff --git a/api/command_offline.go b/api/command_offline.go
index a9e2123d3..1349ac18f 100644
--- a/api/command_offline.go
+++ b/api/command_offline.go
@@ -31,7 +31,7 @@ func (me *OfflineProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *OfflineProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *OfflineProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := c.T("api.command_offline.success")
if len(message) > 0 {
rmsg = message + " " + rmsg
diff --git a/api/command_online.go b/api/command_online.go
index 71ada5b7a..887aa2c47 100644
--- a/api/command_online.go
+++ b/api/command_online.go
@@ -31,7 +31,7 @@ func (me *OnlineProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *OnlineProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *OnlineProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := c.T("api.command_online.success")
if len(message) > 0 {
rmsg = message + " " + rmsg
diff --git a/api/command_shortcuts.go b/api/command_shortcuts.go
index dfbb7071d..f75b419b1 100644
--- a/api/command_shortcuts.go
+++ b/api/command_shortcuts.go
@@ -35,7 +35,7 @@ func (me *ShortcutsProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *ShortcutsProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *ShortcutsProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
shortcutIds := [4]string{
"api.command_shortcuts.nav",
"api.command_shortcuts.files",
diff --git a/api/command_shortcuts_test.go b/api/command_shortcuts_test.go
index 01c56b465..049175ec9 100644
--- a/api/command_shortcuts_test.go
+++ b/api/command_shortcuts_test.go
@@ -14,12 +14,12 @@ func TestShortcutsCommand(t *testing.T) {
Client := th.BasicClient
channel := th.BasicChannel
- rs := Client.Must(Client.Command(channel.Id, "/shortcuts ", false)).Data.(*model.CommandResponse)
+ rs := Client.Must(Client.Command(channel.Id, "/shortcuts ")).Data.(*model.CommandResponse)
if !strings.Contains(rs.Text, "CTRL") {
t.Fatal("failed to display shortcuts")
}
- rs = Client.Must(Client.Command(channel.Id, "/shortcuts mac", false)).Data.(*model.CommandResponse)
+ rs = Client.Must(Client.Command(channel.Id, "/shortcuts mac")).Data.(*model.CommandResponse)
if !strings.Contains(rs.Text, "CMD") {
t.Fatal("failed to display Mac shortcuts")
}
diff --git a/api/command_shrug.go b/api/command_shrug.go
index 8fb5bc200..899fcab33 100644
--- a/api/command_shrug.go
+++ b/api/command_shrug.go
@@ -32,7 +32,7 @@ func (me *ShrugProvider) GetCommand(c *Context) *model.Command {
}
}
-func (me *ShrugProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
+func (me *ShrugProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := `¯\\\_(ツ)\_/¯`
if len(message) > 0 {
rmsg = message + " " + rmsg
diff --git a/api/command_shrug_test.go b/api/command_shrug_test.go
index 99c10d191..e64f4c4b1 100644
--- a/api/command_shrug_test.go
+++ b/api/command_shrug_test.go
@@ -17,7 +17,7 @@ func TestShrugCommand(t *testing.T) {
testString := "/shrug"
- r1 := Client.Must(Client.Command(channel.Id, testString, false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel.Id, testString)).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Command failed to execute")
}
diff --git a/api/command_statuses_test.go b/api/command_statuses_test.go
index 73c6354f4..47628de3f 100644
--- a/api/command_statuses_test.go
+++ b/api/command_statuses_test.go
@@ -22,7 +22,7 @@ func commandAndTest(t *testing.T, th *TestHelper, status string) {
channel := th.BasicChannel
user := th.BasicUser
- r1 := Client.Must(Client.Command(channel.Id, "/"+status, false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel.Id, "/"+status)).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Command failed to execute")
}
diff --git a/api/command_test.go b/api/command_test.go
index 45268a9a5..726a9cb9b 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -246,7 +246,7 @@ func TestTestCommand(t *testing.T) {
cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command)
- r1 := Client.Must(Client.Command(channel1.Id, "/test", false)).Data.(*model.CommandResponse)
+ r1 := Client.Must(Client.Command(channel1.Id, "/test")).Data.(*model.CommandResponse)
if r1 == nil {
t.Fatal("Test command failed to execute")
}
@@ -266,7 +266,7 @@ func TestTestCommand(t *testing.T) {
cmd2 = Client.Must(Client.CreateCommand(cmd2)).Data.(*model.Command)
- r2 := Client.Must(Client.Command(channel1.Id, "/test2", false)).Data.(*model.CommandResponse)
+ r2 := Client.Must(Client.Command(channel1.Id, "/test2")).Data.(*model.CommandResponse)
if r2 == nil {
t.Fatal("Test2 command failed to execute")
}
diff --git a/model/client.go b/model/client.go
index 510ba461f..951b3388a 100644
--- a/model/client.go
+++ b/model/client.go
@@ -826,12 +826,9 @@ func (c *Client) EmailToLDAP(m map[string]string) (*Result, *AppError) {
}
}
-func (c *Client) Command(channelId string, command string, suggest bool) (*Result, *AppError) {
- m := make(map[string]string)
- m["command"] = command
- m["channelId"] = channelId
- m["suggest"] = strconv.FormatBool(suggest)
- if r, err := c.DoApiPost(c.GetTeamRoute()+"/commands/execute", MapToJson(m)); err != nil {
+func (c *Client) Command(channelId string, command string) (*Result, *AppError) {
+ args := &CommandArgs{ChannelId: channelId, Command: command}
+ if r, err := c.DoApiPost(c.GetTeamRoute()+"/commands/execute", args.ToJson()); err != nil {
return nil, err
} else {
defer closeBody(r)
diff --git a/model/command_args.go b/model/command_args.go
new file mode 100644
index 000000000..4da5dc760
--- /dev/null
+++ b/model/command_args.go
@@ -0,0 +1,36 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+type CommandArgs struct {
+ ChannelId string `json:"channel_id"`
+ RootId string `json:"root_id"`
+ ParentId string `json:"parent_id"`
+ Command string `json:"command"`
+}
+
+func (o *CommandArgs) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func CommandArgsFromJson(data io.Reader) *CommandArgs {
+ decoder := json.NewDecoder(data)
+ var o CommandArgs
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
index b108633d7..12e58177d 100644
--- a/webapp/actions/channel_actions.jsx
+++ b/webapp/actions/channel_actions.jsx
@@ -32,7 +32,7 @@ export function goToChannel(channel) {
}
}
-export function executeCommand(channelId, message, suggest, success, error) {
+export function executeCommand(message, args, success, error) {
let msg = message;
msg = msg.substring(0, msg.indexOf(' ')).toLowerCase() + msg.substring(msg.indexOf(' '), msg.length);
@@ -48,8 +48,7 @@ export function executeCommand(channelId, message, suggest, success, error) {
msg = '/shortcuts';
}
}
-
- Client.executeCommand(channelId, msg, suggest, success, error);
+ Client.executeCommand(msg, args, success, error);
}
export function setChannelAsRead(channelIdParam) {
diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx
index d8218490e..398ce4f83 100644
--- a/webapp/client/client.jsx
+++ b/webapp/client/client.jsx
@@ -1494,13 +1494,13 @@ export default class Client {
end(this.handleResponse.bind(this, 'listCommands', success, error));
}
- executeCommand(channelId, command, suggest, success, error) {
+ executeCommand(command, commandArgs, success, error) {
request.
post(`${this.getCommandsRoute()}/execute`).
set(this.defaultHeaders).
type('application/json').
accept('application/json').
- send({channelId, command, suggest: String(suggest)}).
+ send({command, ...commandArgs}).
end(this.handleResponse.bind(this, 'executeCommand', success, error));
this.track('api', 'api_integrations_used');
diff --git a/webapp/components/create_comment.jsx b/webapp/components/create_comment.jsx
index a235691b4..3bd8d5d1c 100644
--- a/webapp/components/create_comment.jsx
+++ b/webapp/components/create_comment.jsx
@@ -4,6 +4,7 @@
import $ from 'jquery';
import ReactDOM from 'react-dom';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
+import * as ChannelActions from 'actions/channel_actions.jsx';
import EmojiStore from 'stores/emoji_store.jsx';
import UserStore from 'stores/user_store.jsx';
import PostDeletedModal from './post_deleted_modal.jsx';
@@ -22,6 +23,7 @@ import * as PostActions from 'actions/post_actions.jsx';
import Constants from 'utils/constants.jsx';
import {FormattedMessage} from 'react-intl';
+import {browserHistory} from 'react-router/es6';
const ActionTypes = Constants.ActionTypes;
const KeyCodes = Constants.KeyCodes;
@@ -121,7 +123,6 @@ export default class CreateComment extends React.Component {
}
MessageHistoryStore.storeMessageInHistory(message);
-
if (message.trim().length === 0 && this.state.fileInfos.length === 0) {
return;
}
@@ -129,6 +130,8 @@ export default class CreateComment extends React.Component {
const isReaction = REACTION_PATTERN.exec(message);
if (isReaction && EmojiStore.has(isReaction[2])) {
this.handleSubmitReaction(isReaction);
+ } else if (message.indexOf('/') === 0) {
+ this.handleSubmitCommand(message);
} else {
this.handleSubmitPost(message);
}
@@ -146,6 +149,36 @@ export default class CreateComment extends React.Component {
this.focusTextbox(forceFocus);
}
+ handleSubmitCommand(message) {
+ PostStore.storeCommentDraft(this.props.rootId, null);
+ this.setState({message: '', postError: null, fileInfos: []});
+
+ const args = {};
+ args.channel_id = this.props.channelId;
+ args.root_id = this.props.rootId;
+ args.parent_id = this.props.rootId;
+ ChannelActions.executeCommand(
+ message,
+ args,
+ (data) => {
+ this.setState({submitting: false});
+ if (data.goto_location && data.goto_location.length > 0) {
+ browserHistory.push(data.goto_location);
+ }
+ },
+ (err) => {
+ if (err.sendMessage) {
+ this.handleSubmitPost(message);
+ } else {
+ const state = {};
+ state.serverError = err.message;
+ state.submitting = false;
+ this.setState(state);
+ }
+ }
+ );
+ }
+
handleSubmitPost(message) {
const userId = UserStore.getCurrentId();
const time = Utils.getTimestamp();
@@ -444,7 +477,6 @@ export default class CreateComment extends React.Component {
onBlur={this.handleBlur}
createMessage={Utils.localizeMessage('create_comment.addComment', 'Add a comment...')}
initialText=''
- supportsCommands={false}
channelId={this.props.channelId}
id='reply_textbox'
ref='textbox'
diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx
index 6bd5f0293..24ebd60b5 100644
--- a/webapp/components/create_post.jsx
+++ b/webapp/components/create_post.jsx
@@ -112,10 +112,11 @@ export default class CreatePost extends React.Component {
PostStore.storeDraft(this.state.channelId, null);
this.setState({message: '', postError: null, fileInfos: []});
+ const args = {};
+ args.channel_id = this.state.channelId;
ChannelActions.executeCommand(
- this.state.channelId,
post.message,
- false,
+ args,
(data) => {
this.setState({submitting: false});
@@ -357,10 +358,11 @@ export default class CreatePost extends React.Component {
showShortcuts(e) {
if ((e.ctrlKey || e.metaKey) && e.keyCode === Constants.KeyCodes.FORWARD_SLASH) {
e.preventDefault();
+ const args = {};
+ args.channel_id = this.state.channelId;
ChannelActions.executeCommand(
- this.state.channelId,
- '/shortcuts ',
- false,
+ '/shortcuts',
+ args,
null,
(err) => {
this.setState({
diff --git a/webapp/components/post_view/components/post_list.jsx b/webapp/components/post_view/components/post_list.jsx
index 157e0dde2..b3b83dfd6 100644
--- a/webapp/components/post_view/components/post_list.jsx
+++ b/webapp/components/post_view/components/post_list.jsx
@@ -293,7 +293,7 @@ export default class PostList extends React.Component {
if (commentRootId) {
for (const postId in posts) {
- if (posts[postId].root_id === commentRootId) {
+ if (posts[postId].root_id === commentRootId && !PostUtils.isSystemMessage(posts[postId])) {
commentCount += 1;
if (posts[postId].user_id === userId) {
shouldHighlightThreads = true;
diff --git a/webapp/components/rhs_comment.jsx b/webapp/components/rhs_comment.jsx
index bb04480ed..8b5d56c01 100644
--- a/webapp/components/rhs_comment.jsx
+++ b/webapp/components/rhs_comment.jsx
@@ -227,6 +227,8 @@ export default class RhsComment extends React.Component {
render() {
const post = this.props.post;
const flagIcon = Constants.FLAG_ICON_SVG;
+ const mattermostLogo = Constants.MATTERMOST_ICON_SVG;
+ const isSystemMessage = PostUtils.isSystemMessage(post);
var currentUserCss = '';
if (this.props.currentUser === post.user_id) {
@@ -236,10 +238,31 @@ export default class RhsComment extends React.Component {
var timestamp = this.props.currentUser.update_at;
let botIndicator;
-
+ let userProfile = (
+ <UserProfile user={this.props.user}/>
+ );
if (post.props && post.props.from_webhook) {
+ if (post.props.override_username && global.window.mm_config.EnablePostUsernameOverride === 'true') {
+ userProfile = (
+ <UserProfile
+ user={this.props.user}
+ overwriteName={post.props.override_username}
+ disablePopover={true}
+ />
+ );
+ }
botIndicator = <li className='bot-indicator'>{Constants.BOT_NAME}</li>;
+ } else if (isSystemMessage) {
+ userProfile = (
+ <UserProfile
+ user={{}}
+ overwriteName={Constants.SYSTEM_MESSAGE_PROFILE_NAME}
+ overwriteImage={Constants.SYSTEM_MESSAGE_PROFILE_IMAGE}
+ disablePopover={true}
+ />
+ );
}
+
let loading;
let postClass = '';
let message = <PostMessageContainer post={post}/>;
@@ -264,6 +287,11 @@ export default class RhsComment extends React.Component {
);
}
+ let systemMessageClass = '';
+ if (isSystemMessage) {
+ systemMessageClass = 'post--system';
+ }
+
let status = this.props.status;
if (post.props && post.props.from_webhook === 'true') {
status = null;
@@ -279,6 +307,15 @@ export default class RhsComment extends React.Component {
/>
);
+ if (isSystemMessage) {
+ profilePic = (
+ <span
+ className='icon'
+ dangerouslySetInnerHTML={{__html: mattermostLogo}}
+ />
+ );
+ }
+
let compactClass = '';
if (this.props.compactDisplay) {
compactClass = 'post--compact';
@@ -387,13 +424,13 @@ export default class RhsComment extends React.Component {
};
return (
- <div className={'post post--thread ' + currentUserCss + ' ' + compactClass}>
+ <div className={'post post--thread ' + currentUserCss + ' ' + compactClass + ' ' + systemMessageClass}>
<div className='post__content'>
{profilePicContainer}
<div>
<ul className='post__header'>
<li className='col col__name'>
- <strong><UserProfile user={this.props.user}/></strong>
+ <strong>{userProfile}</strong>
</li>
{botIndicator}
<li className='col'>
diff --git a/webapp/tests/client_command.test.jsx b/webapp/tests/client_command.test.jsx
index 7d39537f8..e6795e5d7 100644
--- a/webapp/tests/client_command.test.jsx
+++ b/webapp/tests/client_command.test.jsx
@@ -38,10 +38,11 @@ describe('Client.Commands', function() {
it('executeCommand', function(done) {
TestHelper.initBasic(() => {
+ const args = {};
+ args.channel_id = TestHelper.basicChannel().id;
TestHelper.basicClient().executeCommand(
- TestHelper.basicChannel().id,
'/shrug',
- null,
+ args,
function(data) {
assert.equal(data.response_type, 'in_channel');
done();