summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-06-27 08:46:38 -0400
committerGitHub <noreply@github.com>2018-06-27 08:46:38 -0400
commitd7976549a0b45a42c04ac043a15677b7ca1228e9 (patch)
tree14940a3a61bbff407887a2d5afcd8ea71ab41fb1 /plugin
parent1e5c432e1029601a664454388ae366ef69618d62 (diff)
downloadchat-d7976549a0b45a42c04ac043a15677b7ca1228e9.tar.gz
chat-d7976549a0b45a42c04ac043a15677b7ca1228e9.tar.bz2
chat-d7976549a0b45a42c04ac043a15677b7ca1228e9.zip
MM-9674 Add plugin API for publishing custom WebSocket events (#8999)
* Add plugin API for publishing custom WebSocket events * Add clearer payload comment * Update comment
Diffstat (limited to 'plugin')
-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
4 files changed, 40 insertions, 2 deletions
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`.