mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-18 01:58:49 -05:00
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"github.com/mattermost/mattermost-server/v5/app/plugin_api_tests"
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
"github.com/mattermost/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) {
|
|
teamMembers, err := p.API.GetTeamMembersForUser(p.configuration.BasicUserId, 0, 10)
|
|
if err != nil {
|
|
return nil, err.Error() + "failed to get team members"
|
|
} else if len(teamMembers) != 1 {
|
|
return nil, "Invalid number of team members"
|
|
} else if teamMembers[0].UserId != p.configuration.BasicUserId || teamMembers[0].TeamId != p.configuration.BasicTeamId {
|
|
return nil, "Invalid user or team id returned"
|
|
}
|
|
return nil, "OK"
|
|
}
|
|
|
|
func main() {
|
|
plugin.ClientMain(&MyPlugin{})
|
|
}
|