summaryrefslogtreecommitdiffstats
path: root/plugin/pluginenv/environment.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/pluginenv/environment.go')
-rw-r--r--plugin/pluginenv/environment.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/plugin/pluginenv/environment.go b/plugin/pluginenv/environment.go
index adc02e885..947eda86d 100644
--- a/plugin/pluginenv/environment.go
+++ b/plugin/pluginenv/environment.go
@@ -306,6 +306,65 @@ func (h *MultiPluginHooks) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
}
+// MessageWillBePosted invokes the MessageWillBePosted hook for all plugins. Ordering
+// is not guaranteed and the next plugin will get the previous one's modifications.
+// if a plugin rejects a post, the rest of the plugins will not know that an attempt was made.
+// Returns the final result post, or nil if the post was rejected and a string with a reason
+// for the user the message was rejected.
+func (h *MultiPluginHooks) MessageWillBePosted(post *model.Post) (*model.Post, string) {
+ h.env.mutex.RLock()
+ defer h.env.mutex.RUnlock()
+
+ for _, activePlugin := range h.env.activePlugins {
+ if activePlugin.Supervisor == nil {
+ continue
+ }
+ var rejectionReason string
+ post, rejectionReason = activePlugin.Supervisor.Hooks().MessageWillBePosted(post)
+ if post == nil {
+ return nil, rejectionReason
+ }
+ }
+ return post, ""
+}
+
+// MessageWillBeUpdated invokes the MessageWillBeUpdated hook for all plugins. Ordering
+// is not guaranteed and the next plugin will get the previous one's modifications.
+// if a plugin rejects a post, the rest of the plugins will not know that an attempt was made.
+// Returns the final result post, or nil if the post was rejected and a string with a reason
+// for the user the message was rejected.
+func (h *MultiPluginHooks) MessageWillBeUpdated(newPost, oldPost *model.Post) (*model.Post, string) {
+ h.env.mutex.RLock()
+ defer h.env.mutex.RUnlock()
+
+ post := newPost
+ for _, activePlugin := range h.env.activePlugins {
+ if activePlugin.Supervisor == nil {
+ continue
+ }
+ var rejectionReason string
+ post, rejectionReason = activePlugin.Supervisor.Hooks().MessageWillBeUpdated(post, oldPost)
+ if post == nil {
+ return nil, rejectionReason
+ }
+ }
+ return post, ""
+}
+
+func (h *MultiPluginHooks) MessageHasBeenPosted(post *model.Post) {
+ h.invoke(func(hooks plugin.Hooks) error {
+ hooks.MessageHasBeenPosted(post)
+ return nil
+ })
+}
+
+func (h *MultiPluginHooks) MessageHasBeenUpdated(newPost, oldPost *model.Post) {
+ h.invoke(func(hooks plugin.Hooks) error {
+ hooks.MessageHasBeenUpdated(newPost, oldPost)
+ return nil
+ })
+}
+
func (h *SinglePluginHooks) invoke(f func(plugin.Hooks) error) error {
h.env.mutex.RLock()
defer h.env.mutex.RUnlock()