Convert to typescript the slash commands create files (#24306)

Co-authored-by: Leonardo Ostjen Couto <leonardoostjen@gmail.com>
pull/24441/head^2
eduardofcabrera 4 years ago committed by GitHub
parent 4487f9ecc0
commit 61fa8f140f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/slashcommands-create/client/client.js
  2. 15
      app/slashcommands-create/client/client.ts
  3. 0
      app/slashcommands-create/client/index.ts
  4. 0
      app/slashcommands-create/server/index.ts
  5. 62
      app/slashcommands-create/server/server.js
  6. 68
      app/slashcommands-create/server/server.ts

@ -1,7 +0,0 @@
import { slashCommands } from '../../utils';
slashCommands.add('create', null, {
description: 'Create_A_New_Channel',
params: '#channel',
permission: ['create-c', 'create-p'],
});

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

@ -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'],
});

@ -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<string, string>): 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,
);
Loading…
Cancel
Save