github.com/adacta-ru/mattermost-server/v6@v6.0.0/app/plugin_api_tests/test_search_channels_plugin/main.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"github.com/adacta-ru/mattermost-server/v6/app/plugin_api_tests"
     8  	"github.com/adacta-ru/mattermost-server/v6/model"
     9  	"github.com/adacta-ru/mattermost-server/v6/plugin"
    10  )
    11  
    12  type MyPlugin struct {
    13  	plugin.MattermostPlugin
    14  	configuration plugin_api_tests.BasicConfig
    15  }
    16  
    17  func (p *MyPlugin) OnConfigurationChange() error {
    18  	if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
    19  		return err
    20  	}
    21  	return nil
    22  }
    23  
    24  func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
    25  
    26  	channels, err := p.API.SearchChannels(p.configuration.BasicTeamId, p.configuration.BasicChannelName)
    27  	if err != nil {
    28  		return nil, err.Error()
    29  	}
    30  	if len(channels) != 1 {
    31  		return nil, "Returned invalid number of channels"
    32  	}
    33  
    34  	channels, err = p.API.SearchChannels("invalidid", p.configuration.BasicChannelName)
    35  	if err != nil {
    36  		return nil, err.Error()
    37  	}
    38  	if len(channels) != 0 {
    39  		return nil, "Returned invalid number of channels"
    40  	}
    41  
    42  	return nil, "OK"
    43  }
    44  
    45  func main() {
    46  	plugin.ClientMain(&MyPlugin{})
    47  }