Commit e9c6cc26 authored by Joram Wilander's avatar Joram Wilander Committed by Christopher Speller

Move command logic into app layer (#5617)

parent 8b0eedbb
This diff is collapsed.
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/model"
......
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/model"
......
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/model"
......
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"bytes"
......
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/model"
......
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
......@@ -50,8 +49,8 @@ func CreateBasicUser(client *model.Client) *model.AppError {
return err
}
ruser := result.Data.(*model.User)
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
store.Must(app.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
store.Must(Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}))
}
return nil
}
......@@ -82,14 +81,14 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
ruser := result.Data.(*model.User)
status := &model.Status{UserId: ruser.Id, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
if result := <-app.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
if result := <-Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
result.Err.Translate(utils.T)
l4g.Error(result.Err.Error())
return nil, false
}
// We need to cheat to verify the user's email
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
return result.Data.(*model.User), true
}
......
This diff is collapsed.
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type AwayProvider struct {
......@@ -23,21 +23,21 @@ func (me *AwayProvider) GetTrigger() string {
return CMD_AWAY
}
func (me *AwayProvider) GetCommand(c *Context) *model.Command {
func (me *AwayProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_AWAY,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_away.desc"),
DisplayName: c.T("api.command_away.name"),
AutoCompleteDesc: T("api.command_away.desc"),
DisplayName: T("api.command_away.name"),
}
}
func (me *AwayProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := c.T("api.command_away.success")
func (me *AwayProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := args.T("api.command_away.success")
if len(message) > 0 {
rmsg = message + " " + rmsg
}
app.SetStatusAwayIfNeeded(c.Session.UserId, true)
SetStatusAwayIfNeeded(args.UserId, true)
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: rmsg}
}
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"strconv"
......@@ -9,8 +9,8 @@ import (
"time"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
var echoSem chan bool
......@@ -30,19 +30,19 @@ func (me *EchoProvider) GetTrigger() string {
return CMD_ECHO
}
func (me *EchoProvider) GetCommand(c *Context) *model.Command {
func (me *EchoProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ECHO,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_echo.desc"),
AutoCompleteHint: c.T("api.command_echo.hint"),
DisplayName: c.T("api.command_echo.name"),
AutoCompleteDesc: T("api.command_echo.desc"),
AutoCompleteHint: T("api.command_echo.hint"),
DisplayName: T("api.command_echo.name"),
}
}
func (me *EchoProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *EchoProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
if len(message) == 0 {
return &model.CommandResponse{Text: c.T("api.command_echo.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_echo.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
maxThreads := 100
......@@ -64,7 +64,7 @@ func (me *EchoProvider) DoCommand(c *Context, args *model.CommandArgs, message s
}
if delay > 10000 {
return &model.CommandResponse{Text: c.T("api.command_echo.delay.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_echo.delay.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
if echoSem == nil {
......@@ -73,7 +73,7 @@ func (me *EchoProvider) DoCommand(c *Context, args *model.CommandArgs, message s
}
if len(echoSem) >= maxThreads {
return &model.CommandResponse{Text: c.T("api.command_echo.high_volume.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_echo.high_volume.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
echoSem <- true
......@@ -84,12 +84,12 @@ func (me *EchoProvider) DoCommand(c *Context, args *model.CommandArgs, message s
post.RootId = args.RootId
post.ParentId = args.ParentId
post.Message = message
post.UserId = c.Session.UserId
post.UserId = args.UserId
time.Sleep(time.Duration(delay) * time.Second)
if _, err := app.CreatePost(post, c.TeamId, true); err != nil {
l4g.Error(c.T("api.command_echo.create.app_error"), err)
if _, err := CreatePost(post, args.TeamId, true); err != nil {
l4g.Error(args.T("api.command_echo.create.app_error"), err)
}
}()
......
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"strconv"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type ExpandProvider struct {
......@@ -34,54 +34,54 @@ func (me *CollapseProvider) GetTrigger() string {
return CMD_COLLAPSE
}
func (me *ExpandProvider) GetCommand(c *Context) *model.Command {
func (me *ExpandProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_EXPAND,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_expand.desc"),
DisplayName: c.T("api.command_expand.name"),
AutoCompleteDesc: T("api.command_expand.desc"),
DisplayName: T("api.command_expand.name"),
}
}
func (me *CollapseProvider) GetCommand(c *Context) *model.Command {
func (me *CollapseProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_COLLAPSE,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_collapse.desc"),
DisplayName: c.T("api.command_collapse.name"),
AutoCompleteDesc: T("api.command_collapse.desc"),
DisplayName: T("api.command_collapse.name"),
}
}
func (me *ExpandProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(c, false)
func (me *ExpandProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(args, false)
}
func (me *CollapseProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(c, true)
func (me *CollapseProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(args, true)
}
func setCollapsePreference(c *Context, isCollapse bool) *model.CommandResponse {
func setCollapsePreference(args *model.CommandArgs, isCollapse bool) *model.CommandResponse {
pref := model.Preference{
UserId: c.Session.UserId,
UserId: args.UserId,
Category: model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS,
Name: model.PREFERENCE_NAME_COLLAPSE_SETTING,
Value: strconv.FormatBool(isCollapse),
}
if result := <-app.Srv.Store.Preference().Save(&model.Preferences{pref}); result.Err != nil {
return &model.CommandResponse{Text: c.T("api.command_expand_collapse.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
if result := <-Srv.Store.Preference().Save(&model.Preferences{pref}); result.Err != nil {
return &model.CommandResponse{Text: args.T("api.command_expand_collapse.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
socketMessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PREFERENCE_CHANGED, "", "", c.Session.UserId, nil)
socketMessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PREFERENCE_CHANGED, "", "", args.UserId, nil)
socketMessage.Add("preference", pref.ToJson())
go app.Publish(socketMessage)
go Publish(socketMessage)
var rmsg string
if isCollapse {
rmsg = c.T("api.command_collapse.success")
rmsg = args.T("api.command_collapse.success")
} else {
rmsg = c.T("api.command_expand.success")
rmsg = args.T("api.command_expand.success")
}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: rmsg}
}
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"strings"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type InvitePeopleProvider struct {
......@@ -27,19 +27,19 @@ func (me *InvitePeopleProvider) GetTrigger() string {
return CMD_INVITE_PEOPLE
}
func (me *InvitePeopleProvider) GetCommand(c *Context) *model.Command {
func (me *InvitePeopleProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_INVITE_PEOPLE,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command.invite_people.desc"),
AutoCompleteHint: c.T("api.command.invite_people.hint"),
DisplayName: c.T("api.command.invite_people.name"),
AutoCompleteDesc: T("api.command.invite_people.desc"),
AutoCompleteHint: T("api.command.invite_people.hint"),
DisplayName: T("api.command.invite_people.name"),
}
}
func (me *InvitePeopleProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *InvitePeopleProvider) DoCommand(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")}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.email_off")}
}
emailList := strings.Fields(message)
......@@ -52,13 +52,13 @@ func (me *InvitePeopleProvider) DoCommand(c *Context, args *model.CommandArgs, m
}
if len(emailList) == 0 {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command.invite_people.no_email")}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.no_email")}
}
if err := app.InviteNewUsersToTeam(emailList, c.TeamId, c.Session.UserId, c.GetSiteURL()); err != nil {
if err := InviteNewUsersToTeam(emailList, args.TeamId, args.UserId, args.SiteURL); err != nil {
l4g.Error(err.Error())
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command.invite_people.fail")}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.fail")}
}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command.invite_people.sent")}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.sent")}
}
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type JoinProvider struct {
......@@ -23,35 +23,40 @@ func (me *JoinProvider) GetTrigger() string {
return CMD_JOIN
}
func (me *JoinProvider) GetCommand(c *Context) *model.Command {
func (me *JoinProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_JOIN,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_join.desc"),
AutoCompleteHint: c.T("api.command_join.hint"),
DisplayName: c.T("api.command_join.name"),
AutoCompleteDesc: T("api.command_join.desc"),
AutoCompleteHint: T("api.command_join.hint"),
DisplayName: T("api.command_join.name"),
}
}
func (me *JoinProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
if result := <-app.Srv.Store.Channel().GetByName(c.TeamId, message, true); result.Err != nil {
return &model.CommandResponse{Text: c.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
func (me *JoinProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
if result := <-Srv.Store.Channel().GetByName(args.TeamId, message, true); result.Err != nil {
return &model.CommandResponse{Text: args.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
} else {
channel := result.Data.(*model.Channel)
if channel.Name == message {
if channel.Type != model.CHANNEL_OPEN {
return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
if err := app.JoinChannel(channel, c.Session.UserId); err != nil {
return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
if err := JoinChannel(channel, args.UserId); err != nil {
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + channel.Name, Text: c.T("api.command_join.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
team, err := GetTeam(channel.TeamId)
if err != nil {
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
return &model.CommandResponse{GotoLocation: args.SiteURL + "/" + team.Name + "/channels/" + channel.Name, Text: args.T("api.command_join.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_join.missing.app_error")}
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_join.missing.app_error")}
}
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type LogoutProvider struct {
......@@ -23,23 +23,23 @@ func (me *LogoutProvider) GetTrigger() string {
return CMD_LOGOUT
}
func (me *LogoutProvider) GetCommand(c *Context) *model.Command {
func (me *LogoutProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_LOGOUT,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_logout.desc"),
AutoCompleteDesc: T("api.command_logout.desc"),
AutoCompleteHint: "",
DisplayName: c.T("api.command_logout.name"),
DisplayName: T("api.command_logout.name"),
}
}
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")}
func (me *LogoutProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_logout.fail_message")}
SUCCESS := &model.CommandResponse{GotoLocation: "/login"}
// We can't actually remove the user's cookie from here so we just dump their session and let the browser figure it out
if c.Session.Id != "" {
if err := app.RevokeSessionById(c.Session.Id); err != nil {
if args.Session.Id != "" {
if err := RevokeSessionById(args.Session.Id); err != nil {
return FAIL
}
return SUCCESS
......
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type MeProvider struct {
......@@ -22,16 +23,16 @@ func (me *MeProvider) GetTrigger() string {
return CMD_ME
}
func (me *MeProvider) GetCommand(c *Context) *model.Command {
func (me *MeProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ME,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_me.desc"),
AutoCompleteHint: c.T("api.command_me.hint"),
DisplayName: c.T("api.command_me.name"),
AutoCompleteDesc: T("api.command_me.desc"),
AutoCompleteHint: T("api.command_me.hint"),
DisplayName: T("api.command_me.name"),
}
}
func (me *MeProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *MeProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: "*" + message + "*"}
}
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"strings"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type msgProvider struct {
......@@ -26,22 +26,23 @@ func (me *msgProvider) GetTrigger() string {
return CMD_MSG
}
func (me *msgProvider) GetCommand(c *Context) *model.Command {
func (me *msgProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_MSG,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_msg.desc"),
AutoCompleteHint: c.T("api.command_msg.hint"),
DisplayName: c.T("api.command_msg.name"),
AutoCompleteDesc: T("api.command_msg.desc"),
AutoCompleteHint: T("api.command_msg.hint"),
DisplayName: T("api.command_msg.name"),
}
}
func (me *msgProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *msgProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
splitMessage := strings.SplitN(message, " ", 2)
parsedMessage := ""
targetUsername := ""
teamId := ""
if len(splitMessage) > 1 {
parsedMessage = strings.SplitN(message, " ", 2)[1]
......@@ -50,46 +51,60 @@ func (me *msgProvider) DoCommand(c *Context, args *model.CommandArgs, message st
targetUsername = strings.TrimPrefix(targetUsername, "@")
var userProfile *model.User
if result := <-app.Srv.Store.User().GetByUsername(targetUsername); result.Err != nil {
if result := <-Srv.Store.User().GetByUsername(targetUsername); result.Err != nil {
l4g.Error(result.Err.Error())
return &model.CommandResponse{Text: c.T("api.command_msg.missing.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_msg.missing.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
} else {
userProfile = result.Data.(*model.User)
}
if userProfile.Id == c.Session.UserId {
return &model.CommandResponse{Text: c.T("api.command_msg.missing.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
if userProfile.Id == args.UserId {
return &model.CommandResponse{Text: args.T("api.command_msg.missing.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
// Find the channel based on this user
channelName := model.GetDMNameFromIds(c.Session.UserId, userProfile.Id)
channelName := model.GetDMNameFromIds(args.UserId, userProfile.Id)
targetChannelId := ""
if channel := <-app.Srv.Store.Channel().GetByName(c.TeamId, channelName, true); channel.Err != nil {
if channel := <-Srv.Store.Channel().GetByName(args.TeamId, channelName, true); channel.Err != nil {
if channel.Err.Id == "store.sql_channel.get_by_name.missing.app_error" {
if directChannel, err := app.CreateDirectChannel(c.Session.UserId, userProfile.Id); err != nil {
if directChannel, err := CreateDirectChannel(args.UserId, userProfile.Id); err != nil {
l4g.Error(err.Error())
return &model.CommandResponse{Text: c.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
} else {
targetChannelId = directChannel.Id
}
} else {
l4g.Error(channel.Err.Error())
return &model.CommandResponse{Text: c.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
return &model.CommandResponse{Text: args.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
} else {
targetChannelId = channel.Data.(*model.Channel).Id
channel := channel.Data.(*model.Channel)
targetChannelId = channel.Id
teamId = channel.TeamId
}
if len(parsedMessage) > 0 {
post := &model.Post{}
post.Message = parsedMessage
post.ChannelId = targetChannelId
post.UserId = c.Session.UserId
if _, err := app.CreatePost(post, c.TeamId, true); err != nil {
return &model.CommandResponse{Text: c.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
post.UserId = args.UserId
if _, err := CreatePost(post, args.TeamId, true); err != nil {
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
}
return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + channelName, Text: "", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
if teamId == "" {
if len(args.Session.TeamMembers) == 0 {
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
teamId = args.Session.TeamMembers[0].TeamId
}
team, err := GetTeam(teamId)
if err != nil {
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
return &model.CommandResponse{GotoLocation: args.SiteURL + "/" + team.Name + "/channels/" + channelName, Text: "", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package api
package app
import (
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
type OfflineProvider struct {
......@@ -23,21 +23,21 @@ func (me *OfflineProvider) GetTrigger() string {
return CMD_OFFLINE
}
func (me *OfflineProvider) GetCommand(c *Context) *model.Command {
func (me *OfflineProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_OFFLINE,
AutoComplete: true,
AutoCompleteDesc: c.T("api.command_offline.desc"),
DisplayName: c.T("api.command_offline.name"),
AutoCompleteDesc: T("api.command_offline.desc"),
DisplayName: T("api.command_offline.name"),
}
}
func (me *OfflineProvider) DoCommand(c *Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := c.T("api.command_offline.success")
func (me *OfflineProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {