summaryrefslogtreecommitdiffstats
path: root/plugin/rpcplugin/hooks.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-12-08 13:55:41 -0600
committerGitHub <noreply@github.com>2017-12-08 13:55:41 -0600
commit4c17bdff1bb871fb31520b7b547f584c53ed854f (patch)
treeedf1e3295d6ff7d67281efc585b2e913b4efda3d /plugin/rpcplugin/hooks.go
parent7ed1177a2b676aa4c93515268642c855cfe57a37 (diff)
downloadchat-4c17bdff1bb871fb31520b7b547f584c53ed854f.tar.gz
chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.tar.bz2
chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.zip
Add plugin slash command support (#7941)
* add plugin slash command support * remove unused string * rebase
Diffstat (limited to 'plugin/rpcplugin/hooks.go')
-rw-r--r--plugin/rpcplugin/hooks.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/plugin/rpcplugin/hooks.go b/plugin/rpcplugin/hooks.go
index 22f26e22e..7b44d0de7 100644
--- a/plugin/rpcplugin/hooks.go
+++ b/plugin/rpcplugin/hooks.go
@@ -11,6 +11,7 @@ import (
"net/rpc"
"reflect"
+ "github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
)
@@ -125,6 +126,20 @@ func (h *LocalHooks) ServeHTTP(args ServeHTTPArgs, reply *struct{}) error {
return nil
}
+type HooksExecuteCommandReply struct {
+ Response *model.CommandResponse
+ Error *model.AppError
+}
+
+func (h *LocalHooks) ExecuteCommand(args *model.CommandArgs, reply *HooksExecuteCommandReply) error {
+ if hook, ok := h.hooks.(interface {
+ ExecuteCommand(*model.CommandArgs) (*model.CommandResponse, *model.AppError)
+ }); ok {
+ reply.Response, reply.Error = hook.ExecuteCommand(args)
+ }
+ return nil
+}
+
func ServeHooks(hooks interface{}, conn io.ReadWriteCloser, muxer *Muxer) {
server := rpc.NewServer()
server.Register(&LocalHooks{
@@ -141,6 +156,7 @@ const (
remoteOnDeactivate = 1
remoteServeHTTP = 2
remoteOnConfigurationChange = 3
+ remoteExecuteCommand = 4
maxRemoteHookCount = iota
)
@@ -225,6 +241,17 @@ func (h *RemoteHooks) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
+func (h *RemoteHooks) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
+ if !h.implemented[remoteExecuteCommand] {
+ return nil, model.NewAppError("RemoteHooks.ExecuteCommand", "plugin.rpcplugin.invocation.error", nil, "err=ExecuteCommand hook not implemented", http.StatusInternalServerError)
+ }
+ var reply HooksExecuteCommandReply
+ if err := h.client.Call("LocalHooks.ExecuteCommand", args, &reply); err != nil {
+ return nil, model.NewAppError("RemoteHooks.ExecuteCommand", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
+ }
+ return reply.Response, reply.Error
+}
+
func (h *RemoteHooks) Close() error {
if h.apiCloser != nil {
h.apiCloser.Close()
@@ -253,6 +280,8 @@ func ConnectHooks(conn io.ReadWriteCloser, muxer *Muxer) (*RemoteHooks, error) {
remote.implemented[remoteOnConfigurationChange] = true
case "ServeHTTP":
remote.implemented[remoteServeHTTP] = true
+ case "ExecuteCommand":
+ remote.implemented[remoteExecuteCommand] = true
}
}
return remote, nil