Add popup to autocomplete commands

pull/654/head
Rodrigo Nascimento 11 years ago
parent 6b6d5eeef7
commit b8dbc50610
  1. 3
      client/stylesheets/base.less
  2. 7
      client/views/app/messagePopup.coffee
  3. 30
      client/views/app/messagePopupConfig.coffee
  4. 1
      client/views/app/messagePopupConfig.html
  5. 4
      client/views/app/messagePopupSlashCommand.html
  6. 20
      packages/rocketchat-lib/client/slashCommand.coffee
  7. 26
      packages/rocketchat-lib/lib/slashCommand.coffee
  8. 3
      packages/rocketchat-lib/package.js
  9. 20
      packages/rocketchat-lib/server/slashCommand.coffee
  10. 33
      packages/rocketchat-slashcommands-invite/invite.coffee
  11. 2
      packages/rocketchat-slashcommands-invite/package.js

@ -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;

@ -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-_.]*)$")

@ -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?

@ -2,4 +2,5 @@
{{#if emojiEnabled}}{{> messagePopup popupEmojiConfig}}{{/if}}
{{> messagePopup popupChannelConfig}}
{{> messagePopup popupUserConfig}}
{{> messagePopup popupSlashCommandsConfig}}
</template>

@ -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>

@ -1,20 +0,0 @@
RocketChat.slashCommands = {}
RocketChat.slashCommands.add = (command, callback) ->
if !RocketChat.slashCommands[command]?
RocketChat.slashCommands[command] = callback
return
RocketChat.slashCommands.run = (command, params, item) ->
if RocketChat.slashCommands[command]?
callback = RocketChat.slashCommands[command]
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

@ -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

@ -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',
@ -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',

@ -1,20 +0,0 @@
RocketChat.slashCommands = {}
RocketChat.slashCommands.add = (command, callback) ->
if !RocketChat.slashCommands[command]?
RocketChat.slashCommands[command] = callback
return
RocketChat.slashCommands.run = (command, params, item) ->
if RocketChat.slashCommands[command]?
callback = RocketChat.slashCommands[command]
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,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

@ -14,7 +14,7 @@ Package.onUse(function(api) {
'rocketchat:lib@0.0.1'
]);
api.addFiles('invite.coffee', 'server');
api.addFiles('invite.coffee');
});
Package.onTest(function(api) {

Loading…
Cancel
Save