diff options
Diffstat (limited to 'app/post.go')
-rw-r--r-- | app/post.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/post.go b/app/post.go index bc31aee44..2efa4c90e 100644 --- a/app/post.go +++ b/app/post.go @@ -160,6 +160,14 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo return nil, err } + if a.PluginsReady() { + if newPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBePosted(post); newPost == nil { + return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + } else { + post = newPost + } + } + var rpost *model.Post if result := <-a.Srv.Store.Post().Save(post); result.Err != nil { return nil, result.Err @@ -167,6 +175,12 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo rpost = result.Data.(*model.Post) } + if a.PluginsReady() { + a.Go(func() { + a.PluginEnv.Hooks().MessageHasBeenPosted(rpost) + }) + } + esInterface := a.Elasticsearch if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing { a.Go(func() { @@ -371,11 +385,25 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model return nil, err } + if a.PluginsReady() { + if pluginModifiedPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBeUpdated(newPost, oldPost); pluginModifiedPost == nil { + return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + } else { + newPost = pluginModifiedPost + } + } + if result := <-a.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil { return nil, result.Err } else { rpost := result.Data.(*model.Post) + if a.PluginsReady() { + a.Go(func() { + a.PluginEnv.Hooks().MessageHasBeenUpdated(newPost, oldPost) + }) + } + esInterface := a.Elasticsearch if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing { a.Go(func() { |