forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (46 loc) · 1.41 KB
/
main.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
50
51
52
53
54
55
56
57
58
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package main
import (
"fmt"
"github.com/adacta-ru/mattermost-server/v5/app/plugin_api_tests"
"github.com/adacta-ru/mattermost-server/v5/model"
"github.com/adacta-ru/mattermost-server/v5/plugin"
)
type MyPlugin struct {
plugin.MattermostPlugin
configuration plugin_api_tests.BasicConfig
}
func (p *MyPlugin) OnConfigurationChange() error {
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
return err
}
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
uid := p.configuration.BasicUserId
statuses := []string{model.STATUS_ONLINE, model.STATUS_AWAY, model.STATUS_DND, model.STATUS_OFFLINE}
for _, s := range statuses {
status, err := p.API.UpdateUserStatus(uid, s)
if err != nil {
return nil, err.Error()
}
if status == nil {
return nil, "Status was expected, got nil"
}
if s != status.Status {
return nil, fmt.Sprintf("Invalid status returned: %v != %v", s, status.Status)
}
}
status, err := p.API.UpdateUserStatus(uid, "notrealstatus")
if err == nil {
return nil, "Expected to get an error while updating invalid user status"
}
if status != nil {
return nil, "Status was expected to be nil, got: " + status.Status
}
return nil, "OK"
}
func main() {
plugin.ClientMain(&MyPlugin{})
}