-
Notifications
You must be signed in to change notification settings - Fork 6
/
hooks.go
44 lines (36 loc) · 1.07 KB
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
)
func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
// Bypass for our bot
if post.UserId == p.BotUserID {
return nil, ""
}
// Nothing to further check if we are not encrypting that channel
encrMeth := p.ChanEncrMethods.get(post.ChannelId)
if encrMeth == ChanEncryptionMethodNone {
return nil, ""
}
// If configured to do so, bypass for all bots
if p.getConfiguration().BotCanAlwaysPost {
user, appErr := p.API.GetUser(post.UserId)
if appErr != nil {
return nil, fmt.Sprintf("unable to check if user is a bot: %s", appErr.Error())
}
if user.IsBot {
return nil, ""
}
}
// Check if the type of the message is whitelisted
if _, has := p.AlwaysAllowMsgTypes[post.Type]; has {
return nil, ""
}
// If the message is not encrypted, rejects it!
if post.Type != "custom_e2ee" {
return nil, "Unencrypted messages can't be sent on an encrypted channel."
}
return nil, ""
}