diff --git a/app/ui-flextab/client/tabs/userActions.js b/app/ui-flextab/client/tabs/userActions.js index 070d7ff6ea9f0..cc0bd80ecc3bd 100644 --- a/app/ui-flextab/client/tabs/userActions.js +++ b/app/ui-flextab/client/tabs/userActions.js @@ -101,7 +101,7 @@ export const getActions = ({ user, directActions, hideAdminControls }) => { icon: 'message', name: t('Conversation'), action: prevent(getUser, ({ username }) => - Meteor.call('createDirectMessage', username, success((result) => result.rid && FlowRouter.go('direct', { username }, FlowRouter.current().queryParams))), + Meteor.call('createDirectMessage', username, success((result) => result.rid && FlowRouter.go('direct', { rid: result.rid }, FlowRouter.current().queryParams))), ), condition() { return canDirectMessageTo(this.username, directActions); diff --git a/app/ui-utils/client/lib/callMethod.js b/app/ui-utils/client/lib/callMethod.js index 9b5f3e9d5afe5..390c1ea21bc89 100644 --- a/app/ui-utils/client/lib/callMethod.js +++ b/app/ui-utils/client/lib/callMethod.js @@ -17,3 +17,12 @@ export const call = (method, ...params) => new Promise((resolve, reject) => { return resolve(result); }); }); + +export const callMethod = (method, ...params) => new Promise((resolve, reject) => { + Meteor.call(method, ...params, (err, result) => { + if (err) { + return reject(err); + } + return resolve(result); + }); +}); diff --git a/app/ui-utils/client/lib/openRoom.js b/app/ui-utils/client/lib/openRoom.js index 60582d8561071..18d644323c83d 100644 --- a/app/ui-utils/client/lib/openRoom.js +++ b/app/ui-utils/client/lib/openRoom.js @@ -12,7 +12,7 @@ import { ChatSubscription, Rooms } from '../../../models'; import { settings } from '../../../settings'; import { callbacks } from '../../../callbacks'; import { roomTypes } from '../../../utils'; -import { call } from './callMethod'; +import { call, callMethod } from './callMethod'; import { RoomManager, fireGlobalEvent, RoomHistoryManager } from '..'; @@ -60,7 +60,7 @@ export const openRoom = async function(type, name) { } try { - const room = roomTypes.findRoom(type, name, user) || await call('getRoomByTypeAndName', type, name); + const room = roomTypes.findRoom(type, name, user) || await callMethod('getRoomByTypeAndName', type, name); if (RoomManager.open(type + name).ready() !== true) { if (settings.get('Accounts_AllowAnonymousRead')) { @@ -113,10 +113,10 @@ export const openRoom = async function(type, name) { return callbacks.run('enter-room', sub); } catch (error) { c.stop(); - if (type !== 'd') { + if (type === 'd') { const result = await call('createDirectMessage', ...name.split(', ')).then((result) => waitUntilRoomBeInserted(type, result.rid)).catch(() => {}); if (result) { - return FlowRouter.go('direct', { rid: result.rid }, FlowRouter.current().queryParams); + return FlowRouter.go('direct', { rid: result._id }, FlowRouter.current().queryParams); } } Session.set('roomNotFound', { type, name, error });