Skip to content

Commit

Permalink
Update to MM v5.2 and webpack externals
Browse files Browse the repository at this point in the history
  • Loading branch information
seansackowitz committed Aug 18, 2018
1 parent 21761e1 commit c2303bd
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 789 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Inside the `/webapp` directory, you will find the JS and React files that make u
## TODO

There is still a lot of work to do to separate this from the Zoom plugin, such as:
1. Convert names from zoom to jitsi
1. ~~Convert names from zoom to jitsi~~
2. Integrate with the Jitsi server for meeting status
3. Clean up a lot of unnecessary code
4. Add meeting topics back
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"id": "jitsi",
"name": "Jitsi",
"description": "Jitsi audio and video conferencing plugin for Mattermost. Follow https://github.com/seansackowitz/mattermost-plugin-jitsi for notifications on updates.",
"version": "0.2.0",
"version": "1.0.0",
"backend": {
"executable": "server/plugin.exe"
},
"webapp": {
"bundle_path": "/static/jitsi_bundle.js"
"bundle_path": "webapp/jitsi_bundle.js"
},
"settings_schema": {
"settings": [
Expand Down
17 changes: 0 additions & 17 deletions server/config.go

This file was deleted.

6 changes: 2 additions & 4 deletions server/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
)
import "github.com/mattermost/mattermost-server/plugin"

func main() {
rpcplugin.Main(&Plugin{})
plugin.ClientMain(&Plugin{})
}
50 changes: 17 additions & 33 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"regexp"
"strings"
"sync/atomic"

"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
Expand All @@ -18,42 +17,27 @@ const (
)

type Plugin struct {
api plugin.API
configuration atomic.Value
}
plugin.MattermostPlugin

func (p *Plugin) OnActivate(api plugin.API) error {
p.api = api
if err := p.OnConfigurationChange(); err != nil {
return err
}
JitsiURL string
}

config := p.config()
if err := config.IsValid(); err != nil {
func (p *Plugin) OnActivate() error {
if err := p.IsConfigurationValid(); err != nil {
return err
}

return nil
}

func (p *Plugin) config() *Configuration {
return p.configuration.Load().(*Configuration)
}

func (p *Plugin) OnConfigurationChange() error {
var configuration Configuration
err := p.api.LoadPluginConfiguration(&configuration)
p.configuration.Store(&configuration)
return err
}

func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
config := p.config()
if err := config.IsValid(); err != nil {
http.Error(w, "This plugin is not configured.", http.StatusNotImplemented)
return
func (p *Plugin) IsConfigurationValid() error {
if len(p.JitsiURL) == 0 {
return fmt.Errorf("Jitsi URL is not configured.")
}
return nil
}

func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
switch path := r.URL.Path; path {
case "/api/v1/meetings":
p.handleStartMeeting(w, r)
Expand Down Expand Up @@ -93,12 +77,12 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {

var user *model.User
var err *model.AppError
user, err = p.api.GetUser(userId)
user, err = p.API.GetUser(userId)
if err != nil {
http.Error(w, err.Error(), err.StatusCode)
}

if _, err := p.api.GetChannelMember(req.ChannelId, user.Id); err != nil {
if _, err := p.API.GetChannelMember(req.ChannelId, user.Id); err != nil {
http.Error(w, "Forbidden", http.StatusForbidden)
return
}
Expand All @@ -108,14 +92,14 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
if len(req.Topic) < 1 {
meetingID = generateRoomWithoutSeparator()
}
jitsiURL := strings.TrimSpace(p.config().JitsiURL)
jitsiURL := strings.TrimSpace(p.JitsiURL)
meetingURL := jitsiURL + "/" + meetingID

post := &model.Post{
UserId: user.Id,
ChannelId: req.ChannelId,
Message: fmt.Sprintf("Meeting started at %s.", meetingURL),
Type: "custom_zoom",
Type: "custom_jitsi",
Props: map[string]interface{}{
"meeting_id": meetingID,
"meeting_link": meetingURL,
Expand All @@ -128,11 +112,11 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
},
}

if post, err := p.api.CreatePost(post); err != nil {
if post, err := p.API.CreatePost(post); err != nil {
http.Error(w, err.Error(), err.StatusCode)
return
} else {
err = p.api.KeyValueStore().Set(fmt.Sprintf("%v%v", POST_MEETING_KEY, meetingID), []byte(post.Id))
err = p.API.KVSet(fmt.Sprintf("%v%v", POST_MEETING_KEY, meetingID), []byte(post.Id))
if err != nil {
http.Error(w, err.Error(), err.StatusCode)
return
Expand Down
4 changes: 2 additions & 2 deletions webapp/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function startMeeting(channelId, personal = false, topic = '', meetingId
await Client.startMeeting(channelId, personal, topic, meetingId);
} catch (error) {
const post = {
id: 'zoomPlugin' + Date.now(),
id: 'jitsiPlugin' + Date.now(),
create_at: Date.now(),
update_at: 0,
edit_at: 0,
Expand All @@ -19,7 +19,7 @@ export function startMeeting(channelId, personal = false, topic = '', meetingId
root_id: '',
parent_id: '',
original_id: '',
message: 'We could not verify your Mattermost account in Zoom. Please ensure that your Mattermost email address matches your Zoom email address.',
message: 'We could not start a meeting at this time.',
type: 'system_ephemeral',
props: {},
hashtags: '',
Expand Down
2 changes: 1 addition & 1 deletion webapp/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Client {
this.url = '/plugins/jitsi';
}

startMeeting = async (channelId, personal = true, topic = '', meetingId = 0) => {
startMeeting = async (channelId, personal = false, topic = '', meetingId = 0) => {
return this.doPost(`${this.url}/api/v1/meetings`, {channel_id: channelId, personal, topic, meeting_id: meetingId});
}

Expand Down
Loading

0 comments on commit c2303bd

Please sign in to comment.