-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
49 lines (41 loc) · 1.48 KB
/
plugin.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
45
46
47
48
49
package main
import (
"net/http"
"sync"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
)
// Emoticon2EmojiPlugin is a Mattermost plugin that replace text emoticons in messages by an emoji approximation
type Emoticon2EmojiPlugin struct {
plugin.MattermostPlugin
// configurationLock synchronizes access to the configuration.
configurationLock sync.RWMutex
// configuration is the active plugin configuration. Consult getConfiguration and
// setConfiguration for usage.
configuration *Emoticon2EmojiPluginConfiguration
}
// OnActivate register the plugin command
func (p *Emoticon2EmojiPlugin) OnActivate() error {
return p.OnConfigurationChange()
}
// MessageWillBePosted converts emoticons in new posts
func (p *Emoticon2EmojiPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
post.Message = p.translate(post.Message)
return post, ""
}
// MessageWillBeUpdated converts emoticons in edited posts
func (p *Emoticon2EmojiPlugin) MessageWillBeUpdated(c *plugin.Context, newPost, oldPost *model.Post) (*model.Post, string) {
newPost.Message = p.translate(newPost.Message)
return newPost, ""
}
func appError(message string, err error) *model.AppError {
errorMessage := ""
if err != nil {
errorMessage = err.Error()
}
return model.NewAppError("Emoticon2Emoji Plugin", message, nil, errorMessage, http.StatusBadRequest)
}
// Install the RCP plugin
func main() {
plugin.ClientMain(&Emoticon2EmojiPlugin{})
}