github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/hooks.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 "net/http" 8 9 "github.com/mattermost/mattermost-server/model" 10 ) 11 12 // Methods from the Hooks interface can be used by a plugin to respond to events. Methods are likely 13 // to be added over time, and plugins are not expected to implement all of them. Instead, plugins 14 // are expected to implement a subset of them and pass an instance to plugin/rpcplugin.Main, which 15 // will take over execution of the process and add default behaviors for missing hooks. 16 type Hooks interface { 17 // OnActivate is invoked when the plugin is activated. Implementations will usually want to save 18 // the api argument for later use. Loading configuration for the first time is also a commonly 19 // done here. 20 OnActivate(API) error 21 22 // OnDeactivate is invoked when the plugin is deactivated. This is the plugin's last chance to 23 // use the API, and the plugin will be terminated shortly after this invocation. 24 OnDeactivate() error 25 26 // OnConfigurationChange is invoked when configuration changes may have been made. 27 OnConfigurationChange() error 28 29 // ServeHTTP allows the plugin to implement the http.Handler interface. Requests destined for 30 // the /plugins/{id} path will be routed to the plugin. 31 // 32 // The Mattermost-User-Id header will be present if (and only if) the request is by an 33 // authenticated user. 34 ServeHTTP(http.ResponseWriter, *http.Request) 35 36 // ExecuteCommand executes a command that has been previously registered via the RegisterCommand 37 // API. 38 ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) 39 40 // MessageWillBePosted is invoked when a message is posted by a user before it is commited 41 // to the database. If you also want to act on edited posts, see MessageWillBeUpdated. 42 // Return values should be the modified post or nil if rejected and an explanation for the user. 43 // 44 // If you don't need to modify or reject posts, use MessageHasBeenPosted instead. 45 // 46 // Note that this method will be called for posts created by plugins, including the plugin that 47 // created the post. 48 MessageWillBePosted(post *model.Post) (*model.Post, string) 49 50 // MessageWillBeUpdated is invoked when a message is updated by a user before it is commited 51 // to the database. If you also want to act on new posts, see MessageWillBePosted. 52 // Return values should be the modified post or nil if rejected and an explanation for the user. 53 // On rejection, the post will be kept in its previous state. 54 // 55 // If you don't need to modify or rejected updated posts, use MessageHasBeenUpdated instead. 56 // 57 // Note that this method will be called for posts updated by plugins, including the plugin that 58 // updated the post. 59 MessageWillBeUpdated(newPost, oldPost *model.Post) (*model.Post, string) 60 61 // MessageHasBeenPosted is invoked after the message has been commited to the databse. 62 // If you need to modify or reject the post, see MessageWillBePosted 63 // Note that this method will be called for posts created by plugins, including the plugin that 64 // created the post. 65 MessageHasBeenPosted(post *model.Post) 66 67 // MessageHasBeenUpdated is invoked after a message is updated and has been updated in the databse. 68 // If you need to modify or reject the post, see MessageWillBeUpdated 69 // Note that this method will be called for posts created by plugins, including the plugin that 70 // created the post. 71 MessageHasBeenUpdated(newPost, oldPost *model.Post) 72 }