summaryrefslogtreecommitdiffstats
path: root/app/post.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/post.go')
-rw-r--r--app/post.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/app/post.go b/app/post.go
index 8c44436aa..299c9ce3a 100644
--- a/app/post.go
+++ b/app/post.go
@@ -162,14 +162,22 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
}
if a.PluginsReady() {
- var rejectionReason string
+ var rejectionError *model.AppError
pluginContext := &plugin.Context{}
a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
- post, rejectionReason = hooks.MessageWillBePosted(pluginContext, post)
- return post != nil
+ replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post)
+ if rejectionReason != "" {
+ rejectionError = model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest)
+ return false
+ }
+ if replacementPost != nil {
+ post = replacementPost
+ }
+
+ return true
}, plugin.MessageWillBePostedId)
- if post == nil {
- return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest)
+ if rejectionError != nil {
+ return nil, rejectionError
}
}