Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Unnecessary meteor.defer on openRoom #14396

Merged
merged 1 commit into from
May 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
};