Skip to content

Commit fbdf43a

Browse files
committed
Code refactoring and review fixes
1 parent 1395e4e commit fbdf43a

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

plugin.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
"key": "RejectDMs",
1313
"display_name": "Reject DMs:",
1414
"type": "bool",
15+
"default": true,
1516
"help_text": "If set the plugin will reject direct messages."
1617
},
1718
{
1819
"key": "RejectGroupChats",
1920
"display_name": "Reject Group Chats:",
2021
"type": "bool",
22+
"default": true,
2123
"help_text": "If set the plugin will reject messages sent to group chats."
2224
},
2325
{

server/config/main.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ package config
22

33
import (
44
"errors"
5+
"strings"
56

67
"github.com/mattermost/mattermost-server/plugin"
78
"go.uber.org/atomic"
89
)
910

1011
const (
11-
CommandPrefix = PluginName
12-
URLMappingKeyPrefix = "url_"
13-
ServerExeToWebappRootPath = "/../webapp"
14-
15-
URLPluginBase = "/plugins/" + PluginName
16-
URLStaticBase = URLPluginBase + "/static"
17-
1812
HeaderMattermostUserID = "Mattermost-User-Id"
1913
)
2014

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

37+
c.RejectionMessage = strings.TrimSpace(c.RejectionMessage)
38+
4339
return nil
4440
}
4541

server/plugin.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,7 @@ func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*mode
5454
return nil, ""
5555
}
5656

57-
if channel.Type == model.CHANNEL_DIRECT && conf.RejectDMs {
58-
config.Mattermost.SendEphemeralPost(post.UserId, &model.Post{
59-
Message: conf.RejectionMessage,
60-
ChannelId: post.ChannelId,
61-
})
62-
return nil, conf.RejectionMessage
63-
}
64-
65-
if channel.Type == model.CHANNEL_GROUP && conf.RejectGroupChats {
57+
if (channel.Type == model.CHANNEL_DIRECT && conf.RejectDMs) || (channel.Type == model.CHANNEL_GROUP && conf.RejectGroupChats) {
6658
config.Mattermost.SendEphemeralPost(post.UserId, &model.Post{
6759
Message: conf.RejectionMessage,
6860
ChannelId: post.ChannelId,

0 commit comments

Comments
 (0)