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 удалений

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

@@ -118,6 +118,10 @@ type ConfigurationWillBeSavedIFace interface {
ConfigurationWillBeSaved(newCfg *model.Config) (*model.Config, error)
}
type NotificationWillBePushedIFace interface {
NotificationWillBePushed(pushNotification *model.PluginPushNotification) (cancel bool)
}
type HooksAdapter struct {
implemented map[int]struct{}
productHooks any
@@ -365,6 +369,15 @@ func NewAdapter(productHooks any) (*HooksAdapter, error) {
return nil, errors.New("hook has ConfigurationWillBeSaved method but does not implement plugin.ConfigurationWillBeSaved interface")
}
// Assessing the type of the productHooks if it individually implements NotificationWillBePushed interface.
tt = reflect.TypeOf((*NotificationWillBePushedIFace)(nil)).Elem()
if ft.Implements(tt) {
a.implemented[NotificationWillBePushedID] = struct{}{}
} else if _, ok := ft.MethodByName("NotificationWillBePushed"); ok {
return nil, errors.New("hook has NotificationWillBePushed method but does not implement plugin.NotificationWillBePushed interface")
}
return a, nil
}
@@ -601,3 +614,12 @@ func (a *HooksAdapter) ConfigurationWillBeSaved(newCfg *model.Config) (*model.Co
return a.productHooks.(ConfigurationWillBeSavedIFace).ConfigurationWillBeSaved(newCfg)
}
func (a *HooksAdapter) NotificationWillBePushed(pushNotification *model.PluginPushNotification) (cancel bool) {
if _, ok := a.implemented[NotificationWillBePushedID]; !ok {
panic("product hooks must implement NotificationWillBePushed")
}
return a.productHooks.(NotificationWillBePushedIFace).NotificationWillBePushed(pushNotification)
}