Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add messageswillbeconsumed hook demo #168

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ unless by the demo plugin user itself.
This demo implementation logs a message to the demo channel whenever a message is updated,
unless by the demo plugin user itself.

### MessagesWillBeConsumed

This demo implementation replaces "[SECURE]" message prefix with "[ENCRYPTED]".

## [team_hooks.go](team_hooks.go)

### UserHasJoinedTeam
Expand Down
21 changes: 21 additions & 0 deletions server/message_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,24 @@ func (p *Plugin) MessageHasBeenDeleted(c *plugin.Context, post *model.Post) {
)
}
}

// MessagesWillBeConsumed is invoked before a message is sent to the client. It allows plugins to
// modify the message before it is sent to the client. Note that this method will be called for
// posts created by plugins, including the plugin that created the post.
//
// This demo implementation replaces "SECURE" prefix in the messages with "ENCRYPTED" prefix.
func (p *Plugin) MessagesWillBeConsumed(posts []*model.Post) []*model.Post {
configuration := p.getConfiguration()

if configuration.disabled {
return posts
}

for _, post := range posts {
// Replaces posts that include "SECURE" prefix with "ENCRYPTED" prefix.
if strings.HasPrefix(post.Message, "[SECURE]") {
post.Message = strings.Replace(post.Message, "[SECURE]", "[ENCRYPTED]", 1)
}
}
return posts
}
Loading