diff --git a/app/slashcommands-create/client/client.js b/app/slashcommands-create/client/client.js deleted file mode 100644 index 68a96f6ae3a..00000000000 --- a/app/slashcommands-create/client/client.js +++ /dev/null @@ -1,7 +0,0 @@ -import { slashCommands } from '../../utils'; - -slashCommands.add('create', null, { - description: 'Create_A_New_Channel', - params: '#channel', - permission: ['create-c', 'create-p'], -}); diff --git a/app/slashcommands-create/client/client.ts b/app/slashcommands-create/client/client.ts new file mode 100644 index 00000000000..f618d472f09 --- /dev/null +++ b/app/slashcommands-create/client/client.ts @@ -0,0 +1,15 @@ +import { slashCommands } from '../../utils/lib/slashCommand'; + +slashCommands.add( + 'create', + undefined, + { + description: 'Create_A_New_Channel', + params: '#channel', + permission: ['create-c', 'create-p'], + }, + undefined, + false, + undefined, + undefined, +); diff --git a/app/slashcommands-create/client/index.js b/app/slashcommands-create/client/index.ts similarity index 100% rename from app/slashcommands-create/client/index.js rename to app/slashcommands-create/client/index.ts diff --git a/app/slashcommands-create/server/index.js b/app/slashcommands-create/server/index.ts similarity index 100% rename from app/slashcommands-create/server/index.js rename to app/slashcommands-create/server/index.ts diff --git a/app/slashcommands-create/server/server.js b/app/slashcommands-create/server/server.js deleted file mode 100644 index 14b6b6d3867..00000000000 --- a/app/slashcommands-create/server/server.js +++ /dev/null @@ -1,62 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Match } from 'meteor/check'; -import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; - -import { settings } from '../../settings'; -import { Rooms } from '../../models'; -import { slashCommands } from '../../utils'; -import { api } from '../../../server/sdk/api'; - -function Create(command, params, item) { - function getParams(str) { - const regex = /(--(\w+))+/g; - const result = []; - let m; - while ((m = regex.exec(str)) !== null) { - if (m.index === regex.lastIndex) { - regex.lastIndex++; - } - result.push(m[2]); - } - return result; - } - - const regexp = new RegExp(settings.get('UTF8_Channel_Names_Validation')); - - if (command !== 'create' || !Match.test(params, String)) { - return; - } - let channel = regexp.exec(params.trim()); - channel = channel ? channel[0] : ''; - if (channel === '') { - return; - } - - const user = Meteor.users.findOne(Meteor.userId()); - const room = Rooms.findOneByName(channel); - if (room != null) { - api.broadcast('notify.ephemeralMessage', Meteor.userId(), item.rid, { - msg: TAPi18n.__( - 'Channel_already_exist', - { - postProcess: 'sprintf', - sprintf: [channel], - }, - user.language, - ), - }); - return; - } - - if (getParams(params).indexOf('private') > -1) { - return Meteor.call('createPrivateGroup', channel, []); - } - - Meteor.call('createChannel', channel, []); -} - -slashCommands.add('create', Create, { - description: 'Create_A_New_Channel', - params: '#channel', - permission: ['create-c', 'create-p'], -}); diff --git a/app/slashcommands-create/server/server.ts b/app/slashcommands-create/server/server.ts new file mode 100644 index 00000000000..ada7ff23388 --- /dev/null +++ b/app/slashcommands-create/server/server.ts @@ -0,0 +1,68 @@ +import { Meteor } from 'meteor/meteor'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; + +import { settings } from '../../settings/server'; +import { Rooms } from '../../models/server'; +import { slashCommands } from '../../utils/lib/slashCommand'; +import { api } from '../../../server/sdk/api'; + +function Create(_command: 'create', params: string, item: Record): void { + function getParams(str: string): string[] { + const regex = /(--(\w+))+/g; + const result = []; + let m; + while ((m = regex.exec(str)) !== null) { + if (m.index === regex.lastIndex) { + regex.lastIndex++; + } + result.push(m[2]); + } + return result; + } + + const regexp = new RegExp(settings.get('UTF8_Channel_Names_Validation') as string); + + const channel = regexp.exec(params.trim()); + + if (!channel) { + return; + } + + const channelStr: string = channel ? channel[0] : ''; + if (channelStr === '') { + return; + } + const userId = Meteor.userId() as string; + + const room = Rooms.findOneByName(channelStr); + if (room != null) { + api.broadcast('notify.ephemeralMessage', userId, item.rid, { + msg: TAPi18n.__('Channel_already_exist', { + postProcess: 'sprintf', + sprintf: [channelStr], + lng: settings.get('Language') || 'en', + }), + }); + return; + } + + if (getParams(params).indexOf('private') > -1) { + return Meteor.call('createPrivateGroup', channelStr, []); + } + + Meteor.call('createChannel', channelStr, []); +} + +slashCommands.add( + 'create', + Create, + { + description: 'Create_A_New_Channel', + params: '#channel', + permission: ['create-c', 'create-p'], + }, + undefined, + false, + undefined, + undefined, +);