diff --git a/apps/meteor/app/slashcommand-asciiarts/lib/gimme.ts b/apps/meteor/app/slashcommand-asciiarts/lib/gimme.ts index 795c10aa3be..95a43b495ec 100644 --- a/apps/meteor/app/slashcommand-asciiarts/lib/gimme.ts +++ b/apps/meteor/app/slashcommand-asciiarts/lib/gimme.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, 'rid'>): void { +async function Gimme(_command: 'gimme', params: string, item: RequiredField, 'rid'>): Promise { const msg = item; msg.msg = `༼ つ ◕_◕ ༽つ ${params}`; - Meteor.call('sendMessage', msg); + await Meteor.callAsync('sendMessage', msg); } slashCommands.add({ diff --git a/apps/meteor/app/slashcommand-asciiarts/lib/lenny.ts b/apps/meteor/app/slashcommand-asciiarts/lib/lenny.ts index cba8f3f3857..ad3f4a1947f 100644 --- a/apps/meteor/app/slashcommand-asciiarts/lib/lenny.ts +++ b/apps/meteor/app/slashcommand-asciiarts/lib/lenny.ts @@ -7,10 +7,10 @@ import { slashCommands } from '../../utils/lib/slashCommand'; * @param {Object} message - The message object */ -function LennyFace(_command: 'lennyface', params: string, item: RequiredField, 'rid'>): void { +async function LennyFace(_command: 'lennyface', params: string, item: RequiredField, 'rid'>): Promise { const msg = item; msg.msg = `${params} ( ͡° ͜ʖ ͡°)`; - Meteor.call('sendMessage', msg); + await Meteor.callAsync('sendMessage', msg); } slashCommands.add({ diff --git a/apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts b/apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts index 0e0d50860d7..15b118e1166 100644 --- a/apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts +++ b/apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts @@ -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 => { const msg = item; msg.msg = `${params} ¯\\\\_(ツ)_/¯`; - Meteor.call('sendMessage', msg); + await Meteor.callAsync('sendMessage', msg); }, options: { description: 'Slash_Shrug_Description', diff --git a/apps/meteor/app/slashcommand-asciiarts/lib/tableflip.ts b/apps/meteor/app/slashcommand-asciiarts/lib/tableflip.ts index 6bd3883a875..09136920702 100644 --- a/apps/meteor/app/slashcommand-asciiarts/lib/tableflip.ts +++ b/apps/meteor/app/slashcommand-asciiarts/lib/tableflip.ts @@ -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 => { const msg = item; msg.msg = `${params} (╯°□°)╯︵ ┻━┻`; - Meteor.call('sendMessage', msg); + await Meteor.callAsync('sendMessage', msg); }, options: { description: 'Slash_Tableflip_Description', diff --git a/apps/meteor/app/slashcommand-asciiarts/lib/unflip.ts b/apps/meteor/app/slashcommand-asciiarts/lib/unflip.ts index 2fbe8f75c2f..e9e9f7c5fe7 100644 --- a/apps/meteor/app/slashcommand-asciiarts/lib/unflip.ts +++ b/apps/meteor/app/slashcommand-asciiarts/lib/unflip.ts @@ -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 => { const msg = item; msg.msg = `${params} ┬─┬ ノ( ゜-゜ノ)`; - Meteor.call('sendMessage', msg); + await Meteor.callAsync('sendMessage', msg); }, options: { description: 'Slash_TableUnflip_Description', diff --git a/apps/meteor/app/slashcommands-archiveroom/server/server.ts b/apps/meteor/app/slashcommands-archiveroom/server/server.ts index ed07f22171b..fc4d1c2b021 100644 --- a/apps/meteor/app/slashcommands-archiveroom/server/server.ts +++ b/apps/meteor/app/slashcommands-archiveroom/server/server.ts @@ -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 { 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, { diff --git a/apps/meteor/app/slashcommands-create/server/server.ts b/apps/meteor/app/slashcommands-create/server/server.ts index 5203379373e..366e645372c 100644 --- a/apps/meteor/app/slashcommands-create/server/server.ts +++ b/apps/meteor/app/slashcommands-create/server/server.ts @@ -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 { 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', diff --git a/apps/meteor/app/slashcommands-hide/server/hide.ts b/apps/meteor/app/slashcommands-hide/server/hide.ts index 459d6c2e635..89ca9ffa892 100644 --- a/apps/meteor/app/slashcommands-hide/server/hide.ts +++ b/apps/meteor/app/slashcommands-hide/server/hide.ts @@ -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 => { 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 }), diff --git a/apps/meteor/app/slashcommands-invite/server/server.ts b/apps/meteor/app/slashcommands-invite/server/server.ts index c0f3eb2b456..110bd2da2be 100644 --- a/apps/meteor/app/slashcommands-invite/server/server.ts +++ b/apps/meteor/app/slashcommands-invite/server/server.ts @@ -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 => { 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', diff --git a/apps/meteor/app/slashcommands-inviteall/server/server.ts b/apps/meteor/app/slashcommands-inviteall/server/server.ts index a20f7bcaf85..faa30b75918 100644 --- a/apps/meteor/app/slashcommands-inviteall/server/server.ts +++ b/apps/meteor/app/slashcommands-inviteall/server/server.ts @@ -13,7 +13,7 @@ import { slashCommands } from '../../utils/lib/slashCommand'; import { settings } from '../../settings/server'; function inviteAll(type: T): SlashCommand['callback'] { - return function inviteAll(command: T, params: string, item): void { + return async function inviteAll(command: T, params: string, item): Promise { if (!/invite\-all-(to|from)/.test(command)) { return; } @@ -66,7 +66,7 @@ function inviteAll(type: T): SlashCommand['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(type: T): SlashCommand['callback'] { }), }); } else { - Meteor.call('addUsersToRoom', { + await Meteor.callAsync('addUsersToRoom', { rid: targetChannel._id, users, }); diff --git a/apps/meteor/app/slashcommands-join/server/server.ts b/apps/meteor/app/slashcommands-join/server/server.ts index b3e5aba1bdd..df7bb6ed027 100644 --- a/apps/meteor/app/slashcommands-join/server/server.ts +++ b/apps/meteor/app/slashcommands-join/server/server.ts @@ -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 => { 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', diff --git a/apps/meteor/app/slashcommands-kick/server/server.ts b/apps/meteor/app/slashcommands-kick/server/server.ts index 5ac1ae2463c..c3e72d20fc1 100644 --- a/apps/meteor/app/slashcommands-kick/server/server.ts +++ b/apps/meteor/app/slashcommands-kick/server/server.ts @@ -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 => { 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', diff --git a/apps/meteor/app/slashcommands-leave/server/leave.ts b/apps/meteor/app/slashcommands-leave/server/leave.ts index 9bfb15e39b7..2b09da5dc7f 100644 --- a/apps/meteor/app/slashcommands-leave/server/leave.ts +++ b/apps/meteor/app/slashcommands-leave/server/leave.ts @@ -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 { try { - Meteor.call('leaveRoom', item.rid); + await Meteor.callAsync('leaveRoom', item.rid); } catch ({ error }) { const userId = Meteor.userId() as string; if (typeof error !== 'string') { diff --git a/apps/meteor/app/slashcommands-me/server/me.ts b/apps/meteor/app/slashcommands-me/server/me.ts index 9f19e1616c3..af111f3ea59 100644 --- a/apps/meteor/app/slashcommands-me/server/me.ts +++ b/apps/meteor/app/slashcommands-me/server/me.ts @@ -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 { if (params.trim()) { const msg = item; msg.msg = `_${params}_`; - Meteor.call('sendMessage', msg); + await Meteor.callAsync('sendMessage', msg); } }, options: { diff --git a/apps/meteor/app/slashcommands-msg/server/server.ts b/apps/meteor/app/slashcommands-msg/server/server.ts index fe3e47ee127..fbfbf576102 100644 --- a/apps/meteor/app/slashcommands-msg/server/server.ts +++ b/apps/meteor/app/slashcommands-msg/server/server.ts @@ -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 { 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', diff --git a/apps/meteor/app/slashcommands-mute/server/mute.ts b/apps/meteor/app/slashcommands-mute/server/mute.ts index e212b833245..0ba235cb42c 100644 --- a/apps/meteor/app/slashcommands-mute/server/mute.ts +++ b/apps/meteor/app/slashcommands-mute/server/mute.ts @@ -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 { 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, }); diff --git a/apps/meteor/app/slashcommands-mute/server/unmute.ts b/apps/meteor/app/slashcommands-mute/server/unmute.ts index 5c96ff9d4f3..be04fb5ddf7 100644 --- a/apps/meteor/app/slashcommands-mute/server/unmute.ts +++ b/apps/meteor/app/slashcommands-mute/server/unmute.ts @@ -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 { 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, }); diff --git a/apps/meteor/app/slashcommands-status/server/status.ts b/apps/meteor/app/slashcommands-status/server/status.ts index 4144b1f16f0..f55c411e8be 100644 --- a/apps/meteor/app/slashcommands-status/server/status.ts +++ b/apps/meteor/app/slashcommands-status/server/status.ts @@ -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 { 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'; diff --git a/apps/meteor/app/slashcommands-unarchiveroom/server/server.ts b/apps/meteor/app/slashcommands-unarchiveroom/server/server.ts index a7fd6f76e97..23001811899 100644 --- a/apps/meteor/app/slashcommands-unarchiveroom/server/server.ts +++ b/apps/meteor/app/slashcommands-unarchiveroom/server/server.ts @@ -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 { 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, { diff --git a/apps/meteor/app/user-status/server/methods/setUserStatus.ts b/apps/meteor/app/user-status/server/methods/setUserStatus.ts index b63eb73edd7..1b891655663 100644 --- a/apps/meteor/app/user-status/server/methods/setUserStatus.ts +++ b/apps/meteor/app/user-status/server/methods/setUserStatus.ts @@ -26,7 +26,7 @@ Meteor.methods({ method: 'setUserStatus', }); } - Meteor.call('UserPresence:setDefaultStatus', statusType); + await Meteor.callAsync('UserPresence:setDefaultStatus', statusType); } if (statusText || statusText === '') { diff --git a/apps/meteor/ee/app/api-enterprise/server/canned-responses.ts b/apps/meteor/ee/app/api-enterprise/server/canned-responses.ts index 8c246a8ccb1..7a9a9d2095e 100644 --- a/apps/meteor/ee/app/api-enterprise/server/canned-responses.ts +++ b/apps/meteor/ee/app/api-enterprise/server/canned-responses.ts @@ -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(); }, }, diff --git a/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts b/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts index 0a2836612ae..75d3aa31b0d 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts @@ -57,7 +57,7 @@ export const removeBusinessHourByAgentIds = async (agentIds: string[], businessH }; export const resetDefaultBusinessHourIfNeeded = async (): Promise => { - Meteor.call('license:isEnterprise', async (err: any, isEnterprise: any) => { + await Meteor.callAsync('license:isEnterprise', async (err: any, isEnterprise: any) => { if (err) { throw err; } diff --git a/apps/meteor/ee/app/livechat-enterprise/server/hooks/resumeOnHold.ts b/apps/meteor/ee/app/livechat-enterprise/server/hooks/resumeOnHold.ts index ce52e3f7342..9bb92947b15 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/hooks/resumeOnHold.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/hooks/resumeOnHold.ts @@ -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;