(feature) New MessagesWillBeConsumed Server Plugin Hook (#23305)
* feature: implemented basic MessageWillBeConsumed hook and applied on GetSinglePost method. * use hook in get methods * chore: refactored hook usage and created utils functions to apply hook * bugfix: single post not updating * chore: adjusted hook to return post * chore: reverted some uneeded changes * chore: updated hook to accept slice of posts * bugfix: slice filled with niil values * chore: MessageWillBeConsumed ranamed to MessagesWillBeConsumed * Update plugin/hooks.go Co-authored-by: Jesse Hallam <jesse@thehallams.ca> * Add feature flag * Update min version * update tests to account for feature flag * fix linting issues --------- Co-authored-by: Matej Topolovac <> Co-authored-by: mtopolovac <43346061+mtopolovac@users.noreply.github.com> Co-authored-by: Jesse Hallam <jesse@thehallams.ca> Co-authored-by: Kevin Hsieh <kevinh@qrypt.com> Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Этот коммит содержится в:
@@ -50,6 +50,10 @@ type MessageHasBeenUpdatedIFace interface {
|
||||
MessageHasBeenUpdated(c *Context, newPost, oldPost *model.Post)
|
||||
}
|
||||
|
||||
type MessagesWillBeConsumedIFace interface {
|
||||
MessagesWillBeConsumed(posts []*model.Post) []*model.Post
|
||||
}
|
||||
|
||||
type MessageHasBeenDeletedIFace interface {
|
||||
MessageHasBeenDeleted(c *Context, post *model.Post)
|
||||
}
|
||||
@@ -224,6 +228,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 MessagesWillBeConsumed interface.
|
||||
tt = reflect.TypeOf((*MessagesWillBeConsumedIFace)(nil)).Elem()
|
||||
|
||||
if ft.Implements(tt) {
|
||||
a.implemented[MessagesWillBeConsumedID] = struct{}{}
|
||||
} else if _, ok := ft.MethodByName("MessagesWillBeConsumed"); ok {
|
||||
return nil, errors.New("hook has MessagesWillBeConsumed method but does not implement plugin.MessagesWillBeConsumed interface")
|
||||
}
|
||||
|
||||
// Assessing the type of the productHooks if it individually implements MessageHasBeenDeleted interface.
|
||||
tt = reflect.TypeOf((*MessageHasBeenDeletedIFace)(nil)).Elem()
|
||||
|
||||
@@ -488,6 +501,15 @@ func (a *HooksAdapter) MessageHasBeenUpdated(c *Context, newPost, oldPost *model
|
||||
|
||||
}
|
||||
|
||||
func (a *HooksAdapter) MessagesWillBeConsumed(posts []*model.Post) []*model.Post {
|
||||
if _, ok := a.implemented[MessagesWillBeConsumedID]; !ok {
|
||||
panic("product hooks must implement MessagesWillBeConsumed")
|
||||
}
|
||||
|
||||
return a.productHooks.(MessagesWillBeConsumedIFace).MessagesWillBeConsumed(posts)
|
||||
|
||||
}
|
||||
|
||||
func (a *HooksAdapter) MessageHasBeenDeleted(c *Context, post *model.Post) {
|
||||
if _, ok := a.implemented[MessageHasBeenDeletedID]; !ok {
|
||||
panic("product hooks must implement MessageHasBeenDeleted")
|
||||
|
||||
Ссылка в новой задаче
Block a user