summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/plugin_api.go9
-rw-r--r--plugin/api.go6
-rw-r--r--plugin/client_rpc_generated.go27
-rw-r--r--plugin/plugintest/api.go7
-rw-r--r--plugin/plugintest/hooks.go2
5 files changed, 49 insertions, 2 deletions
diff --git a/app/plugin_api.go b/app/plugin_api.go
index ffb8cccd6..fc786202e 100644
--- a/app/plugin_api.go
+++ b/app/plugin_api.go
@@ -5,6 +5,7 @@ package app
import (
"encoding/json"
+ "fmt"
"github.com/mattermost/mattermost-server/model"
)
@@ -176,3 +177,11 @@ func (api *PluginAPI) KVGet(key string) ([]byte, *model.AppError) {
func (api *PluginAPI) KVDelete(key string) *model.AppError {
return api.app.DeletePluginKey(api.id, key)
}
+
+func (api *PluginAPI) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) {
+ api.app.Publish(&model.WebSocketEvent{
+ Event: fmt.Sprintf("custom_%v_%v", api.id, event),
+ Data: payload,
+ Broadcast: broadcast,
+ })
+}
diff --git a/plugin/api.go b/plugin/api.go
index ed2bfa733..842cef4f6 100644
--- a/plugin/api.go
+++ b/plugin/api.go
@@ -113,6 +113,12 @@ type API interface {
// Delete will remove a key-value pair. Returns nil for non-existent keys.
KVDelete(key string) *model.AppError
+
+ // PublishWebSocketEvent sends an event to WebSocket connections.
+ // event is the type and will be prepended with "custom_<pluginid>_"
+ // payload is the data sent with the event. Interface values must be primitive Go types or mattermost-server/model types
+ // broadcast determines to which users to send the event
+ PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast)
}
var Handshake = plugin.HandshakeConfig{
diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go
index b32a3e36e..9880814b2 100644
--- a/plugin/client_rpc_generated.go
+++ b/plugin/client_rpc_generated.go
@@ -1101,3 +1101,30 @@ func (s *APIRPCServer) KVDelete(args *KVDeleteArgs, returns *KVDeleteReturns) er
}
return nil
}
+
+type PublishWebSocketEventArgs struct {
+ A string
+ B map[string]interface{}
+ C *model.WebsocketBroadcast
+}
+
+type PublishWebSocketEventReturns struct {
+}
+
+func (g *APIRPCClient) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) {
+ _args := &PublishWebSocketEventArgs{event, payload, broadcast}
+ _returns := &PublishWebSocketEventReturns{}
+ if err := g.client.Call("Plugin.PublishWebSocketEvent", _args, _returns); err != nil {
+ g.log.Error("RPC call to PublishWebSocketEvent API failed.", mlog.Err(err))
+ }
+ return
+}
+
+func (s *APIRPCServer) PublishWebSocketEvent(args *PublishWebSocketEventArgs, returns *PublishWebSocketEventReturns) error {
+ if hook, ok := s.impl.(interface {
+ PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast)
+ }); ok {
+ hook.PublishWebSocketEvent(args.A, args.B, args.C)
+ }
+ return nil
+}
diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go
index 11c5a9c59..145fcbf9d 100644
--- a/plugin/plugintest/api.go
+++ b/plugin/plugintest/api.go
@@ -1,4 +1,4 @@
-// Code generated by mockery v1.0.0. DO NOT EDIT.
+// Code generated by mockery v1.0.0
// Regenerate this file using `make plugin-mocks`.
@@ -563,6 +563,11 @@ func (_m *API) LoadPluginConfiguration(dest interface{}) error {
return r0
}
+// PublishWebSocketEvent provides a mock function with given fields: event, payload, broadcast
+func (_m *API) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) {
+ _m.Called(event, payload, broadcast)
+}
+
// RegisterCommand provides a mock function with given fields: command
func (_m *API) RegisterCommand(command *model.Command) error {
ret := _m.Called(command)
diff --git a/plugin/plugintest/hooks.go b/plugin/plugintest/hooks.go
index 790a5a993..0d335a626 100644
--- a/plugin/plugintest/hooks.go
+++ b/plugin/plugintest/hooks.go
@@ -1,4 +1,4 @@
-// Code generated by mockery v1.0.0. DO NOT EDIT.
+// Code generated by mockery v1.0.0
// Regenerate this file using `make plugin-mocks`.