github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/app/plugin_api_tests/test_get_profile_image_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/mattermost/mattermost-server/v5/app/plugin_api_tests"
     8  	"github.com/mattermost/mattermost-server/v5/model"
     9  	"github.com/mattermost/mattermost-server/v5/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(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
    25  
    26  	// check existing user first
    27  	data, err := p.API.GetProfileImage(p.configuration.BasicUserId)
    28  	if err != nil {
    29  		return nil, err.Error()
    30  	}
    31  	if plugin_api_tests.IsEmpty(data) {
    32  		return nil, "GetProfileImage return empty"
    33  	}
    34  
    35  	// then unknown user
    36  	data, err = p.API.GetProfileImage(model.NewId())
    37  	if err == nil || data != nil {
    38  		return nil, "GetProfileImage should've returned an error"
    39  	}
    40  	return nil, "OK"
    41  }
    42  
    43  func main() {
    44  	plugin.ClientMain(&MyPlugin{})
    45  }