From 3967bce8e501dcd4778e5db58a46f1234f48f61a Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 8 May 2019 18:02:04 -0300 Subject: [PATCH] [IMPROVE] allow users to skip activeUsers to be ready (#14431) * allow users to skip activeUsers to be ready * Update main.js * Update app/ui-master/client/main.js Co-Authored-By: ggazzo --- app/ui-master/client/main.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/ui-master/client/main.js b/app/ui-master/client/main.js index 644607d467bd..0371c0a84707 100644 --- a/app/ui-master/client/main.js +++ b/app/ui-master/client/main.js @@ -5,13 +5,14 @@ import { Match } from 'meteor/check'; import { Tracker } from 'meteor/tracker'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { t, getUserPreference } from '../../utils'; +import { getConfig } from '../../ui-utils/client/config'; import { Session } from 'meteor/session'; import { Template } from 'meteor/templating'; import { chatMessages } from '../../ui'; import { mainReady, Layout, iframeLogin, modal, popover, menu, fireGlobalEvent, RoomManager } from '../../ui-utils'; import { toolbarSearch } from '../../ui-sidenav'; import { settings } from '../../settings'; -import { CachedChatSubscription, Roles, ChatSubscription } from '../../models'; +import { CachedChatSubscription, Roles, ChatSubscription, Users } from '../../models'; import { CachedCollectionManager } from '../../ui-cached-collection'; import { hasRole } from '../../authorization'; import { tooltip } from '../../tooltip'; @@ -131,6 +132,8 @@ Template.main.onCreated(function() { tooltip.init(); }); + +const skipActiveUsersToBeReady = [getConfig('experimental'), getConfig('skipActiveUsersToBeReady')].includes('true'); Template.main.helpers({ removeSidenav() { return Layout.isEmbedded() && !/^\/admin/.test(FlowRouter.current().route.path); @@ -156,18 +159,26 @@ Template.main.helpers({ return iframeEnabled && iframeLogin.reactiveIframeUrl.get(); }, subsReady() { - const routerReady = FlowRouter.subsReady('userData', 'activeUsers'); + const subscriptions = ['userData']; + if (!skipActiveUsersToBeReady) { + subscriptions.push('activeUsers'); + } + const routerReady = FlowRouter.subsReady.apply(FlowRouter, subscriptions); + const subscriptionsReady = CachedChatSubscription.ready.get(); const settingsReady = settings.cachedCollection.ready.get(); - const ready = (Meteor.userId() == null) || (routerReady && subscriptionsReady && settingsReady); + + const ready = (routerReady && subscriptionsReady && settingsReady) || !Meteor.userId(); + CachedCollectionManager.syncEnabled = ready; - Meteor.defer(() => { - mainReady.set(ready); - }); + mainReady.set(ready); + return ready; }, hasUsername() { - return (Meteor.userId() != null && Meteor.user().username != null) || (Meteor.userId() == null && settings.get('Accounts_AllowAnonymousRead') === true); + const uid = Meteor.userId(); + const user = uid && Users.findOne({ _id: uid }, { fields: { username: 1 } }); + return (user && user.username) || settings.get('Accounts_AllowAnonymousRead'); }, requirePasswordChange() { const user = Meteor.user();