Skip to content

Commit

Permalink
[FIX] Unnecessary meteor.defer on openRoom (#14396)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored and rodrigok committed May 9, 2019
1 parent 43e4eb1 commit 3d64d98
Showing 1 changed file with 71 additions and 75 deletions.
146 changes: 71 additions & 75 deletions app/ui-utils/client/lib/openRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,87 +42,83 @@ function replaceCenterDomBy(dom) {
}

export const openRoom = function(type, name) {
Session.set('openedRoom', null);

return Meteor.defer(() =>
window.currentTracker = Tracker.autorun(function(c) {
const user = Meteor.user();
if ((user && user.username == null) || (user == null && settings.get('Accounts_AllowAnonymousRead') === false)) {
BlazeLayout.render('main');
return;
}
window.currentTracker = Tracker.autorun(function(c) {
const user = Meteor.user();
if ((user && user.username == null) || (user == null && settings.get('Accounts_AllowAnonymousRead') === false)) {
BlazeLayout.render('main');
return;
}

if (RoomManager.open(type + name).ready() !== true) {
replaceCenterDomBy(getDomOfLoading());
return;
}
if (window.currentTracker) {
window.currentTracker = undefined;
}
c.stop();

const room = roomTypes.findRoom(type, name, user);
if (room == null) {
if (type === 'd') {
Meteor.call('createDirectMessage', name, function(error) {
if (!error) {
RoomManager.close(type + name);
return openRoom('d', name);
} else {
Session.set('roomNotFound', { type, name, error });
BlazeLayout.render('main', { center: 'roomNotFound' });
return;
}
});
} else {
Meteor.call('getRoomByTypeAndName', type, name, function(error, record) {
if (error) {
Session.set('roomNotFound', { type, name, error });
return BlazeLayout.render('main', { center: 'roomNotFound' });
} else {
Rooms.upsert({ _id: record._id }, _.omit(record, '_id'));
RoomManager.close(type + name);
return openRoom(type, name);
}
});
}
return;
if (RoomManager.open(type + name).ready() !== true) {
replaceCenterDomBy(getDomOfLoading());
return;
}
if (window.currentTracker) {
window.currentTracker = undefined;
}
c.stop();

const room = roomTypes.findRoom(type, name, user);
if (room == null) {
if (type === 'd') {
Meteor.call('createDirectMessage', name, function(error) {
if (!error) {
RoomManager.close(type + name);
return openRoom('d', name);
} else {
Session.set('roomNotFound', { type, name, error });
BlazeLayout.render('main', { center: 'roomNotFound' });
return;
}
});
} else {
Meteor.call('getRoomByTypeAndName', type, name, function(error, record) {
if (error) {
Session.set('roomNotFound', { type, name, error });
return BlazeLayout.render('main', { center: 'roomNotFound' });
} else {
Rooms.upsert({ _id: record._id }, _.omit(record, '_id'));
RoomManager.close(type + name);
return openRoom(type, name);
}
});
}
return;
}

const roomDom = RoomManager.getDomOfRoom(type + name, room._id);
const mainNode = replaceCenterDomBy(roomDom);
const roomDom = RoomManager.getDomOfRoom(type + name, room._id);
const mainNode = replaceCenterDomBy(roomDom);

if (mainNode) {
if (roomDom.classList.contains('room-container')) {
roomDom.querySelector('.messages-box > .wrapper').scrollTop = roomDom.oldScrollTop;
}
if (mainNode) {
if (roomDom.classList.contains('room-container')) {
roomDom.querySelector('.messages-box > .wrapper').scrollTop = roomDom.oldScrollTop;
}
}

Session.set('openedRoom', room._id);
RoomManager.openedRoom = room._id;

fireGlobalEvent('room-opened', _.omit(room, 'usernames'));

Session.set('editRoomTitle', false);
RoomManager.updateMentionsMarksOfRoom(type + name);
Meteor.setTimeout(() => readMessage.readNow(), 2000);
// KonchatNotification.removeRoomNotification(params._id)
// update user's room subscription
const sub = ChatSubscription.findOne({ rid: room._id });
if (sub && sub.open === false) {
Meteor.call('openRoom', room._id, function(err) {
if (err) {
return handleError(err);
}
});
}
Session.set('openedRoom', room._id);
RoomManager.openedRoom = room._id;

fireGlobalEvent('room-opened', _.omit(room, 'usernames'));

Session.set('editRoomTitle', false);
RoomManager.updateMentionsMarksOfRoom(type + name);
Meteor.setTimeout(() => readMessage.readNow(), 2000);
// KonchatNotification.removeRoomNotification(params._id)
// update user's room subscription
const sub = ChatSubscription.findOne({ rid: room._id });
if (sub && sub.open === false) {
Meteor.call('openRoom', room._id, function(err) {
if (err) {
return handleError(err);
}
});
}

if (FlowRouter.getQueryParam('msg')) {
const msg = { _id: FlowRouter.getQueryParam('msg'), rid: room._id };
RoomHistoryManager.getSurroundingMessages(msg);
}
if (FlowRouter.getQueryParam('msg')) {
const msg = { _id: FlowRouter.getQueryParam('msg'), rid: room._id };
RoomHistoryManager.getSurroundingMessages(msg);
}

return callbacks.run('enter-room', sub);
})
);
return callbacks.run('enter-room', sub);
});
};

0 comments on commit 3d64d98

Please sign in to comment.