Skip to content

Commit

Permalink
Merge pull request #654 from RocketChat/commands-popup
Browse files Browse the repository at this point in the history
Add popup to autocomplete commands
  • Loading branch information
rodrigok committed Sep 1, 2015
2 parents 6a5f275 + b8dbc50 commit b7eed3d
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 58 deletions.
3 changes: 3 additions & 0 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,9 @@ a.github-fork {
.popup-user-status-busy {
background-color: @status-busy;
}
.popup-slash-command-description {
float: right;
}
.message-form {
> div {
position: relative;
Expand Down
7 changes: 6 additions & 1 deletion client/views/app/messagePopup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ Template.messagePopup.onCreated ->

template.trigger = val(template.data.trigger, '@')

template.triggerAnywhere = val(template.data.triggerAnywhere, true)

template.prefix = val(template.data.prefix, template.trigger)

template.suffix = val(template.data.suffix, ' ')

template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^| )#{template.trigger}[A-Za-z0-9-_.]*$")
if template.triggerAnywhere is true
template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^| )#{template.trigger}[A-Za-z0-9-_.]*$")
else
template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^)#{template.trigger}[A-Za-z0-9-_.]*$")

template.selectorRegex = val(template.data.selectorRegex, new RegExp "#{template.trigger}([A-Za-z0-9-_.]*)$")

Expand Down
30 changes: 30 additions & 0 deletions client/views/app/messagePopupConfig.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ Template.messagePopupConfig.helpers

return config

popupSlashCommandsConfig: ->
self = this
template = Template.instance()

config =
title: 'Commands'
collection: RocketChat.slashCommands.commands
trigger: '/'
triggerAnywhere: false
template: 'messagePopupSlashCommand'
getInput: self.getInput
getFilter: (collection, filter) ->
commands = []
for command, item of collection
if command.indexOf(filter) > -1
commands.push
_id: command
params: item.params
description: item.description

if commands.length > 10
break

commands = commands.sort (a, b) ->
return a._id > b._id

return commands

return config

emojiEnabled: ->
return RocketChat.emoji?

Expand Down
1 change: 1 addition & 0 deletions client/views/app/messagePopupConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
{{#if emojiEnabled}}{{> messagePopup popupEmojiConfig}}{{/if}}
{{> messagePopup popupChannelConfig}}
{{> messagePopup popupUserConfig}}
{{> messagePopup popupSlashCommandsConfig}}
</template>
4 changes: 4 additions & 0 deletions client/views/app/messagePopupSlashCommand.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<template name="messagePopupSlashCommand">
<strong>/{{_id}}</strong>{{#if params}} {{params}}{{/if}}
<div class="popup-slash-command-description"><i>{{description}}</i></div>
</template>
20 changes: 0 additions & 20 deletions packages/rocketchat-lib/client/slashCommand.coffee

This file was deleted.

26 changes: 26 additions & 0 deletions packages/rocketchat-lib/lib/slashCommand.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
RocketChat.slashCommands =
commands: {}

RocketChat.slashCommands.add = (command, callback, options) ->
if not RocketChat.slashCommands.commands[command]?
RocketChat.slashCommands.commands[command] =
command: command
callback: callback
params: options?.params
description: options?.description

return

RocketChat.slashCommands.run = (command, params, item) ->
if RocketChat.slashCommands.commands[command]?.callback?
callback = RocketChat.slashCommands.commands[command].callback
callback command, params, item


Meteor.methods
slashCommand: (command) ->
if not Meteor.userId()
throw new Meteor.Error 203, t('User_logged_out')

RocketChat.slashCommands.run command.cmd, command.params, command.msg

3 changes: 1 addition & 2 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Package.onUse(function(api) {

api.addFiles('lib/core.coffee', ['server', 'client']);
api.addFiles('lib/callbacks.coffee', ['server', 'client']);
api.addFiles('lib/slashCommand.coffee', ['server', 'client']);

api.addFiles([
'server/functions/checkUsernameAvailability.coffee',
Expand All @@ -31,8 +32,6 @@ Package.onUse(function(api) {
], ['server']);

api.addFiles('server/sendMessage.coffee', ['server']);
api.addFiles('server/slashCommand.coffee', ['server']);
api.addFiles('client/slashCommand.coffee', ['client']);

api.addFiles([
'settings/lib/settings.coffee',
Expand Down
20 changes: 0 additions & 20 deletions packages/rocketchat-lib/server/slashCommand.coffee

This file was deleted.

33 changes: 19 additions & 14 deletions packages/rocketchat-slashcommands-invite/invite.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
# @param {Object} message - The message object
###

class Invite
constructor: (command, params, item) ->
if command isnt 'invite' or not Match.test params, String
return
if Meteor.isClient
RocketChat.slashCommands.add 'invite', undefined,
description: 'Invite one user to join this channel'
params: '@username'
else
class Invite
constructor: (command, params, item) ->
if command isnt 'invite' or not Match.test params, String
return

username = params.trim()
if username is ''
return
username = params.trim()
if username is ''
return

username = username.replace('@', '')
username = username.replace('@', '')

user = Meteor.users.findOne({ username: username })
user = Meteor.users.findOne({ username: username })

if not user?
return
if not user?
return

Meteor.runAsUser user._id, ->
Meteor.call 'joinRoom', item.rid
Meteor.runAsUser user._id, ->
Meteor.call 'joinRoom', item.rid


RocketChat.slashCommands.add 'invite', Invite
RocketChat.slashCommands.add 'invite', Invite
2 changes: 1 addition & 1 deletion packages/rocketchat-slashcommands-invite/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Package.onUse(function(api) {
'rocketchat:[email protected]'
]);

api.addFiles('invite.coffee', 'server');
api.addFiles('invite.coffee');
});

Package.onTest(function(api) {
Expand Down

0 comments on commit b7eed3d

Please sign in to comment.