Skip to content
Snippets Groups Projects
Unverified Commit cdb372a0 authored by Diego Sampaio's avatar Diego Sampaio Committed by GitHub
Browse files

regression: remove callbacks from `Meteor.callAsync` (#28809)

parent c5f89935
No related branches found
No related tags found
No related merge requests found
......@@ -63,13 +63,13 @@ slashCommands.add({
}
rid = roomObject._id;
}
await Meteor.callAsync('hideRoom', rid, (error: string) => {
if (error) {
return api.broadcast('notify.ephemeralMessage', user._id, item.rid, {
msg: TAPi18n.__(error, { lng }),
});
}
});
try {
await Meteor.callAsync('hideRoom', rid);
} catch (error: any) {
await api.broadcast('notify.ephemeralMessage', user._id, item.rid, {
msg: TAPi18n.__(error, { lng }),
});
}
},
options: { description: 'Hide_room', params: '#room' },
});
......@@ -32,16 +32,16 @@ slashCommands.add({
if (type && type.indexOf('d') === -1) {
return;
}
return Meteor.callAsync('createDirectMessage', room, function (err: Meteor.Error) {
if (err) {
return;
}
try {
await Meteor.callAsync('createDirectMessage', room);
const subscription = Subscriptions.findOne(query);
if (!subscription) {
return;
}
roomCoordinator.openRouteLink(subscription.t, subscription, FlowRouter.current().queryParams);
});
} catch (err: unknown) {
// noop
}
},
options: {
description: 'Opens_a_channel_group_or_direct_message',
......
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { api } from '@rocket.chat/core-services';
import { slashCommands } from '../../utils/lib/slashCommand';
import { settings } from '../../settings/server';
import { dispatchToastMessage } from '../../../client/lib/toast';
slashCommands.add({
command: 'status',
callback: async function Status(_command, params, item): Promise<void> {
const userId = Meteor.userId() as string;
callback: async function Status(_command, params): Promise<void> {
const userId = Meteor.userId();
if (!userId) {
return;
}
await Meteor.callAsync('setUserStatus', null, params, (error: Meteor.Error) => {
if (error) {
dispatchToastMessage({ type: 'error', message: error });
return;
}
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('StatusMessage_Changed_Successfully', { lng: settings.get('Language') || 'en' }),
});
});
try {
await Meteor.callAsync('setUserStatus', null, params);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
},
options: {
description: 'Slash_Status_Description',
......
......@@ -9,26 +9,29 @@ import { settings } from '../../settings/server';
slashCommands.add({
command: 'status',
callback: async function Status(_command: 'status', params, item): Promise<void> {
const userId = Meteor.userId() as string;
const userId = Meteor.userId();
if (!userId) {
return;
}
await Meteor.callAsync('setUserStatus', null, params, async (err: Meteor.Error) => {
const user = await Users.findOneById(userId, { projection: { language: 1 } });
const lng = user?.language || settings.get('Language') || 'en';
const user = await Users.findOneById(userId, { projection: { language: 1 } });
const lng = user?.language || settings.get('Language') || 'en';
if (err) {
if (err.error === 'error-not-allowed') {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('StatusMessage_Change_Disabled', { lng }),
});
}
try {
await Meteor.callAsync('setUserStatus', null, params);
throw err;
} else {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('StatusMessage_Changed_Successfully', { lng }),
});
} catch (err: any) {
if (err.error === 'error-not-allowed') {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('StatusMessage_Changed_Successfully', { lng }),
msg: TAPi18n.__('StatusMessage_Change_Disabled', { lng }),
});
}
});
throw err;
}
},
options: {
description: 'Slash_Status_Description',
......
......@@ -10,14 +10,13 @@ slashCommands.add({
command: 'topic',
callback: async function Topic(_command: 'topic', params, item): Promise<void> {
if (hasPermission('edit-room', item.rid)) {
await Meteor.callAsync('saveRoomSettings', item.rid, 'roomTopic', params, (error: Meteor.Error) => {
if (error) {
dispatchToastMessage({ type: 'error', message: error });
throw error;
}
try {
await Meteor.callAsync('saveRoomSettings', item.rid, 'roomTopic', params);
callbacks.run('roomTopicChanged', ChatRoom.findOne(item.rid));
});
} catch (error: unknown) {
dispatchToastMessage({ type: 'error', message: error });
throw error;
}
}
},
options: {
......
import { Meteor } from 'meteor/meteor';
import moment from 'moment-timezone';
import type { ILivechatBusinessHour } from '@rocket.chat/core-typings';
import { LivechatBusinessHourTypes } from '@rocket.chat/core-typings';
import { LivechatBusinessHours, LivechatDepartment, LivechatDepartmentAgents, Users } from '@rocket.chat/models';
import { isEnterprise } from '../../../license/server/license';
const getAllAgentIdsWithoutDepartment = async (): Promise<string[]> => {
const agentIdsWithDepartment = (
await LivechatDepartmentAgents.find({ departmentEnabled: true }, { projection: { agentId: 1 } }).toArray()
......@@ -57,29 +58,26 @@ export const removeBusinessHourByAgentIds = async (agentIds: string[], businessH
};
export const resetDefaultBusinessHourIfNeeded = async (): Promise<void> => {
await Meteor.callAsync('license:isEnterprise', async (err: any, isEnterprise: any) => {
if (err) {
throw err;
}
if (isEnterprise) {
return;
}
const defaultBusinessHour = await LivechatBusinessHours.findOneDefaultBusinessHour<Pick<ILivechatBusinessHour, '_id'>>({
projection: { _id: 1 },
});
if (!defaultBusinessHour) {
return;
}
await LivechatBusinessHours.update(
{ _id: defaultBusinessHour._id },
{
$set: {
timezone: {
name: moment.tz.guess(),
utc: String(moment().utcOffset() / 60),
},
if (isEnterprise()) {
return;
}
const defaultBusinessHour = await LivechatBusinessHours.findOneDefaultBusinessHour<Pick<ILivechatBusinessHour, '_id'>>({
projection: { _id: 1 },
});
if (!defaultBusinessHour) {
return;
}
await LivechatBusinessHours.updateOne(
{ _id: defaultBusinessHour._id },
{
$set: {
timezone: {
name: moment.tz.guess(),
utc: String(moment().utcOffset() / 60),
},
},
);
});
},
);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment