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
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
cb870c83d1
Коммит
ddacfa58ba
@@ -20,7 +20,7 @@ import (
|
|||||||
type CommandProvider interface {
|
type CommandProvider interface {
|
||||||
GetTrigger() string
|
GetTrigger() string
|
||||||
GetCommand(c *Context) *model.Command
|
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)
|
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) {
|
func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
props := model.MapFromJson(r.Body)
|
commandArgs := model.CommandArgsFromJson(r.Body)
|
||||||
command := strings.TrimSpace(props["command"])
|
|
||||||
channelId := strings.TrimSpace(props["channelId"])
|
|
||||||
|
|
||||||
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, "")
|
c.Err = model.NewLocAppError("executeCommand", "api.command.execute_command.start.app_error", nil, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(channelId) > 0 {
|
if len(commandArgs.ChannelId) > 0 {
|
||||||
if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_USE_SLASH_COMMANDS) {
|
if !HasPermissionToChannelContext(c, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.Split(command, " ")
|
parts := strings.Split(commandArgs.Command, " ")
|
||||||
trigger := parts[0][1:]
|
trigger := parts[0][1:]
|
||||||
trigger = strings.ToLower(trigger)
|
trigger = strings.ToLower(trigger)
|
||||||
message := strings.Join(parts[1:], " ")
|
message := strings.Join(parts[1:], " ")
|
||||||
provider := GetCommandProvider(trigger)
|
provider := GetCommandProvider(trigger)
|
||||||
|
|
||||||
if provider != nil {
|
if provider != nil {
|
||||||
response := provider.DoCommand(c, channelId, message)
|
response := provider.DoCommand(c, commandArgs, message)
|
||||||
handleResponse(c, w, response, channelId, provider.GetCommand(c), true)
|
handleResponse(c, w, response, commandArgs, provider.GetCommand(c), true)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -121,7 +119,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chanChan := Srv.Store.Channel().Get(channelId)
|
chanChan := Srv.Store.Channel().Get(commandArgs.ChannelId)
|
||||||
teamChan := Srv.Store.Team().Get(c.TeamId)
|
teamChan := Srv.Store.Team().Get(c.TeamId)
|
||||||
userChan := Srv.Store.User().Get(c.Session.UserId)
|
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_id", cmd.TeamId)
|
||||||
p.Set("team_domain", team.Name)
|
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("channel_name", channel.Name)
|
||||||
|
|
||||||
p.Set("user_id", c.Session.UserId)
|
p.Set("user_id", c.Session.UserId)
|
||||||
@@ -200,7 +198,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
if response == nil {
|
if response == nil {
|
||||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
||||||
} else {
|
} else {
|
||||||
handleResponse(c, w, response, channelId, cmd, false)
|
handleResponse(c, w, response, commandArgs, cmd, false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defer resp.Body.Close()
|
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}, "")
|
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 := &model.Post{}
|
||||||
post.ChannelId = channelId
|
post.ChannelId = commandArgs.ChannelId
|
||||||
|
post.RootId = commandArgs.RootId
|
||||||
|
post.ParentId = commandArgs.ParentId
|
||||||
|
|
||||||
if !builtIn {
|
if !builtIn {
|
||||||
post.AddProp("from_webhook", "true")
|
post.AddProp("from_webhook", "true")
|
||||||
@@ -258,6 +257,7 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe
|
|||||||
post.Message = response.Text
|
post.Message = response.Text
|
||||||
post.CreateAt = model.GetMillis()
|
post.CreateAt = model.GetMillis()
|
||||||
post.UserId = c.Session.UserId
|
post.UserId = c.Session.UserId
|
||||||
|
post.ParentId = ""
|
||||||
SendEphemeralPost(
|
SendEphemeralPost(
|
||||||
c.TeamId,
|
c.TeamId,
|
||||||
c.Session.UserId,
|
c.Session.UserId,
|
||||||
|
|||||||
@@ -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")
|
rmsg := c.T("api.command_away.success")
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
rmsg = message + " " + rmsg
|
rmsg = message + " " + rmsg
|
||||||
|
|||||||
@@ -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
|
maxThreads := 100
|
||||||
|
|
||||||
delay := 0
|
delay := 0
|
||||||
@@ -75,7 +75,9 @@ func (me *EchoProvider) DoCommand(c *Context, channelId string, message string)
|
|||||||
go func() {
|
go func() {
|
||||||
defer func() { <-echoSem }()
|
defer func() { <-echoSem }()
|
||||||
post := &model.Post{}
|
post := &model.Post{}
|
||||||
post.ChannelId = channelId
|
post.ChannelId = args.ChannelId
|
||||||
|
post.RootId = args.RootId
|
||||||
|
post.ParentId = args.ParentId
|
||||||
post.Message = message
|
post.Message = message
|
||||||
post.UserId = c.Session.UserId
|
post.UserId = c.Session.UserId
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestEchoCommand(t *testing.T) {
|
|||||||
|
|
||||||
echoTestString := "/echo test"
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Echo command failed to execute")
|
t.Fatal("Echo command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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")
|
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")
|
return setCollapsePreference(c, "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func TestExpandCommand(t *testing.T) {
|
|||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
channel := th.BasicChannel
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
t.Fatal("Command failed to execute")
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ func TestCollapseCommand(t *testing.T) {
|
|||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
channel := th.BasicChannel
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
t.Fatal("Command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
if !utils.Cfg.EmailSettings.SendEmailNotifications {
|
||||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command.invite_people.email_off")}
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command.invite_people.email_off")}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,17 @@ func TestInvitePeopleCommand(t *testing.T) {
|
|||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
channel := th.BasicChannel
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
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 {
|
if r2 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
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 {
|
if r3 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
t.Fatal("Command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
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}
|
return &model.CommandResponse{Text: c.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ func TestJoinCommands(t *testing.T) {
|
|||||||
|
|
||||||
channel3 := Client.Must(Client.CreateDirectChannel(user2.Id)).Data.(*model.Channel)
|
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) {
|
if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) {
|
||||||
t.Fatal("failed to join channel")
|
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) {
|
if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) {
|
||||||
t.Fatal("should not have joined direct message channel")
|
t.Fatal("should not have joined direct message channel")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
//This command is only available when EnableTesting is true
|
||||||
if !utils.Cfg.ServiceSettings.EnableTesting {
|
if !utils.Cfg.ServiceSettings.EnableTesting {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestLoadTestHelpCommands(t *testing.T) {
|
|||||||
|
|
||||||
utils.Cfg.ServiceSettings.EnableTesting = true
|
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") {
|
if !strings.Contains(rs.Text, "Mattermost load testing commands to help") {
|
||||||
t.Fatal(rs.Text)
|
t.Fatal(rs.Text)
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ func TestLoadTestSetupCommands(t *testing.T) {
|
|||||||
|
|
||||||
utils.Cfg.ServiceSettings.EnableTesting = true
|
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" {
|
if rs.Text != "Created enviroment" {
|
||||||
t.Fatal(rs.Text)
|
t.Fatal(rs.Text)
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ func TestLoadTestUsersCommands(t *testing.T) {
|
|||||||
|
|
||||||
utils.Cfg.ServiceSettings.EnableTesting = true
|
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" {
|
if rs.Text != "Added users" {
|
||||||
t.Fatal(rs.Text)
|
t.Fatal(rs.Text)
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ func TestLoadTestChannelsCommands(t *testing.T) {
|
|||||||
|
|
||||||
utils.Cfg.ServiceSettings.EnableTesting = true
|
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" {
|
if rs.Text != "Added channels" {
|
||||||
t.Fatal(rs.Text)
|
t.Fatal(rs.Text)
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ func TestLoadTestPostsCommands(t *testing.T) {
|
|||||||
|
|
||||||
utils.Cfg.ServiceSettings.EnableTesting = true
|
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" {
|
if rs.Text != "Added posts" {
|
||||||
t.Fatal(rs.Text)
|
t.Fatal(rs.Text)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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")}
|
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")}
|
SUCCESS := &model.CommandResponse{GotoLocation: "/", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
|
||||||
|
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ import (
|
|||||||
func TestLogoutTestCommand(t *testing.T) {
|
func TestLogoutTestCommand(t *testing.T) {
|
||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
|
|
||||||
th.BasicClient.Must(th.BasicClient.Command(th.BasicChannel.Id, "/logout", false))
|
th.BasicClient.Must(th.BasicClient.Command(th.BasicChannel.Id, "/logout"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 + "*"}
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: "*" + message + "*"}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestMeCommand(t *testing.T) {
|
|||||||
|
|
||||||
testString := "/me hello"
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
t.Fatal("Command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
splitMessage := strings.SplitN(message, " ", 2)
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ func TestMsgCommands(t *testing.T) {
|
|||||||
Client.Must(Client.CreateDirectChannel(user2.Id))
|
Client.Must(Client.CreateDirectChannel(user2.Id))
|
||||||
Client.Must(Client.CreateDirectChannel(user3.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) {
|
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")
|
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) {
|
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")
|
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")
|
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) {
|
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")
|
t.Fatal("failed to go back to existing direct channel")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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")
|
rmsg := c.T("api.command_offline.success")
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
rmsg = message + " " + rmsg
|
rmsg = message + " " + rmsg
|
||||||
|
|||||||
@@ -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")
|
rmsg := c.T("api.command_online.success")
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
rmsg = message + " " + rmsg
|
rmsg = message + " " + rmsg
|
||||||
|
|||||||
@@ -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{
|
shortcutIds := [4]string{
|
||||||
"api.command_shortcuts.nav",
|
"api.command_shortcuts.nav",
|
||||||
"api.command_shortcuts.files",
|
"api.command_shortcuts.files",
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ func TestShortcutsCommand(t *testing.T) {
|
|||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
channel := th.BasicChannel
|
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") {
|
if !strings.Contains(rs.Text, "CTRL") {
|
||||||
t.Fatal("failed to display shortcuts")
|
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") {
|
if !strings.Contains(rs.Text, "CMD") {
|
||||||
t.Fatal("failed to display Mac shortcuts")
|
t.Fatal("failed to display Mac shortcuts")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 := `¯\\\_(ツ)\_/¯`
|
rmsg := `¯\\\_(ツ)\_/¯`
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
rmsg = message + " " + rmsg
|
rmsg = message + " " + rmsg
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestShrugCommand(t *testing.T) {
|
|||||||
|
|
||||||
testString := "/shrug"
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
t.Fatal("Command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func commandAndTest(t *testing.T, th *TestHelper, status string) {
|
|||||||
channel := th.BasicChannel
|
channel := th.BasicChannel
|
||||||
user := th.BasicUser
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Command failed to execute")
|
t.Fatal("Command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ func TestTestCommand(t *testing.T) {
|
|||||||
|
|
||||||
cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command)
|
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 {
|
if r1 == nil {
|
||||||
t.Fatal("Test command failed to execute")
|
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)
|
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 {
|
if r2 == nil {
|
||||||
t.Fatal("Test2 command failed to execute")
|
t.Fatal("Test2 command failed to execute")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
func (c *Client) Command(channelId string, command string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
args := &CommandArgs{ChannelId: channelId, Command: command}
|
||||||
m["command"] = command
|
if r, err := c.DoApiPost(c.GetTeamRoute()+"/commands/execute", args.ToJson()); err != nil {
|
||||||
m["channelId"] = channelId
|
|
||||||
m["suggest"] = strconv.FormatBool(suggest)
|
|
||||||
if r, err := c.DoApiPost(c.GetTeamRoute()+"/commands/execute", MapToJson(m)); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
|
|||||||
36
model/command_args.go
Обычный файл
36
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
let msg = message;
|
||||||
|
|
||||||
msg = msg.substring(0, msg.indexOf(' ')).toLowerCase() + msg.substring(msg.indexOf(' '), msg.length);
|
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';
|
msg = '/shortcuts';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Client.executeCommand(msg, args, success, error);
|
||||||
Client.executeCommand(channelId, msg, suggest, success, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setChannelAsRead(channelIdParam) {
|
export function setChannelAsRead(channelIdParam) {
|
||||||
|
|||||||
@@ -1494,13 +1494,13 @@ export default class Client {
|
|||||||
end(this.handleResponse.bind(this, 'listCommands', success, error));
|
end(this.handleResponse.bind(this, 'listCommands', success, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCommand(channelId, command, suggest, success, error) {
|
executeCommand(command, commandArgs, success, error) {
|
||||||
request.
|
request.
|
||||||
post(`${this.getCommandsRoute()}/execute`).
|
post(`${this.getCommandsRoute()}/execute`).
|
||||||
set(this.defaultHeaders).
|
set(this.defaultHeaders).
|
||||||
type('application/json').
|
type('application/json').
|
||||||
accept('application/json').
|
accept('application/json').
|
||||||
send({channelId, command, suggest: String(suggest)}).
|
send({command, ...commandArgs}).
|
||||||
end(this.handleResponse.bind(this, 'executeCommand', success, error));
|
end(this.handleResponse.bind(this, 'executeCommand', success, error));
|
||||||
|
|
||||||
this.track('api', 'api_integrations_used');
|
this.track('api', 'api_integrations_used');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
||||||
|
import * as ChannelActions from 'actions/channel_actions.jsx';
|
||||||
import EmojiStore from 'stores/emoji_store.jsx';
|
import EmojiStore from 'stores/emoji_store.jsx';
|
||||||
import UserStore from 'stores/user_store.jsx';
|
import UserStore from 'stores/user_store.jsx';
|
||||||
import PostDeletedModal from './post_deleted_modal.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 Constants from 'utils/constants.jsx';
|
||||||
|
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
|
import {browserHistory} from 'react-router/es6';
|
||||||
|
|
||||||
const ActionTypes = Constants.ActionTypes;
|
const ActionTypes = Constants.ActionTypes;
|
||||||
const KeyCodes = Constants.KeyCodes;
|
const KeyCodes = Constants.KeyCodes;
|
||||||
@@ -121,7 +123,6 @@ export default class CreateComment extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageHistoryStore.storeMessageInHistory(message);
|
MessageHistoryStore.storeMessageInHistory(message);
|
||||||
|
|
||||||
if (message.trim().length === 0 && this.state.fileInfos.length === 0) {
|
if (message.trim().length === 0 && this.state.fileInfos.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -129,6 +130,8 @@ export default class CreateComment extends React.Component {
|
|||||||
const isReaction = REACTION_PATTERN.exec(message);
|
const isReaction = REACTION_PATTERN.exec(message);
|
||||||
if (isReaction && EmojiStore.has(isReaction[2])) {
|
if (isReaction && EmojiStore.has(isReaction[2])) {
|
||||||
this.handleSubmitReaction(isReaction);
|
this.handleSubmitReaction(isReaction);
|
||||||
|
} else if (message.indexOf('/') === 0) {
|
||||||
|
this.handleSubmitCommand(message);
|
||||||
} else {
|
} else {
|
||||||
this.handleSubmitPost(message);
|
this.handleSubmitPost(message);
|
||||||
}
|
}
|
||||||
@@ -146,6 +149,36 @@ export default class CreateComment extends React.Component {
|
|||||||
this.focusTextbox(forceFocus);
|
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) {
|
handleSubmitPost(message) {
|
||||||
const userId = UserStore.getCurrentId();
|
const userId = UserStore.getCurrentId();
|
||||||
const time = Utils.getTimestamp();
|
const time = Utils.getTimestamp();
|
||||||
@@ -444,7 +477,6 @@ export default class CreateComment extends React.Component {
|
|||||||
onBlur={this.handleBlur}
|
onBlur={this.handleBlur}
|
||||||
createMessage={Utils.localizeMessage('create_comment.addComment', 'Add a comment...')}
|
createMessage={Utils.localizeMessage('create_comment.addComment', 'Add a comment...')}
|
||||||
initialText=''
|
initialText=''
|
||||||
supportsCommands={false}
|
|
||||||
channelId={this.props.channelId}
|
channelId={this.props.channelId}
|
||||||
id='reply_textbox'
|
id='reply_textbox'
|
||||||
ref='textbox'
|
ref='textbox'
|
||||||
|
|||||||
@@ -112,10 +112,11 @@ export default class CreatePost extends React.Component {
|
|||||||
PostStore.storeDraft(this.state.channelId, null);
|
PostStore.storeDraft(this.state.channelId, null);
|
||||||
this.setState({message: '', postError: null, fileInfos: []});
|
this.setState({message: '', postError: null, fileInfos: []});
|
||||||
|
|
||||||
|
const args = {};
|
||||||
|
args.channel_id = this.state.channelId;
|
||||||
ChannelActions.executeCommand(
|
ChannelActions.executeCommand(
|
||||||
this.state.channelId,
|
|
||||||
post.message,
|
post.message,
|
||||||
false,
|
args,
|
||||||
(data) => {
|
(data) => {
|
||||||
this.setState({submitting: false});
|
this.setState({submitting: false});
|
||||||
|
|
||||||
@@ -357,10 +358,11 @@ export default class CreatePost extends React.Component {
|
|||||||
showShortcuts(e) {
|
showShortcuts(e) {
|
||||||
if ((e.ctrlKey || e.metaKey) && e.keyCode === Constants.KeyCodes.FORWARD_SLASH) {
|
if ((e.ctrlKey || e.metaKey) && e.keyCode === Constants.KeyCodes.FORWARD_SLASH) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
const args = {};
|
||||||
|
args.channel_id = this.state.channelId;
|
||||||
ChannelActions.executeCommand(
|
ChannelActions.executeCommand(
|
||||||
this.state.channelId,
|
'/shortcuts',
|
||||||
'/shortcuts ',
|
args,
|
||||||
false,
|
|
||||||
null,
|
null,
|
||||||
(err) => {
|
(err) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ export default class PostList extends React.Component {
|
|||||||
|
|
||||||
if (commentRootId) {
|
if (commentRootId) {
|
||||||
for (const postId in posts) {
|
for (const postId in posts) {
|
||||||
if (posts[postId].root_id === commentRootId) {
|
if (posts[postId].root_id === commentRootId && !PostUtils.isSystemMessage(posts[postId])) {
|
||||||
commentCount += 1;
|
commentCount += 1;
|
||||||
if (posts[postId].user_id === userId) {
|
if (posts[postId].user_id === userId) {
|
||||||
shouldHighlightThreads = true;
|
shouldHighlightThreads = true;
|
||||||
|
|||||||
@@ -227,6 +227,8 @@ export default class RhsComment extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const post = this.props.post;
|
const post = this.props.post;
|
||||||
const flagIcon = Constants.FLAG_ICON_SVG;
|
const flagIcon = Constants.FLAG_ICON_SVG;
|
||||||
|
const mattermostLogo = Constants.MATTERMOST_ICON_SVG;
|
||||||
|
const isSystemMessage = PostUtils.isSystemMessage(post);
|
||||||
|
|
||||||
var currentUserCss = '';
|
var currentUserCss = '';
|
||||||
if (this.props.currentUser === post.user_id) {
|
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;
|
var timestamp = this.props.currentUser.update_at;
|
||||||
|
|
||||||
let botIndicator;
|
let botIndicator;
|
||||||
|
let userProfile = (
|
||||||
|
<UserProfile user={this.props.user}/>
|
||||||
|
);
|
||||||
if (post.props && post.props.from_webhook) {
|
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>;
|
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 loading;
|
||||||
let postClass = '';
|
let postClass = '';
|
||||||
let message = <PostMessageContainer post={post}/>;
|
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;
|
let status = this.props.status;
|
||||||
if (post.props && post.props.from_webhook === 'true') {
|
if (post.props && post.props.from_webhook === 'true') {
|
||||||
status = null;
|
status = null;
|
||||||
@@ -279,6 +307,15 @@ export default class RhsComment extends React.Component {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isSystemMessage) {
|
||||||
|
profilePic = (
|
||||||
|
<span
|
||||||
|
className='icon'
|
||||||
|
dangerouslySetInnerHTML={{__html: mattermostLogo}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let compactClass = '';
|
let compactClass = '';
|
||||||
if (this.props.compactDisplay) {
|
if (this.props.compactDisplay) {
|
||||||
compactClass = 'post--compact';
|
compactClass = 'post--compact';
|
||||||
@@ -387,13 +424,13 @@ export default class RhsComment extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'post post--thread ' + currentUserCss + ' ' + compactClass}>
|
<div className={'post post--thread ' + currentUserCss + ' ' + compactClass + ' ' + systemMessageClass}>
|
||||||
<div className='post__content'>
|
<div className='post__content'>
|
||||||
{profilePicContainer}
|
{profilePicContainer}
|
||||||
<div>
|
<div>
|
||||||
<ul className='post__header'>
|
<ul className='post__header'>
|
||||||
<li className='col col__name'>
|
<li className='col col__name'>
|
||||||
<strong><UserProfile user={this.props.user}/></strong>
|
<strong>{userProfile}</strong>
|
||||||
</li>
|
</li>
|
||||||
{botIndicator}
|
{botIndicator}
|
||||||
<li className='col'>
|
<li className='col'>
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ describe('Client.Commands', function() {
|
|||||||
|
|
||||||
it('executeCommand', function(done) {
|
it('executeCommand', function(done) {
|
||||||
TestHelper.initBasic(() => {
|
TestHelper.initBasic(() => {
|
||||||
|
const args = {};
|
||||||
|
args.channel_id = TestHelper.basicChannel().id;
|
||||||
TestHelper.basicClient().executeCommand(
|
TestHelper.basicClient().executeCommand(
|
||||||
TestHelper.basicChannel().id,
|
|
||||||
'/shrug',
|
'/shrug',
|
||||||
null,
|
args,
|
||||||
function(data) {
|
function(data) {
|
||||||
assert.equal(data.response_type, 'in_channel');
|
assert.equal(data.response_type, 'in_channel');
|
||||||
done();
|
done();
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user