Skip to content

Commit

Permalink
[IMPROVE] allow users to skip activeUsers to be ready (#14431)
Browse files Browse the repository at this point in the history
* allow users to skip activeUsers to be ready

* Update main.js

* Update app/ui-master/client/main.js

Co-Authored-By: ggazzo <guilhermegazzo@gmail.com>
  • Loading branch information
ggazzo committed May 8, 2019
1 parent f9881d8 commit 3967bce
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions app/ui-master/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 3967bce

Please sign in to comment.