MM-53924 - Implement NotificationWillBePushed plugin hook (#24263)

* add NotificationWillBePushed hook

* mocks

* use a struct for hook parameters; simplify number of parameters sent across RPC

* missing wg.Wait

* change to a bool return value
Этот коммит содержится в:
Christopher Poile
2023-08-18 12:01:50 -04:00
коммит произвёл GitHub
родитель 56a0becbca
Коммит f13a531bca
10 изменённых файлов: 257 добавлений и 4 удалений

Просмотреть файл

@@ -14,6 +14,8 @@ import (
"strings"
"sync"
"github.com/mattermost/mattermost/server/public/plugin"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
@@ -138,6 +140,24 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
}
func (a *App) sendPushNotification(notification *PostNotification, user *model.User, explicitMention, channelWideMention bool, replyToThreadType string) {
cancelled := false
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
cancelled = hooks.NotificationWillBePushed(&model.PluginPushNotification{
Post: notification.Post.ForPlugin(),
Channel: notification.Channel,
UserID: user.Id,
})
if cancelled {
mlog.Info("Notification cancelled by plugin")
return false
}
return true
}, plugin.NotificationWillBePushedID)
if cancelled {
return
}
cfg := a.Config()
channel := notification.Channel
post := notification.Post