refactor: Convert meteor call to callAsync (2/N) (#28588)

pull/28584/head
Marcos Spessatto Defendi 3 years ago committed by GitHub
parent d3904b313e
commit 62eb6793e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/meteor/app/slashcommand-asciiarts/lib/gimme.ts
  2. 4
      apps/meteor/app/slashcommand-asciiarts/lib/lenny.ts
  3. 4
      apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts
  4. 4
      apps/meteor/app/slashcommand-asciiarts/lib/tableflip.ts
  5. 4
      apps/meteor/app/slashcommand-asciiarts/lib/unflip.ts
  6. 4
      apps/meteor/app/slashcommands-archiveroom/server/server.ts
  7. 6
      apps/meteor/app/slashcommands-create/server/server.ts
  8. 4
      apps/meteor/app/slashcommands-hide/server/hide.ts
  9. 42
      apps/meteor/app/slashcommands-invite/server/server.ts
  10. 6
      apps/meteor/app/slashcommands-inviteall/server/server.ts
  11. 4
      apps/meteor/app/slashcommands-join/server/server.ts
  12. 4
      apps/meteor/app/slashcommands-kick/server/server.ts
  13. 4
      apps/meteor/app/slashcommands-leave/server/leave.ts
  14. 4
      apps/meteor/app/slashcommands-me/server/me.ts
  15. 6
      apps/meteor/app/slashcommands-msg/server/server.ts
  16. 4
      apps/meteor/app/slashcommands-mute/server/mute.ts
  17. 4
      apps/meteor/app/slashcommands-mute/server/unmute.ts
  18. 4
      apps/meteor/app/slashcommands-status/server/status.ts
  19. 4
      apps/meteor/app/slashcommands-unarchiveroom/server/server.ts
  20. 2
      apps/meteor/app/user-status/server/methods/setUserStatus.ts
  21. 18
      apps/meteor/ee/app/api-enterprise/server/canned-responses.ts
  22. 2
      apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts
  23. 2
      apps/meteor/ee/app/livechat-enterprise/server/hooks/resumeOnHold.ts

@ -7,10 +7,10 @@ import { slashCommands } from '../../utils/lib/slashCommand';
* @param {Object} message - The message object
*/
function Gimme(_command: 'gimme', params: string, item: RequiredField<Partial<IMessage>, 'rid'>): void {
async function Gimme(_command: 'gimme', params: string, item: RequiredField<Partial<IMessage>, 'rid'>): Promise<void> {
const msg = item;
msg.msg = `༼ つ ◕_◕ ༽つ ${params}`;
Meteor.call('sendMessage', msg);
await Meteor.callAsync('sendMessage', msg);
}
slashCommands.add({

@ -7,10 +7,10 @@ import { slashCommands } from '../../utils/lib/slashCommand';
* @param {Object} message - The message object
*/
function LennyFace(_command: 'lennyface', params: string, item: RequiredField<Partial<IMessage>, 'rid'>): void {
async function LennyFace(_command: 'lennyface', params: string, item: RequiredField<Partial<IMessage>, 'rid'>): Promise<void> {
const msg = item;
msg.msg = `${params} ( ͡° ͜ʖ ͡°)`;
Meteor.call('sendMessage', msg);
await Meteor.callAsync('sendMessage', msg);
}
slashCommands.add({

@ -8,10 +8,10 @@ import { slashCommands } from '../../utils/lib/slashCommand';
slashCommands.add({
command: 'shrug',
callback: (_command: 'shrug', params, item): void => {
callback: async (_command: 'shrug', params, item): Promise<void> => {
const msg = item;
msg.msg = `${params} ¯\\\\_(ツ)_/¯`;
Meteor.call('sendMessage', msg);
await Meteor.callAsync('sendMessage', msg);
},
options: {
description: 'Slash_Shrug_Description',

@ -8,10 +8,10 @@ import { slashCommands } from '../../utils/lib/slashCommand';
slashCommands.add({
command: 'tableflip',
callback: (_command, params, item): void => {
callback: async (_command, params, item): Promise<void> => {
const msg = item;
msg.msg = `${params} (╯°□°)╯︵ ┻━┻`;
Meteor.call('sendMessage', msg);
await Meteor.callAsync('sendMessage', msg);
},
options: {
description: 'Slash_Tableflip_Description',

@ -8,10 +8,10 @@ import { slashCommands } from '../../utils/lib/slashCommand';
slashCommands.add({
command: 'unflip',
callback: (_command: 'unflip', params, item): void => {
callback: async (_command: 'unflip', params, item): Promise<void> => {
const msg = item;
msg.msg = `${params} ┬─┬ ノ( ゜-゜ノ)`;
Meteor.call('sendMessage', msg);
await Meteor.callAsync('sendMessage', msg);
},
options: {
description: 'Slash_TableUnflip_Description',

@ -8,7 +8,7 @@ import { settings } from '../../settings/server';
slashCommands.add({
command: 'archive',
callback: function Archive(_command, params, item): void {
callback: async function Archive(_command, params, item): Promise<void> {
let channel = params.trim();
let room;
@ -53,7 +53,7 @@ slashCommands.add({
});
return;
}
Meteor.call('archiveRoom', room._id);
await Meteor.callAsync('archiveRoom', room._id);
Messages.createRoomArchivedByRoomIdAndUser(room._id, Meteor.user());
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {

@ -8,7 +8,7 @@ import { slashCommands } from '../../utils/lib/slashCommand';
slashCommands.add({
command: 'create',
callback: function Create(_command: 'create', params, item): void {
callback: async function Create(_command: 'create', params, item): Promise<void> {
function getParams(str: string): string[] {
const regex = /(--(\w+))+/g;
const result = [];
@ -49,10 +49,10 @@ slashCommands.add({
}
if (getParams(params).indexOf('private') > -1) {
return Meteor.call('createPrivateGroup', channelStr, []);
return Meteor.callAsync('createPrivateGroup', channelStr, []);
}
Meteor.call('createChannel', channelStr, []);
await Meteor.callAsync('createChannel', channelStr, []);
},
options: {
description: 'Create_A_New_Channel',

@ -13,7 +13,7 @@ import { slashCommands } from '../../utils/server';
slashCommands.add({
command: 'hide',
callback: (_command: 'hide', param, item): void => {
callback: async (_command: 'hide', param, item): Promise<void> => {
const room = param.trim();
const userId = Meteor.userId();
if (!userId) {
@ -63,7 +63,7 @@ slashCommands.add({
}
rid = roomObject._id;
}
Meteor.call('hideRoom', rid, (error: string) => {
await Meteor.callAsync('hideRoom', rid, (error: string) => {
if (error) {
return api.broadcast('notify.ephemeralMessage', user._id, item.rid, {
msg: TAPi18n.__(error, { lng }),

@ -12,7 +12,7 @@ import { Subscriptions } from '../../models/server';
*/
slashCommands.add({
command: 'invite',
callback: (_command: 'invite', params, item): void => {
callback: async (_command: 'invite', params, item): Promise<void> => {
const usernames = params
.split(/[\s,]/)
.map((username) => username.replace(/(^@)|( @)/, ''))
@ -54,27 +54,29 @@ slashCommands.add({
return false;
});
usersFiltered.forEach(function (user) {
try {
return Meteor.call('addUserToRoom', {
rid: item.rid,
username: user.username,
});
} catch ({ error }) {
if (typeof error !== 'string') {
return;
}
if (error === 'cant-invite-for-direct-room') {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('Cannot_invite_users_to_direct_rooms', { lng: settings.get('Language') || 'en' }),
});
} else {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__(error, { lng: settings.get('Language') || 'en' }),
await Promise.all(
usersFiltered.map(async (user) => {
try {
return await Meteor.callAsync('addUserToRoom', {
rid: item.rid,
username: user.username,
});
} catch ({ error }) {
if (typeof error !== 'string') {
return;
}
if (error === 'cant-invite-for-direct-room') {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('Cannot_invite_users_to_direct_rooms', { lng: settings.get('Language') || 'en' }),
});
} else {
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__(error, { lng: settings.get('Language') || 'en' }),
});
}
}
}
});
}),
);
},
options: {
description: 'Invite_user_to_join_channel',

@ -13,7 +13,7 @@ import { slashCommands } from '../../utils/lib/slashCommand';
import { settings } from '../../settings/server';
function inviteAll<T extends string>(type: T): SlashCommand<T>['callback'] {
return function inviteAll(command: T, params: string, item): void {
return async function inviteAll(command: T, params: string, item): Promise<void> {
if (!/invite\-all-(to|from)/.test(command)) {
return;
}
@ -66,7 +66,7 @@ function inviteAll<T extends string>(type: T): SlashCommand<T>['callback'] {
const users = cursor.fetch().map((s: ISubscription) => s.u.username);
if (!targetChannel && ['c', 'p'].indexOf(baseChannel.t) > -1) {
Meteor.call(baseChannel.t === 'c' ? 'createChannel' : 'createPrivateGroup', channel, users);
await Meteor.callAsync(baseChannel.t === 'c' ? 'createChannel' : 'createPrivateGroup', channel, users);
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {
msg: TAPi18n.__('Channel_created', {
postProcess: 'sprintf',
@ -75,7 +75,7 @@ function inviteAll<T extends string>(type: T): SlashCommand<T>['callback'] {
}),
});
} else {
Meteor.call('addUsersToRoom', {
await Meteor.callAsync('addUsersToRoom', {
rid: targetChannel._id,
users,
});

@ -8,7 +8,7 @@ import { slashCommands } from '../../utils/lib/slashCommand';
slashCommands.add({
command: 'join',
callback: (_command: 'join', params, item): void => {
callback: async (_command: 'join', params, item): Promise<void> => {
let channel = params.trim();
if (channel === '') {
return;
@ -44,7 +44,7 @@ slashCommands.add({
});
}
Meteor.call('joinRoom', room._id);
await Meteor.callAsync('joinRoom', room._id);
},
options: {
description: 'Join_the_given_channel',

@ -9,7 +9,7 @@ import { slashCommands } from '../../utils/lib/slashCommand';
slashCommands.add({
command: 'kick',
callback: (_command: 'kick', params, item): void => {
callback: async (_command: 'kick', params, item): Promise<void> => {
const username = params.trim().replace('@', '');
if (username === '') {
return;
@ -32,7 +32,7 @@ slashCommands.add({
}
const { rid } = item;
Meteor.call('removeUserFromRoom', { rid, username });
await Meteor.callAsync('removeUserFromRoom', { rid, username });
},
options: {
description: 'Remove_someone_from_room',

@ -11,9 +11,9 @@ import { Users } from '../../models/server';
* Leave is a named function that will replace /leave commands
* @param {Object} message - The message object
*/
const Leave: SlashCommand<'leave'>['callback'] = function Leave(_command, _params, item): void {
const Leave: SlashCommand<'leave'>['callback'] = async function Leave(_command, _params, item): Promise<void> {
try {
Meteor.call('leaveRoom', item.rid);
await Meteor.callAsync('leaveRoom', item.rid);
} catch ({ error }) {
const userId = Meteor.userId() as string;
if (typeof error !== 'string') {

@ -8,11 +8,11 @@ import { slashCommands } from '../../utils/lib/slashCommand';
*/
slashCommands.add({
command: 'me',
callback: function Me(_command: 'me', params, item): void {
callback: async function Me(_command: 'me', params, item): Promise<void> {
if (params.trim()) {
const msg = item;
msg.msg = `_${params}_`;
Meteor.call('sendMessage', msg);
await Meteor.callAsync('sendMessage', msg);
}
},
options: {

@ -13,7 +13,7 @@ import { Users } from '../../models/server';
slashCommands.add({
command: 'msg',
callback: function Msg(_command: 'msg', params, item): void {
callback: async function Msg(_command: 'msg', params, item): Promise<void> {
const trimmedParams = params.trim();
const separator = trimmedParams.indexOf(' ');
const userId = Meteor.userId() as string;
@ -38,13 +38,13 @@ slashCommands.add({
});
return;
}
const { rid } = Meteor.call('createDirectMessage', targetUsername);
const { rid } = await Meteor.callAsync('createDirectMessage', targetUsername);
const msgObject = {
_id: Random.id(),
rid,
msg: message,
};
Meteor.call('sendMessage', msgObject);
await Meteor.callAsync('sendMessage', msgObject);
},
options: {
description: 'Direct_message_someone',

@ -12,7 +12,7 @@ import { Users } from '../../models/server';
slashCommands.add({
command: 'mute',
callback: function Mute(_command: 'mute', params, item): void {
callback: async function Mute(_command: 'mute', params, item): Promise<void> {
const username = params.trim().replace('@', '');
if (username === '') {
return;
@ -30,7 +30,7 @@ slashCommands.add({
});
}
Meteor.call('muteUserInRoom', {
await Meteor.callAsync('muteUserInRoom', {
rid: item.rid,
username,
});

@ -12,7 +12,7 @@ import { settings } from '../../settings/server';
slashCommands.add({
command: 'unmute',
callback: function Unmute(_command, params, item): void {
callback: async function Unmute(_command, params, item): Promise<void> {
const username = params.trim().replace('@', '');
if (username === '') {
return;
@ -30,7 +30,7 @@ slashCommands.add({
return;
}
Meteor.call('unmuteUserInRoom', {
await Meteor.callAsync('unmuteUserInRoom', {
rid: item.rid,
username,
});

@ -8,10 +8,10 @@ import { Users } from '../../models/server';
slashCommands.add({
command: 'status',
callback: function Status(_command: 'status', params, item): void {
callback: async function Status(_command: 'status', params, item): Promise<void> {
const userId = Meteor.userId() as string;
Meteor.call('setUserStatus', null, params, (err: Meteor.Error) => {
await Meteor.callAsync('setUserStatus', null, params, (err: Meteor.Error) => {
const user = userId && Users.findOneById(userId, { fields: { language: 1 } });
const lng = user?.language || settings.get('Language') || 'en';

@ -10,7 +10,7 @@ import { RoomMemberActions } from '../../../definition/IRoomTypeConfig';
slashCommands.add({
command: 'unarchive',
callback: function Unarchive(_command: 'unarchive', params, item): void {
callback: async function Unarchive(_command: 'unarchive', params, item): Promise<void> {
let channel = params.trim();
let room;
@ -51,7 +51,7 @@ slashCommands.add({
return;
}
Meteor.call('unarchiveRoom', room._id);
await Meteor.callAsync('unarchiveRoom', room._id);
Messages.createRoomUnarchivedByRoomIdAndUser(room._id, Meteor.user());
void api.broadcast('notify.ephemeralMessage', userId, item.rid, {

@ -26,7 +26,7 @@ Meteor.methods<ServerMethods>({
method: 'setUserStatus',
});
}
Meteor.call('UserPresence:setDefaultStatus', statusType);
await Meteor.callAsync('UserPresence:setDefaultStatus', statusType);
}
if (statusText || statusText === '') {

@ -52,22 +52,18 @@ API.v1.addRoute(
},
async post() {
const { _id, shortcut, text, scope, departmentId, tags } = this.bodyParams;
Meteor.runAsUser(this.userId, () => {
Meteor.call('saveCannedResponse', _id, {
shortcut,
text,
scope,
...(tags && { tags }),
...(departmentId && { departmentId }),
});
await Meteor.callAsync('saveCannedResponse', _id, {
shortcut,
text,
scope,
...(tags && { tags }),
...(departmentId && { departmentId }),
});
return API.v1.success();
},
async delete() {
const { _id } = this.requestParams();
Meteor.runAsUser(this.userId, () => {
Meteor.call('removeCannedResponse', _id);
});
await Meteor.callAsync('removeCannedResponse', _id);
return API.v1.success();
},
},

@ -57,7 +57,7 @@ export const removeBusinessHourByAgentIds = async (agentIds: string[], businessH
};
export const resetDefaultBusinessHourIfNeeded = async (): Promise<void> => {
Meteor.call('license:isEnterprise', async (err: any, isEnterprise: any) => {
await Meteor.callAsync('license:isEnterprise', async (err: any, isEnterprise: any) => {
if (err) {
throw err;
}

@ -36,7 +36,7 @@ callbacks.add(
// if a visitor sends a message in room which is On Hold
if (message.token && room.onHold) {
Meteor.call('livechat:resumeOnHold', rid, { clientAction: false });
await Meteor.callAsync('livechat:resumeOnHold', rid, { clientAction: false });
}
return message;

Loading…
Cancel
Save