Skip to content

Commit

Permalink
Add option to enable processing on post update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Gittins committed Nov 15, 2019
1 parent ba7743d commit 0c963af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// Config from config.json
type Config struct {
EnableAdminCommand bool
EnableOnUpdate bool
Links []Link
}

Expand Down Expand Up @@ -74,6 +75,7 @@ func (conf Config) ToConfig() map[string]interface{} {
}
return map[string]interface{}{
"EnableAdminCommand": conf.EnableAdminCommand,
"EnableOnUpdate": conf.EnableOnUpdate,
"Links": links,
}
}
Expand Down
21 changes: 18 additions & 3 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ type Plugin struct {
confLock sync.RWMutex
}

// MessageWillBePosted is invoked when a message is posted by a user before it is committed
// to the database.
func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *Plugin) ProcessPost(c *plugin.Context, post *model.Post) (*model.Post, string) {
conf := p.getConfig()
postText := post.Message
offset := 0
Expand Down Expand Up @@ -98,3 +96,20 @@ func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*mode

return post, ""
}

// MessageWillBePosted is invoked when a message is posted by a user before it is committed
// to the database.
func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
return p.ProcessPost(c, post)
}

// MessageWillBeUpdated is invoked when a message is updated by a user before it is committed
// to the database.
func (p *Plugin) MessageWillBeUpdated(c *plugin.Context, post *model.Post, _ *model.Post) (*model.Post, string) {
conf := p.getConfig()
if conf.EnableOnUpdate {
return p.ProcessPost(c, post)
} else {
return post, ""
}
}

0 comments on commit 0c963af

Please sign in to comment.