MM-19508 Extend ShouldProcessMessage to filter out from_webhoo… (#13270)
Extend ShouldProcessMessage to filter out from_webhook posts
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
7274f4c6c2
Коммит
722924b910
@@ -66,6 +66,7 @@ type ShouldProcessMessageOption func(*shouldProcessMessageOptions)
|
||||
type shouldProcessMessageOptions struct {
|
||||
AllowSystemMessages bool
|
||||
AllowBots bool
|
||||
AllowWebhook bool
|
||||
FilterChannelIDs []string
|
||||
FilterUserIDs []string
|
||||
OnlyBotDMs bool
|
||||
@@ -89,6 +90,15 @@ func AllowBots() ShouldProcessMessageOption {
|
||||
}
|
||||
}
|
||||
|
||||
// AllowWebhook configures a call to ShouldProcessMessage to return true for posts from webhook.
|
||||
//
|
||||
// As it is typically desirable only to consume messages from human users of the system, ShouldProcessMessage ignores webhook messages by default.
|
||||
func AllowWebhook() ShouldProcessMessageOption {
|
||||
return func(options *shouldProcessMessageOptions) {
|
||||
options.AllowWebhook = true
|
||||
}
|
||||
}
|
||||
|
||||
// FilterChannelIDs configures a call to ShouldProcessMessage to return true only for the given channels.
|
||||
//
|
||||
// By default, posts from all channels are allowed to be processed.
|
||||
@@ -138,6 +148,10 @@ func (p *HelpersImpl) ShouldProcessMessage(post *model.Post, options ...ShouldPr
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if !messageProcessOptions.AllowWebhook && post.Props["from_webhook"] == "true" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if !messageProcessOptions.AllowBots {
|
||||
user, appErr := p.API.GetUser(post.UserId)
|
||||
if appErr != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user