Adds an exported const string that can be used by plugins to signal a client that the incoming post should be dismissed, instead of the current behavior which just leaves it pending.
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
16c11d7bf9
Коммит
c73bc21d1e
@@ -236,7 +236,11 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
|||||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||||
replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post)
|
replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post)
|
||||||
if rejectionReason != "" {
|
if rejectionReason != "" {
|
||||||
rejectionError = model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest)
|
id := "Post rejected by plugin. " + rejectionReason
|
||||||
|
if rejectionReason == plugin.DismissPostError {
|
||||||
|
id = plugin.DismissPostError
|
||||||
|
}
|
||||||
|
rejectionError = model.NewAppError("createPost", id, nil, "", http.StatusBadRequest)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if replacementPost != nil {
|
if replacementPost != nil {
|
||||||
@@ -245,6 +249,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}, plugin.MessageWillBePostedId)
|
}, plugin.MessageWillBePostedId)
|
||||||
|
|
||||||
if rejectionError != nil {
|
if rejectionError != nil {
|
||||||
return nil, rejectionError
|
return nil, rejectionError
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ const (
|
|||||||
TotalHooksId = iota
|
TotalHooksId = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DismissPostError dismisses a pending post when the error is returned from MessageWillBePosted.
|
||||||
|
DismissPostError = "plugin.message_will_be_posted.dismiss_post"
|
||||||
|
)
|
||||||
|
|
||||||
// Hooks describes the methods a plugin may implement to automatically receive the corresponding
|
// Hooks describes the methods a plugin may implement to automatically receive the corresponding
|
||||||
// event.
|
// event.
|
||||||
//
|
//
|
||||||
@@ -90,6 +95,7 @@ type Hooks interface {
|
|||||||
// To reject a post, return an non-empty string describing why the post was rejected.
|
// To reject a post, return an non-empty string describing why the post was rejected.
|
||||||
// To modify the post, return the replacement, non-nil *model.Post and an empty string.
|
// To modify the post, return the replacement, non-nil *model.Post and an empty string.
|
||||||
// To allow the post without modification, return a nil *model.Post and an empty string.
|
// To allow the post without modification, return a nil *model.Post and an empty string.
|
||||||
|
// To dismiss the post, return a nil *model.Post and the const DismissPostError string.
|
||||||
//
|
//
|
||||||
// If you don't need to modify or reject posts, use MessageHasBeenPosted instead.
|
// If you don't need to modify or reject posts, use MessageHasBeenPosted instead.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ func (s *SqlPostStore) Get(id string) (*model.PostList, *model.AppError) {
|
|||||||
|
|
||||||
for _, p := range posts {
|
for _, p := range posts {
|
||||||
pl.AddPost(p)
|
pl.AddPost(p)
|
||||||
|
pl.AddOrder(p.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pl, nil
|
return pl, nil
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user