2017-10-25 11:33:19 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2017-08-16 17:23:38 -05:00
|
|
|
package plugin
|
|
|
|
|
|
2017-08-28 11:27:18 -05:00
|
|
|
import (
|
|
|
|
|
"net/http"
|
2017-12-08 13:55:41 -06:00
|
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
2017-08-28 11:27:18 -05:00
|
|
|
)
|
|
|
|
|
|
2018-06-25 12:33:13 -07:00
|
|
|
// These assignments are part of the wire protocol. You can add more, but should not change existing
|
|
|
|
|
// assignments. Follow the naming convention of <HookName>Id as the autogenerated glue code depends on that.
|
|
|
|
|
const (
|
|
|
|
|
OnActivateId = 0
|
|
|
|
|
OnDeactivateId = 1
|
|
|
|
|
ServeHTTPId = 2
|
|
|
|
|
OnConfigurationChangeId = 3
|
|
|
|
|
ExecuteCommandId = 4
|
|
|
|
|
MessageWillBePostedId = 5
|
|
|
|
|
MessageWillBeUpdatedId = 6
|
|
|
|
|
MessageHasBeenPostedId = 7
|
|
|
|
|
MessageHasBeenUpdatedId = 8
|
|
|
|
|
TotalHooksId = iota
|
|
|
|
|
)
|
|
|
|
|
|
2017-11-03 11:34:44 -05:00
|
|
|
// Methods from the Hooks interface can be used by a plugin to respond to events. Methods are likely
|
|
|
|
|
// to be added over time, and plugins are not expected to implement all of them. Instead, plugins
|
|
|
|
|
// are expected to implement a subset of them and pass an instance to plugin/rpcplugin.Main, which
|
|
|
|
|
// will take over execution of the process and add default behaviors for missing hooks.
|
2017-08-16 17:23:38 -05:00
|
|
|
type Hooks interface {
|
2018-06-25 12:33:13 -07:00
|
|
|
// OnActivate is invoked when the plugin is activated.
|
|
|
|
|
OnActivate() error
|
|
|
|
|
|
|
|
|
|
// Implemented returns a list of hooks that are implmented by the plugin.
|
|
|
|
|
// Plugins do not need to provide an implementation. Any given will be ignored.
|
|
|
|
|
Implemented() ([]string, error)
|
2017-08-16 17:23:38 -05:00
|
|
|
|
|
|
|
|
// OnDeactivate is invoked when the plugin is deactivated. This is the plugin's last chance to
|
|
|
|
|
// use the API, and the plugin will be terminated shortly after this invocation.
|
|
|
|
|
OnDeactivate() error
|
2017-08-28 11:27:18 -05:00
|
|
|
|
2017-09-11 10:02:02 -05:00
|
|
|
// OnConfigurationChange is invoked when configuration changes may have been made.
|
|
|
|
|
OnConfigurationChange() error
|
|
|
|
|
|
2017-08-28 11:27:18 -05:00
|
|
|
// ServeHTTP allows the plugin to implement the http.Handler interface. Requests destined for
|
|
|
|
|
// the /plugins/{id} path will be routed to the plugin.
|
|
|
|
|
//
|
|
|
|
|
// The Mattermost-User-Id header will be present if (and only if) the request is by an
|
|
|
|
|
// authenticated user.
|
2018-07-06 06:07:09 -07:00
|
|
|
ServeHTTP(c *Context, w http.ResponseWriter, r *http.Request)
|
2017-12-08 13:55:41 -06:00
|
|
|
|
|
|
|
|
// ExecuteCommand executes a command that has been previously registered via the RegisterCommand
|
|
|
|
|
// API.
|
2018-07-06 06:07:09 -07:00
|
|
|
ExecuteCommand(c *Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
|
2018-05-15 13:33:47 -07:00
|
|
|
|
|
|
|
|
// MessageWillBePosted is invoked when a message is posted by a user before it is commited
|
|
|
|
|
// to the database. If you also want to act on edited posts, see MessageWillBeUpdated.
|
|
|
|
|
// Return values should be the modified post or nil if rejected and an explanation for the user.
|
|
|
|
|
//
|
|
|
|
|
// If you don't need to modify or reject posts, use MessageHasBeenPosted instead.
|
|
|
|
|
//
|
|
|
|
|
// Note that this method will be called for posts created by plugins, including the plugin that
|
|
|
|
|
// created the post.
|
2018-07-06 06:07:09 -07:00
|
|
|
MessageWillBePosted(c *Context, post *model.Post) (*model.Post, string)
|
2018-05-15 13:33:47 -07:00
|
|
|
|
|
|
|
|
// MessageWillBeUpdated is invoked when a message is updated by a user before it is commited
|
|
|
|
|
// to the database. If you also want to act on new posts, see MessageWillBePosted.
|
|
|
|
|
// Return values should be the modified post or nil if rejected and an explanation for the user.
|
|
|
|
|
// On rejection, the post will be kept in its previous state.
|
|
|
|
|
//
|
|
|
|
|
// If you don't need to modify or rejected updated posts, use MessageHasBeenUpdated instead.
|
|
|
|
|
//
|
|
|
|
|
// Note that this method will be called for posts updated by plugins, including the plugin that
|
|
|
|
|
// updated the post.
|
2018-07-06 06:07:09 -07:00
|
|
|
MessageWillBeUpdated(c *Context, newPost, oldPost *model.Post) (*model.Post, string)
|
2018-05-15 13:33:47 -07:00
|
|
|
|
|
|
|
|
// MessageHasBeenPosted is invoked after the message has been commited to the databse.
|
|
|
|
|
// If you need to modify or reject the post, see MessageWillBePosted
|
|
|
|
|
// Note that this method will be called for posts created by plugins, including the plugin that
|
|
|
|
|
// created the post.
|
2018-07-06 06:07:09 -07:00
|
|
|
MessageHasBeenPosted(c *Context, post *model.Post)
|
2018-05-15 13:33:47 -07:00
|
|
|
|
|
|
|
|
// MessageHasBeenUpdated is invoked after a message is updated and has been updated in the databse.
|
|
|
|
|
// If you need to modify or reject the post, see MessageWillBeUpdated
|
|
|
|
|
// Note that this method will be called for posts created by plugins, including the plugin that
|
|
|
|
|
// created the post.
|
2018-07-06 06:07:09 -07:00
|
|
|
MessageHasBeenUpdated(c *Context, newPost, oldPost *model.Post)
|
2017-08-16 17:23:38 -05:00
|
|
|
}
|