github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/plugin/helpers.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package plugin
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/v5/model"
     8  )
     9  
    10  // Helpers provide a common patterns plugins use.
    11  //
    12  // Plugins obtain access to the Helpers by embedding MattermostPlugin.
    13  type Helpers interface {
    14  	// EnsureBot either returns an existing bot user matching the given bot, or creates a bot user from the given bot.
    15  	// A profile image or icon image may be optionally passed in to be set for the existing or newly created bot.
    16  	// Returns the id of the resulting bot.
    17  	//
    18  	// Minimum server version: 5.10
    19  	EnsureBot(bot *model.Bot, options ...EnsureBotOption) (string, error)
    20  
    21  	// KVSetJSON stores a key-value pair, unique per plugin, marshalling the given value as a JSON string.
    22  	//
    23  	// Deprecated: Use p.API.KVSetWithOptions instead.
    24  	//
    25  	// Minimum server version: 5.2
    26  	KVSetJSON(key string, value interface{}) error
    27  
    28  	// KVCompareAndSetJSON updates a key-value pair, unique per plugin, but only if the current value matches the given oldValue after marshalling as a JSON string.
    29  	// Inserts a new key if oldValue == nil.
    30  	// Returns (false, err) if DB error occurred
    31  	// Returns (false, nil) if current value != oldValue or key already exists when inserting
    32  	// Returns (true, nil) if current value == oldValue or new key is inserted
    33  	//
    34  	// Deprecated: Use p.API.KVSetWithOptions instead.
    35  	//
    36  	// Minimum server version: 5.12
    37  	KVCompareAndSetJSON(key string, oldValue interface{}, newValue interface{}) (bool, error)
    38  
    39  	// KVCompareAndDeleteJSON deletes a key-value pair, unique per plugin, but only if the current value matches the given oldValue after marshalling as a JSON string.
    40  	// Returns (false, err) if DB error occurred
    41  	// Returns (false, nil) if current value != oldValue or the key was already deleted
    42  	// Returns (true, nil) if current value == oldValue
    43  	//
    44  	// Minimum server version: 5.16
    45  	KVCompareAndDeleteJSON(key string, oldValue interface{}) (bool, error)
    46  
    47  	// KVGetJSON retrieves a value based on the key, unique per plugin, unmarshalling the previously set JSON string into the given value. Returns true if the key exists.
    48  	//
    49  	// Minimum server version: 5.2
    50  	KVGetJSON(key string, value interface{}) (bool, error)
    51  
    52  	// KVSetWithExpiryJSON stores a key-value pair with an expiry time, unique per plugin, marshalling the given value as a JSON string.
    53  	//
    54  	// Deprecated: Use p.API.KVSetWithOptions instead.
    55  	//
    56  	// Minimum server version: 5.6
    57  	KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error
    58  
    59  	// KVListWithOptions returns all keys that match the given options.  If no options are provided then all keys are returned.
    60  	//
    61  	// Minimum server version: 5.6
    62  	KVListWithOptions(options ...KVListOption) ([]string, error)
    63  
    64  	// CheckRequiredServerConfiguration checks if the server is configured according to
    65  	// plugin requirements.
    66  	//
    67  	// Minimum server version: 5.2
    68  	CheckRequiredServerConfiguration(req *model.Config) (bool, error)
    69  
    70  	// ShouldProcessMessage returns if the message should be processed by a message hook.
    71  	//
    72  	// Use this method to avoid processing unnecessary messages in a MessageHasBeenPosted
    73  	// or MessageWillBePosted hook, and indeed in some cases avoid an infinite loop between
    74  	// two automated bots or plugins.
    75  	//
    76  	// The behaviour is customizable using the given options, since plugin needs may vary.
    77  	// By default, system messages and messages from bots will be skipped.
    78  	//
    79  	// Minimum server version: 5.2
    80  	ShouldProcessMessage(post *model.Post, options ...ShouldProcessMessageOption) (bool, error)
    81  
    82  	// InstallPluginFromURL installs the plugin from the provided url.
    83  	//
    84  	// Minimum server version: 5.18
    85  	InstallPluginFromURL(downloadURL string, replace bool) (*model.Manifest, error)
    86  
    87  	// GetPluginAssetURL builds a URL to the given asset in the assets directory.
    88  	// Use this URL to link to assets from the webapp, or for third-party integrations with your plugin.
    89  	//
    90  	// Minimum server version: 5.2
    91  	GetPluginAssetURL(pluginID, asset string) (string, error)
    92  }
    93  
    94  // HelpersImpl implements the helpers interface with an API that retrieves data on behalf of the plugin.
    95  type HelpersImpl struct {
    96  	API API
    97  }