Skip to content

Commit

Permalink
Implement /call link command
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 committed Feb 2, 2022
1 parent b88d04a commit 7fa292a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
48 changes: 48 additions & 0 deletions e2e/tests/start_call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,51 @@ test.describe('desktop', () => {
});
});

test.describe('auto join link', () => {
test.use({storageState: userState.users[0].storageStatePath});

test('public channel', async ({page, context}) => {
await page.locator('#post_textbox').fill('/call link');
await page.locator('#post_textbox').press('Enter');
await page.locator('#post_textbox').press('Enter');

const post = page.locator('.post-message__text').last();
await expect(post).toBeVisible();

const content = await post.textContent();
if (!content) {
test.fail();
return;
}
const link = content.replace('Call link: ', '');
page.goto(link);

expect(page.locator('#calls-widget .calls-widget-bottom-bar'));
await page.locator('#calls-widget-leave-button').click();
await expect(page.locator('#calls-widget')).toBeHidden();
});

test('dm channel', async ({page, context}) => {
const devPage = new PlaywrightDevPage(page);
await devPage.gotoDM(userState.users[1].username);

await page.locator('#post_textbox').fill('/call link');
await page.locator('#post_textbox').press('Enter');
await page.locator('#post_textbox').press('Enter');

const post = page.locator('.post-message__text').last();
await expect(post).toBeVisible();

const content = await post.textContent();
if (!content) {
test.fail();
return;
}
const link = content.replace('Call link: ', '');
page.goto(link);

expect(page.locator('#calls-widget .calls-widget-bottom-bar'));
await page.locator('#calls-widget-leave-button').click();
await expect(page.locator('#calls-widget')).toBeHidden();
});
});
37 changes: 35 additions & 2 deletions server/slash_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ const (
rootCommandTrigger = "call"
joinCommandTrigger = "join"
leaveCommandTrigger = "leave"
linkCommandTrigger = "link"
)

var subCommands = []string{joinCommandTrigger, leaveCommandTrigger}
var subCommands = []string{joinCommandTrigger, leaveCommandTrigger, linkCommandTrigger}

func getAutocompleteData() *model.AutocompleteData {
data := model.NewAutocompleteData(rootCommandTrigger, "[command]",
"Available commands: "+strings.Join(subCommands, ","))
data.AddCommand(model.NewAutocompleteData(joinCommandTrigger, "", "Joins or starts a call in the current channel"))
data.AddCommand(model.NewAutocompleteData(leaveCommandTrigger, "", "Leaves a call in the current channel"))
data.AddCommand(model.NewAutocompleteData(linkCommandTrigger, "", "Generates a link to join a call in the current channel"))
return data
}

Expand All @@ -46,14 +48,33 @@ func (p *Plugin) unregisterCommands() error {
return nil
}

func (p *Plugin) handleLinkCommand(args *model.CommandArgs) (*model.CommandResponse, error) {
channel, appErr := p.API.GetChannel(args.ChannelId)
if appErr != nil {
return nil, appErr
}

team, appErr := p.API.GetTeam(args.TeamId)
if appErr != nil {
return nil, appErr
}

link := fmt.Sprintf("%s/%s/channels/%s?join_call=true", args.SiteURL, team.Name, channel.Id)

return &model.CommandResponse{
ResponseType: model.CommandResponseTypeEphemeral,
Text: fmt.Sprintf("Call link: %s", link),
}, nil
}

func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
fields := strings.Fields(args.Command)

rootCmd := strings.TrimPrefix(fields[0], "/")
if rootCmd != rootCommandTrigger {
return &model.CommandResponse{
ResponseType: model.CommandResponseTypeEphemeral,
Text: fmt.Sprintf("Unknown command: " + rootCmd),
Text: fmt.Sprintf("Unknown command: %s", rootCmd),
}, nil
}

Expand All @@ -65,6 +86,18 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
}

subCmd := fields[1]

if subCmd == linkCommandTrigger {
resp, err := p.handleLinkCommand(args)
if err != nil {
return &model.CommandResponse{
ResponseType: model.CommandResponseTypeEphemeral,
Text: fmt.Sprintf("Error: %s", err.Error()),
}, nil
}
return resp, nil
}

for _, cmd := range subCommands {
if cmd == subCmd {
return &model.CommandResponse{}, nil
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export default class Plugin {
return {};
}
return {error: {message: 'You are not connected to a call in the current channel.'}};
} else if (subCmd === 'link') {
return {message, args};
}

return {message, args};
Expand Down

0 comments on commit 7fa292a

Please sign in to comment.