Skip to content

Commit

Permalink
Merge pull request #2 from mattermost/mm-11026
Browse files Browse the repository at this point in the history
MM-11026 Migrate to use plugin v2 system coming in Mattermost 5.2
  • Loading branch information
jwilander authored Jul 16, 2018
2 parents 25f7aa8 + bbd0213 commit 95f70fd
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 34 deletions.
128 changes: 107 additions & 21 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import:
- package: github.com/gorilla/mux
version: ^1.6.0
- package: github.com/kballard/go-shellquote
- package: github.com/mattermost/mattermost-server
version: ^4.5.0-rc1
subpackages:
- plugin
- plugin/rpcplugin
- package: golang.org/x/image
subpackages:
- font
- math/fixed
- package: gopkg.in/yaml.v2
- package: github.com/mattermost/mattermost-server
testImport:
- package: github.com/stretchr/testify
version: ^1.1.4
Expand Down
15 changes: 8 additions & 7 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"strings"

"github.com/gorilla/mux"
"github.com/kballard/go-shellquote"
shellquote "github.com/kballard/go-shellquote"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
"github.com/mattermost/mattermost-server/plugin/rpcplugin"

"github.com/mattermost/mattermost-plugin-memes/meme"
"github.com/mattermost/mattermost-plugin-memes/memelibrary"
Expand Down Expand Up @@ -101,20 +100,22 @@ func serveTemplateJPEG(w http.ResponseWriter, r *http.Request) {
}

type Plugin struct {
plugin.MattermostPlugin

router *mux.Router
}

func (p *Plugin) OnActivate(api plugin.API) error {
func (p *Plugin) OnActivate() error {
p.router = mux.NewRouter()
p.router.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
return api.RegisterCommand(&model.Command{
return p.API.RegisterCommand(&model.Command{
Trigger: "meme",
AutoComplete: true,
AutoCompleteDesc: "Renders custom memes so you can express yourself with culture.",
})
}

func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Mattermost-User-Id") == "" {
http.Error(w, "please log in", http.StatusForbidden)
return
Expand All @@ -123,7 +124,7 @@ func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
p.router.ServeHTTP(w, r)
}

func (p *Plugin) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))

if input == "" {
Expand Down Expand Up @@ -182,6 +183,6 @@ func main() {
os.Exit(1)
}
} else {
rpcplugin.Main(&Plugin{})
plugin.ClientMain(&Plugin{})
}
}
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ backend:
executable: plugin.exe
name: Memes
description: Gives you the ability to quickly create and post memes via a /meme slash command.
version: '0.1'
version: '1.0'

0 comments on commit 95f70fd

Please sign in to comment.