Hi,
While working on a plugin making use of the MessageWillBeUpdated hook, I’m trying to delete a post custom prop (that was added to the post previously), but I can’t manage to.
To reproduce,
-
Create&install&activate a plugin with the following hooks:
func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
post.AddProp(“custom_test_prop”, 42)
return post, “”
}func (p *Plugin) MessageWillBeUpdated(c *plugin.Context, newPost, oldPost *model.Post) (*model.Post, string) {
newPost.AddProp(“custom_another_test_prop”, 4242)
newPost.DelProp(“custom_test_prop”)
return newPost, “”
} -
Post a message with “ORIGINAL” as content
-
Edit that message with “EDITED” as content
-
Check the post in the database:
±---------±--------------±--------------±---------±---------------------------------------------------------------------------------------+
| Message | EditAt | DeleteAt | Message | Props |
±---------±--------------±--------------±---------±---------------------------------------------------------------------------------------+
| EDITED | 1620681643944 | 0 | EDITED | {“custom_another_test_prop”:4242,“custom_test_prop”:42,“disable_group_highlight”:true} |
| ORIGINAL | 0 | 1620681643946 | ORIGINAL | {“custom_test_prop”:42,“disable_group_highlight”:true} |
±---------±--------------±--------------±---------±---------------------------------------------------------------------------------------+
Here we see that on editing, custom_another_test_prop
was correctly added but custom_test_prop
was NOT deleted, which is the goal.
The following code that deletes manually the property also fails to have any effect:
func (p *Plugin) MessageWillBeUpdated(c *plugin.Context, newPost, oldPost *model.Post) (*model.Post, string) {
props := newPost.GetProps()
delete(props, “custom_test_prop”)
newPost.SetProps(props)
newPost.AddProp(“custom_another_test_prop”, 4242)
return newPost, “”
}
What’s the correct way of deleting a custom prop?