Skip to content

Commit

Permalink
Code refactoring and review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chetanyakan committed Mar 4, 2019
1 parent 1395e4e commit fbdf43a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
2 changes: 2 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"key": "RejectDMs",
"display_name": "Reject DMs:",
"type": "bool",
"default": true,
"help_text": "If set the plugin will reject direct messages."
},
{
"key": "RejectGroupChats",
"display_name": "Reject Group Chats:",
"type": "bool",
"default": true,
"help_text": "If set the plugin will reject messages sent to group chats."
},
{
Expand Down
10 changes: 3 additions & 7 deletions server/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ package config

import (
"errors"
"strings"

"github.com/mattermost/mattermost-server/plugin"
"go.uber.org/atomic"
)

const (
CommandPrefix = PluginName
URLMappingKeyPrefix = "url_"
ServerExeToWebappRootPath = "/../webapp"

URLPluginBase = "/plugins/" + PluginName
URLStaticBase = URLPluginBase + "/static"

HeaderMattermostUserID = "Mattermost-User-Id"
)

Expand All @@ -40,6 +34,8 @@ func SetConfig(c *Configuration) {
func (c *Configuration) ProcessConfiguration() error {
// any post-processing on configurations goes here

c.RejectionMessage = strings.TrimSpace(c.RejectionMessage)

return nil
}

Expand Down
10 changes: 1 addition & 9 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*mode
return nil, ""
}

if channel.Type == model.CHANNEL_DIRECT && conf.RejectDMs {
config.Mattermost.SendEphemeralPost(post.UserId, &model.Post{
Message: conf.RejectionMessage,
ChannelId: post.ChannelId,
})
return nil, conf.RejectionMessage
}

if channel.Type == model.CHANNEL_GROUP && conf.RejectGroupChats {
if (channel.Type == model.CHANNEL_DIRECT && conf.RejectDMs) || (channel.Type == model.CHANNEL_GROUP && conf.RejectGroupChats) {
config.Mattermost.SendEphemeralPost(post.UserId, &model.Post{
Message: conf.RejectionMessage,
ChannelId: post.ChannelId,
Expand Down

0 comments on commit fbdf43a

Please sign in to comment.