Skip to content

Commit

Permalink
GH-200: Pass topic to zoom start (#209)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Schumacher <[email protected]>
  • Loading branch information
kott and hanzei authored Nov 29, 2021
1 parent ddea06a commit 655befa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
45 changes: 30 additions & 15 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const oAuthHelpText = `* |/zoom connect| - Connect to zoom

const alreadyConnectedString = "Already connected"

const (
actionConnect = "connect"
actionStart = "start"
actionDisconnect = "disconnect"
actionHelp = "help"
)

func (p *Plugin) getCommand() (*model.Command, error) {
iconData, err := command.GetIconData(p.API, "assets/profile.svg")
if err != nil {
Expand All @@ -44,18 +51,26 @@ func (p *Plugin) postCommandResponse(args *model.CommandArgs, text string) {
_ = p.API.SendEphemeralPost(args.UserId, post)
}

func (p *Plugin) parseCommand(rawCommand string) (cmd, action, topic string) {
split := strings.Fields(rawCommand)
cmd = split[0]
if len(split) > 1 {
action = split[1]
}
if action == actionStart {
topic = strings.Join(split[2:], " ")
}
return cmd, action, topic
}

func (p *Plugin) executeCommand(c *plugin.Context, args *model.CommandArgs) (string, error) {
split := strings.Fields(args.Command)
command := split[0]
action := ""
command, action, topic := p.parseCommand(args.Command)

if command != "/zoom" {
return fmt.Sprintf("Command '%s' is not /zoom. Please try again.", command), nil
}

if len(split) > 1 {
action = split[1]
} else {
if action == "" {
return "Please specify an action for /zoom command.", nil
}

Expand All @@ -66,13 +81,13 @@ func (p *Plugin) executeCommand(c *plugin.Context, args *model.CommandArgs) (str
}

switch action {
case "connect":
case actionConnect:
return p.runConnectCommand(user, args)
case "start":
return p.runStartCommand(args, user)
case "disconnect":
case actionStart:
return p.runStartCommand(args, user, topic)
case actionDisconnect:
return p.runDisconnectCommand(user)
case "help", "":
case actionHelp, "":
return p.runHelpCommand(user)
default:
return fmt.Sprintf("Unknown action %v", action), nil
Expand All @@ -97,7 +112,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
}

// runStartCommand runs command to start a Zoom meeting.
func (p *Plugin) runStartCommand(args *model.CommandArgs, user *model.User) (string, error) {
func (p *Plugin) runStartCommand(args *model.CommandArgs, user *model.User, topic string) (string, error) {
if _, appErr := p.API.GetChannelMember(args.ChannelId, user.Id); appErr != nil {
return fmt.Sprintf("We could not get channel members (channelId: %v)", args.ChannelId), nil
}
Expand All @@ -108,7 +123,7 @@ func (p *Plugin) runStartCommand(args *model.CommandArgs, user *model.User) (str
}

if recentMeeting {
p.postConfirm(recentMeetingLink, args.ChannelId, "", user.Id, creatorName, provider)
p.postConfirm(recentMeetingLink, args.ChannelId, topic, user.Id, creatorName, provider)
return "", nil
}

Expand All @@ -121,7 +136,7 @@ func (p *Plugin) runStartCommand(args *model.CommandArgs, user *model.User) (str
return authErr.Message, authErr.Err
}

if err := p.postMeeting(user, zoomUser.Pmi, args.ChannelId, ""); err != nil {
if err := p.postMeeting(user, zoomUser.Pmi, args.ChannelId, topic); err != nil {
return "Failed to post message. Please try again.", nil
}

Expand Down Expand Up @@ -210,7 +225,7 @@ func (p *Plugin) getAutocompleteData() *model.AutocompleteData {
}
zoom := model.NewAutocompleteData("zoom", "[command]", fmt.Sprintf("Available commands: %s", available))

start := model.NewAutocompleteData("start", "", "Starts a Zoom meeting")
start := model.NewAutocompleteData("start", "[meeting topic]", "Starts a Zoom meeting")
zoom.AddCommand(start)

// no point in showing the 'disconnect' option if OAuth is not enabled
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {PostTypes} from 'mattermost-redux/action_types';

import Client from '../client';

export function startMeeting(channelId, force = false) {
export function startMeeting(channelId, force = false, topic = '') {
return async (dispatch, getState) => {
try {
const startFunction = force ? Client.forceStartMeeting : Client.startMeeting;
const meetingURL = await startFunction(channelId, true);
const meetingURL = await startFunction(channelId, true, topic);
if (meetingURL) {
window.open(meetingURL);
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/post_type_zoom/post_type_zoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class PostTypeZoom extends React.PureComponent {
className='btn btn-lg btn-primary'
style={style.button}
rel='noopener noreferrer'
onClick={() => this.props.actions.startMeeting(this.props.currentChannelId, true)}
onClick={() => this.props.actions.startMeeting(this.props.currentChannelId, true, props.meeting_topic)}
>
{'CREATE NEW MEETING'}
</a>
Expand Down

0 comments on commit 655befa

Please sign in to comment.