github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/api.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/model"
     8  )
     9  
    10  // The API can be used to retrieve data or perform actions on behalf of the plugin. Most methods
    11  // have direct counterparts in the REST API and very similar behavior.
    12  //
    13  // Plugins can obtain access to the API by implementing the OnActivate hook.
    14  type API interface {
    15  	// LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a
    16  	// struct that the configuration JSON can be unmarshalled to.
    17  	LoadPluginConfiguration(dest interface{}) error
    18  
    19  	// RegisterCommand registers a custom slash command. When the command is triggered, your plugin
    20  	// can fulfill it via the ExecuteCommand hook.
    21  	RegisterCommand(command *model.Command) error
    22  
    23  	// UnregisterCommand unregisters a command previously registered via RegisterCommand.
    24  	UnregisterCommand(teamId, trigger string) error
    25  
    26  	// CreateUser creates a user.
    27  	CreateUser(user *model.User) (*model.User, *model.AppError)
    28  
    29  	// DeleteUser deletes a user.
    30  	DeleteUser(userId string) *model.AppError
    31  
    32  	// GetUser gets a user.
    33  	GetUser(userId string) (*model.User, *model.AppError)
    34  
    35  	// GetUserByEmail gets a user by their email address.
    36  	GetUserByEmail(email string) (*model.User, *model.AppError)
    37  
    38  	// GetUserByUsername gets a user by their username.
    39  	GetUserByUsername(name string) (*model.User, *model.AppError)
    40  
    41  	// UpdateUser updates a user.
    42  	UpdateUser(user *model.User) (*model.User, *model.AppError)
    43  
    44  	// CreateTeam creates a team.
    45  	CreateTeam(team *model.Team) (*model.Team, *model.AppError)
    46  
    47  	// DeleteTeam deletes a team.
    48  	DeleteTeam(teamId string) *model.AppError
    49  
    50  	// GetTeam gets a team.
    51  	GetTeam(teamId string) (*model.Team, *model.AppError)
    52  
    53  	// GetTeamByName gets a team by its name.
    54  	GetTeamByName(name string) (*model.Team, *model.AppError)
    55  
    56  	// UpdateTeam updates a team.
    57  	UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
    58  
    59  	// CreateChannel creates a channel.
    60  	CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
    61  
    62  	// DeleteChannel deletes a channel.
    63  	DeleteChannel(channelId string) *model.AppError
    64  
    65  	// GetChannel gets a channel.
    66  	GetChannel(channelId string) (*model.Channel, *model.AppError)
    67  
    68  	// GetChannelByName gets a channel by its name.
    69  	GetChannelByName(name, teamId string) (*model.Channel, *model.AppError)
    70  
    71  	// GetDirectChannel gets a direct message channel.
    72  	GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)
    73  
    74  	// GetGroupChannel gets a group message channel.
    75  	GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)
    76  
    77  	// UpdateChannel updates a channel.
    78  	UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
    79  
    80  	// AddChannelMember creates a channel membership for a user.
    81  	AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
    82  
    83  	// GetChannelMember gets a channel membership for a user.
    84  	GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
    85  
    86  	// UpdateChannelMemberRoles updates a user's roles for a channel.
    87  	UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError)
    88  
    89  	// UpdateChannelMemberNotifications updates a user's notification properties for a channel.
    90  	UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)
    91  
    92  	// DeleteChannelMember deletes a channel membership for a user.
    93  	DeleteChannelMember(channelId, userId string) *model.AppError
    94  
    95  	// CreatePost creates a post.
    96  	CreatePost(post *model.Post) (*model.Post, *model.AppError)
    97  
    98  	// DeletePost deletes a post.
    99  	DeletePost(postId string) *model.AppError
   100  
   101  	// GetPost gets a post.
   102  	GetPost(postId string) (*model.Post, *model.AppError)
   103  
   104  	// UpdatePost updates a post.
   105  	UpdatePost(post *model.Post) (*model.Post, *model.AppError)
   106  
   107  	// KeyValueStore returns an object for accessing the persistent key value storage.
   108  	KeyValueStore() KeyValueStore
   109  }
   110  
   111  type KeyValueStore interface {
   112  	// Set will store a key-value pair, unique per plugin.
   113  	Set(key string, value []byte) *model.AppError
   114  
   115  	// Get will retrieve a value based on the key. Returns nil for non-existent keys.
   116  	Get(key string) ([]byte, *model.AppError)
   117  
   118  	// Delete will remove a key-value pair. Returns nil for non-existent keys.
   119  	Delete(key string) *model.AppError
   120  }