Adding 'MessageHasBeenDeleted' hook to plugins (#22476)

* Adding 'MessageHasBeenDeleted' hook to plugins

* Remove debug logs

* Add unit test

* Bumping the required version

* Fix CI problems

* Increasing the minimum version

* go fmt

---------

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Jesús Espino
2023-09-14 18:33:22 +02:00
коммит произвёл GitHub
родитель c731630e88
Коммит 17ff2049ec
7 изменённых файлов: 128 добавлений и 0 удалений

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

@@ -50,6 +50,10 @@ type MessageHasBeenUpdatedIFace interface {
MessageHasBeenUpdated(c *Context, newPost, oldPost *model.Post)
}
type MessageHasBeenDeletedIFace interface {
MessageHasBeenDeleted(c *Context, post *model.Post)
}
type ChannelHasBeenCreatedIFace interface {
ChannelHasBeenCreated(c *Context, channel *model.Channel)
}
@@ -220,6 +224,15 @@ func NewAdapter(productHooks any) (*HooksAdapter, error) {
return nil, errors.New("hook has MessageHasBeenUpdated method but does not implement plugin.MessageHasBeenUpdated interface")
}
// Assessing the type of the productHooks if it individually implements MessageHasBeenDeleted interface.
tt = reflect.TypeOf((*MessageHasBeenDeletedIFace)(nil)).Elem()
if ft.Implements(tt) {
a.implemented[MessageHasBeenDeletedID] = struct{}{}
} else if _, ok := ft.MethodByName("MessageHasBeenDeleted"); ok {
return nil, errors.New("hook has MessageHasBeenDeleted method but does not implement plugin.MessageHasBeenDeleted interface")
}
// Assessing the type of the productHooks if it individually implements ChannelHasBeenCreated interface.
tt = reflect.TypeOf((*ChannelHasBeenCreatedIFace)(nil)).Elem()
@@ -475,6 +488,15 @@ func (a *HooksAdapter) MessageHasBeenUpdated(c *Context, newPost, oldPost *model
}
func (a *HooksAdapter) MessageHasBeenDeleted(c *Context, post *model.Post) {
if _, ok := a.implemented[MessageHasBeenDeletedID]; !ok {
panic("product hooks must implement MessageHasBeenDeleted")
}
a.productHooks.(MessageHasBeenDeletedIFace).MessageHasBeenDeleted(c, post)
}
func (a *HooksAdapter) ChannelHasBeenCreated(c *Context, channel *model.Channel) {
if _, ok := a.implemented[ChannelHasBeenCreatedID]; !ok {
panic("product hooks must implement ChannelHasBeenCreated")