Fix /msg switching teams (#7753)
* Fix /msg switching teams * simplify a bit
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
23e4b4a27d
Коммит
bd3b7aeeea
@@ -37,12 +37,10 @@ func (me *msgProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||||
|
|
||||||
splitMessage := strings.SplitN(message, " ", 2)
|
splitMessage := strings.SplitN(message, " ", 2)
|
||||||
|
|
||||||
parsedMessage := ""
|
parsedMessage := ""
|
||||||
targetUsername := ""
|
targetUsername := ""
|
||||||
teamId := ""
|
|
||||||
|
|
||||||
if len(splitMessage) > 1 {
|
if len(splitMessage) > 1 {
|
||||||
parsedMessage = strings.SplitN(message, " ", 2)[1]
|
parsedMessage = strings.SplitN(message, " ", 2)[1]
|
||||||
@@ -81,7 +79,6 @@ func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string
|
|||||||
} else {
|
} else {
|
||||||
channel := channel.Data.(*model.Channel)
|
channel := channel.Data.(*model.Channel)
|
||||||
targetChannelId = channel.Id
|
targetChannelId = channel.Id
|
||||||
teamId = channel.TeamId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(parsedMessage) > 0 {
|
if len(parsedMessage) > 0 {
|
||||||
@@ -94,6 +91,7 @@ func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
teamId := args.TeamId
|
||||||
if teamId == "" {
|
if teamId == "" {
|
||||||
if len(args.Session.TeamMembers) == 0 {
|
if len(args.Session.TeamMembers) == 0 {
|
||||||
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
|
|||||||
31
app/command_msg_test.go
Обычный файл
31
app/command_msg_test.go
Обычный файл
@@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMsgProvider(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
team := th.CreateTeam()
|
||||||
|
th.LinkUserToTeam(th.BasicUser, team)
|
||||||
|
cmd := &msgProvider{}
|
||||||
|
resp := cmd.DoCommand(th.App, &model.CommandArgs{
|
||||||
|
T: i18n.IdentityTfunc(),
|
||||||
|
SiteURL: "http://test.url",
|
||||||
|
TeamId: team.Id,
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
}, "@"+th.BasicUser2.Username+" hello")
|
||||||
|
channelName := model.GetDMNameFromIds(th.BasicUser.Id, th.BasicUser2.Id)
|
||||||
|
assert.Equal(t, "", resp.Text)
|
||||||
|
assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation)
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user