(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>
Этот коммит содержится в:
@@ -698,6 +698,43 @@ func (s *hooksRPCServer) MessageWillBeUpdated(args *Z_MessageWillBeUpdatedArgs,
|
||||
return nil
|
||||
}
|
||||
|
||||
// MessagesWillBeConsumed is in this file because of the difficulty of identifying which fields need special behaviour.
|
||||
// The special behaviour needed is decoding the returned post into the original one to avoid the unintentional removal
|
||||
// of fields by older plugins.
|
||||
func init() {
|
||||
hookNameToId["MessagesWillBeConsumed"] = MessagesWillBeConsumedID
|
||||
}
|
||||
|
||||
type Z_MessagesWillBeConsumedArgs struct {
|
||||
A []*model.Post
|
||||
}
|
||||
|
||||
type Z_MessagesWillBeConsumedReturns struct {
|
||||
A []*model.Post
|
||||
}
|
||||
|
||||
func (g *hooksRPCClient) MessagesWillBeConsumed(posts []*model.Post) []*model.Post {
|
||||
_args := &Z_MessagesWillBeConsumedArgs{posts}
|
||||
_returns := &Z_MessagesWillBeConsumedReturns{}
|
||||
if g.implemented[MessagesWillBeConsumedID] {
|
||||
if err := g.client.Call("Plugin.MessagesWillBeConsumed", _args, _returns); err != nil {
|
||||
g.log.Error("RPC call MessagesWillBeConsumed to plugin failed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
return _returns.A
|
||||
}
|
||||
|
||||
func (s *hooksRPCServer) MessagesWillBeConsumed(args *Z_MessagesWillBeConsumedArgs, returns *Z_MessagesWillBeConsumedReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
MessagesWillBeConsumed(posts []*model.Post) []*model.Post
|
||||
}); ok {
|
||||
returns.A = hook.MessagesWillBeConsumed(args.A)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("hook MessagesWillBeConsumed called but not implemented"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_LogDebugArgs struct {
|
||||
A string
|
||||
B []any
|
||||
|
||||
Ссылка в новой задаче
Block a user