Skip to content

Commit

Permalink
open room
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Mar 24, 2020
1 parent 4293f38 commit 3b9b013
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/ui-flextab/client/tabs/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions app/ui-utils/client/lib/callMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
8 changes: 4 additions & 4 deletions app/ui-utils/client/lib/openRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '..';

Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 3b9b013

Please sign in to comment.