Room loading improvements (#13471)

pull/13455/head
Rodrigo Nascimento 7 years ago committed by GitHub
parent 959c2dbb72
commit dfa4936fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      packages/rocketchat-lib/client/lib/openRoom.js
  2. 6
      packages/rocketchat-models/client/models/Users.js

@ -1,6 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { Session } from 'meteor/session';
import { RoomManager, fireGlobalEvent, readMessage, RoomHistoryManager } from 'meteor/rocketchat:ui-utils';
@ -9,6 +11,33 @@ import _ from 'underscore';
export let currentTracker = undefined;
let loadingDom;
function getDomOfLoading() {
if (loadingDom) {
return loadingDom;
}
loadingDom = document.createElement('div');
const contentAsFunc = (content) => () => content;
const template = Blaze._TemplateWith({ }, contentAsFunc(Template.loading));
Blaze.render(template, loadingDom);
return loadingDom;
}
function replaceCenterDomBy(dom) {
const mainNode = document.querySelector('.main-content');
if (mainNode) {
for (const child of Array.from(mainNode.children)) {
if (child) { mainNode.removeChild(child); }
}
mainNode.appendChild(dom);
}
return mainNode;
}
openRoom = function(type, name) {
Session.set('openedRoom', null);
@ -21,12 +50,10 @@ openRoom = function(type, name) {
}
if (RoomManager.open(type + name).ready() !== true) {
BlazeLayout.render('main', { modal: RocketChat.Layout.isEmbedded(), center: 'loading' });
replaceCenterDomBy(getDomOfLoading());
return;
}
BlazeLayout.render('main');
if (currentTracker) {
currentTracker = undefined;
}
@ -60,13 +87,10 @@ openRoom = function(type, name) {
return;
}
const mainNode = document.querySelector('.main-content');
const roomDom = RoomManager.getDomOfRoom(type + name, room._id);
const mainNode = replaceCenterDomBy(roomDom);
if (mainNode) {
for (const child of Array.from(mainNode.children)) {
if (child) { mainNode.removeChild(child); }
}
const roomDom = RoomManager.getDomOfRoom(type + name, room._id);
mainNode.appendChild(roomDom);
if (roomDom.classList.contains('room-container')) {
roomDom.querySelector('.messages-box > .wrapper').scrollTop = roomDom.oldScrollTop;
}

@ -1,15 +1,13 @@
import _ from 'underscore';
const Users = {};
Object.assign(Users, {
isUserInRole(userId, roleName) {
const query = {
_id: userId,
roles: roleName,
};
return !_.isUndefined(this.findOne(query, { fields: { roles: 1 } }));
const user = this.findOne(query);
return user && Array.isArray(user.roles) && user.roles.includes(roleName);
},
findUsersInRoles(roles, scope, options) {

Loading…
Cancel
Save