The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/slashcommands-join/server/server.ts

60 lines
1.4 KiB

import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Rooms, Subscriptions } from '../../models/server';
import { settings } from '../../settings/server';
import { slashCommands } from '../../utils/lib/slashCommand';
import { api } from '../../../server/sdk/api';
function Join(_command: 'join', params: string, item: Record<string, string>): void {
let channel = params.trim();
if (channel === '') {
return;
}
channel = channel.replace('#', '');
const userId = Meteor.userId() as string;
const user = Meteor.users.findOne(userId);
const room = Rooms.findOneByNameAndType(channel, 'c');
if (!user) {
return;
}
if (!room) {
api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('Channel_doesnt_exist', {
postProcess: 'sprintf',
sprintf: [channel],
lng: settings.get('Language') || 'en',
}),
});
}
const subscription = Subscriptions.findOneByRoomIdAndUserId(room._id, user._id, {
fields: { _id: 1 },
});
if (subscription) {
throw new Meteor.Error('error-user-already-in-room', 'You are already in the channel', {
method: 'slashCommands',
});
}
Meteor.call('joinRoom', room._id);
}
slashCommands.add(
'join',
Join,
{
description: 'Join_the_given_channel',
params: '#channel',
permission: 'view-c-room',
},
undefined,
false,
undefined,
undefined,
);