From 6fa087387733f6d03ff368f49a70049c1371fe3a Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Mon, 11 Nov 2024 15:17:03 -0300 Subject: [PATCH] refactor: Reduce responsibilities of `CachedCollectionsManager` (#33936) --- .../emoji-custom/client/lib/emojiCustom.ts | 10 +- .../models/client/models/CachedChatRoom.ts | 2 +- .../client/models/CachedChatSubscription.ts | 2 +- .../models/client/models/ChatPermissions.ts | 2 +- .../app/ui-cached-collection/client/index.ts | 2 - .../client/models/CachedCollectionManager.ts | 95 ------------------- apps/meteor/client/importPackages.ts | 1 - .../cachedCollections}/CachedCollection.ts | 65 +++++++------ .../CachedCollectionManager.ts | 22 +++++ .../client/lib/cachedCollections/index.ts | 2 + apps/meteor/client/lib/fetchFeatures.ts | 9 +- apps/meteor/client/lib/loggedIn.ts | 40 ++++++++ .../PrivateSettingsCachedCollection.ts | 2 +- .../PublicSettingsCachedCollection.ts | 2 +- apps/meteor/client/meteorOverrides/index.ts | 1 + .../meteorOverrides/unstoreLoginToken.ts | 9 ++ .../client/providers/TranslationProvider.tsx | 18 ++-- .../meteor/client/startup/incomingMessages.ts | 14 +-- .../notifications/konchatNotifications.ts | 7 +- apps/meteor/client/startup/roles.ts | 4 +- .../client/views/root/MainLayout/Preload.tsx | 2 - 21 files changed, 145 insertions(+), 166 deletions(-) delete mode 100644 apps/meteor/app/ui-cached-collection/client/index.ts delete mode 100644 apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts rename apps/meteor/{app/ui-cached-collection/client/models => client/lib/cachedCollections}/CachedCollection.ts (88%) create mode 100644 apps/meteor/client/lib/cachedCollections/CachedCollectionManager.ts create mode 100644 apps/meteor/client/lib/cachedCollections/index.ts create mode 100644 apps/meteor/client/lib/loggedIn.ts create mode 100644 apps/meteor/client/meteorOverrides/unstoreLoginToken.ts diff --git a/apps/meteor/app/emoji-custom/client/lib/emojiCustom.ts b/apps/meteor/app/emoji-custom/client/lib/emojiCustom.ts index 3f4b876f12a7..11b5359731b1 100644 --- a/apps/meteor/app/emoji-custom/client/lib/emojiCustom.ts +++ b/apps/meteor/app/emoji-custom/client/lib/emojiCustom.ts @@ -3,8 +3,8 @@ import { escapeRegExp } from '@rocket.chat/string-helpers'; import { Meteor } from 'meteor/meteor'; import { Session } from 'meteor/session'; +import { onLoggedIn } from '../../../../client/lib/loggedIn'; import { emoji, removeFromRecent, replaceEmojiInRecent } from '../../../emoji/client'; -import { CachedCollectionManager } from '../../../ui-cached-collection/client'; import { getURL } from '../../../utils/client'; import { sdk } from '../../../utils/client/lib/SDKClient'; @@ -144,8 +144,8 @@ emoji.packages.emojiCustom = { renderPicker: customRender, }; -Meteor.startup(() => - CachedCollectionManager.onLogin(async () => { +Meteor.startup(() => { + onLoggedIn(async () => { try { const { emojis: { update: emojis }, @@ -167,5 +167,5 @@ Meteor.startup(() => } catch (e) { console.error('Error getting custom emoji', e); } - }), -); + }); +}); diff --git a/apps/meteor/app/models/client/models/CachedChatRoom.ts b/apps/meteor/app/models/client/models/CachedChatRoom.ts index 248b68554583..0ebf3e64bcd4 100644 --- a/apps/meteor/app/models/client/models/CachedChatRoom.ts +++ b/apps/meteor/app/models/client/models/CachedChatRoom.ts @@ -1,7 +1,7 @@ import type { IOmnichannelRoom, IRoom, IRoomWithRetentionPolicy } from '@rocket.chat/core-typings'; import { DEFAULT_SLA_CONFIG, LivechatPriorityWeight } from '@rocket.chat/core-typings'; -import { CachedCollection } from '../../../ui-cached-collection/client/models/CachedCollection'; +import { CachedCollection } from '../../../../client/lib/cachedCollections/CachedCollection'; import { CachedChatSubscription } from './CachedChatSubscription'; class CachedChatRoom extends CachedCollection { diff --git a/apps/meteor/app/models/client/models/CachedChatSubscription.ts b/apps/meteor/app/models/client/models/CachedChatSubscription.ts index d17493e57f2e..171d3f0edda1 100644 --- a/apps/meteor/app/models/client/models/CachedChatSubscription.ts +++ b/apps/meteor/app/models/client/models/CachedChatSubscription.ts @@ -2,7 +2,7 @@ import type { IOmnichannelRoom, IRoomWithRetentionPolicy, ISubscription } from ' import { DEFAULT_SLA_CONFIG, LivechatPriorityWeight } from '@rocket.chat/core-typings'; import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts'; -import { CachedCollection } from '../../../ui-cached-collection/client/models/CachedCollection'; +import { CachedCollection } from '../../../../client/lib/cachedCollections/CachedCollection'; import { CachedChatRoom } from './CachedChatRoom'; declare module '@rocket.chat/core-typings' { diff --git a/apps/meteor/app/models/client/models/ChatPermissions.ts b/apps/meteor/app/models/client/models/ChatPermissions.ts index e836f58ebb2e..fcf6ccef0e83 100644 --- a/apps/meteor/app/models/client/models/ChatPermissions.ts +++ b/apps/meteor/app/models/client/models/ChatPermissions.ts @@ -1,6 +1,6 @@ import type { IPermission } from '@rocket.chat/core-typings'; -import { CachedCollection } from '../../../ui-cached-collection/client'; +import { CachedCollection } from '../../../../client/lib/cachedCollections'; export const AuthzCachedCollection = new CachedCollection({ name: 'permissions', diff --git a/apps/meteor/app/ui-cached-collection/client/index.ts b/apps/meteor/app/ui-cached-collection/client/index.ts deleted file mode 100644 index 45776cc4d22c..000000000000 --- a/apps/meteor/app/ui-cached-collection/client/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { CachedCollection } from './models/CachedCollection'; -export { CachedCollectionManager } from './models/CachedCollectionManager'; diff --git a/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts b/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts deleted file mode 100644 index b03115105841..000000000000 --- a/apps/meteor/app/ui-cached-collection/client/models/CachedCollectionManager.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { Emitter } from '@rocket.chat/emitter'; -import { Accounts } from 'meteor/accounts-base'; -import { check } from 'meteor/check'; -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; - -import type { CachedCollection } from './CachedCollection'; - -class CachedCollectionManager extends Emitter<{ reconnect: void; login: string | null }> { - private items: CachedCollection[]; - - private _syncEnabled: boolean; - - private logged: boolean; - - private step: number; - - constructor() { - super(); - this.items = []; - this._syncEnabled = false; - this.logged = false; - - const { _unstoreLoginToken } = Accounts; - Accounts._unstoreLoginToken = (...args) => { - _unstoreLoginToken.apply(Accounts, args); - this.clearAllCacheOnLogout(); - }; - - Tracker.autorun(() => { - const [WAITING_FIRST_CONNECTION, WAITING_FIRST_DISCONNECTION, LISTENING_RECONNECTIONS] = [0, 1, 2]; - this.step = this.step || WAITING_FIRST_CONNECTION; - const { connected } = Meteor.status(); - switch (this.step) { - case WAITING_FIRST_CONNECTION: - return !connected || this.step++; - case WAITING_FIRST_DISCONNECTION: - return connected || this.step++; - case LISTENING_RECONNECTIONS: - return connected && this.emit('reconnect'); - } - }); - - Accounts.onLogin(() => { - this.emit('login', Meteor.userId()); - }); - Tracker.autorun(() => { - const uid = Meteor.userId(); - this.logged = uid !== null; - }); - } - - register(cachedCollection: CachedCollection) { - this.items.push(cachedCollection); - } - - clearAllCache() { - for (const item of this.items) { - void item.clearCache(); - } - } - - clearAllCacheOnLogout() { - for (const item of this.items) { - item.clearCacheOnLogout(); - } - } - - set syncEnabled(value) { - check(value, Boolean); - this._syncEnabled = value; - } - - get syncEnabled() { - return this._syncEnabled; - } - - onReconnect(cb: () => void) { - this.on('reconnect', cb); - } - - onLogin(cb: () => void) { - this.on('login', cb); - if (this.logged) { - cb(); - } - } -} - -const instance = new CachedCollectionManager(); - -export { - /** @deprecated */ - instance as CachedCollectionManager, -}; diff --git a/apps/meteor/client/importPackages.ts b/apps/meteor/client/importPackages.ts index ddc173e63116..d0f89f407e6d 100644 --- a/apps/meteor/client/importPackages.ts +++ b/apps/meteor/client/importPackages.ts @@ -42,6 +42,5 @@ import '../app/utils/client'; import '../app/settings/client'; import '../app/models/client'; import '../app/ui-utils/client'; -import '../app/ui-cached-collection/client'; import '../app/reactions/client'; import '../app/livechat/client'; diff --git a/apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts b/apps/meteor/client/lib/cachedCollections/CachedCollection.ts similarity index 88% rename from apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts rename to apps/meteor/client/lib/cachedCollections/CachedCollection.ts index 10ea6d9453bb..a435c5768860 100644 --- a/apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts +++ b/apps/meteor/client/lib/cachedCollections/CachedCollection.ts @@ -1,17 +1,18 @@ import type { StreamNames } from '@rocket.chat/ddp-client'; -import { Emitter } from '@rocket.chat/emitter'; import localforage from 'localforage'; import { Accounts } from 'meteor/accounts-base'; import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { ReactiveVar } from 'meteor/reactive-var'; - -import type { MinimongoCollection } from '../../../../client/definitions/MinimongoCollection'; -import { baseURI } from '../../../../client/lib/baseURI'; -import { getConfig } from '../../../../client/lib/utils/getConfig'; -import { isTruthy } from '../../../../lib/isTruthy'; -import { withDebouncing } from '../../../../lib/utils/highOrderFunctions'; -import { sdk } from '../../../utils/client/lib/SDKClient'; +import { Tracker } from 'meteor/tracker'; + +import { sdk } from '../../../app/utils/client/lib/SDKClient'; +import { isTruthy } from '../../../lib/isTruthy'; +import { withDebouncing } from '../../../lib/utils/highOrderFunctions'; +import type { MinimongoCollection } from '../../definitions/MinimongoCollection'; +import { baseURI } from '../baseURI'; +import { onLoggedIn } from '../loggedIn'; +import { getConfig } from '../utils/getConfig'; import { CachedCollectionManager } from './CachedCollectionManager'; export type EventType = 'notify-logged' | 'notify-all' | 'notify-user'; @@ -35,34 +36,30 @@ const hasUnserializedUpdatedAt = (record: T): record is T & { _updatedAt: Con '_updatedAt' in record && !((record as unknown as { _updatedAt: unknown })._updatedAt instanceof Date); -localforage.config({ - name: baseURI, -}); +localforage.config({ name: baseURI }); -export class CachedCollection extends Emitter<{ changed: T; removed: T }> { +export class CachedCollection { private static MAX_CACHE_TIME = 60 * 60 * 24 * 30; public collection: MinimongoCollection; public ready = new ReactiveVar(false); - public name: Name; + protected name: Name; - public eventType: StreamNames; + protected eventType: StreamNames; - public version = 18; + protected version = 18; - public userRelated: boolean; + protected userRelated: boolean; - public updatedAt = new Date(0); + protected updatedAt = new Date(0); - public log: (...args: any[]) => void; + protected log: (...args: any[]) => void; - public timer: ReturnType; + private timer: ReturnType; constructor({ name, eventType = 'notify-user', userRelated = true }: { name: Name; eventType?: StreamNames; userRelated?: boolean }) { - super(); - this.collection = new Mongo.Collection(null) as MinimongoCollection; this.name = name; @@ -80,9 +77,14 @@ export class CachedCollection extends Emitter< return; } - CachedCollectionManager.onLogin(() => { + if (process.env.NODE_ENV === 'test') { + return; + } + + onLoggedIn(() => { void this.init(); }); + Accounts.onLogout(() => { this.ready.set(false); }); @@ -187,7 +189,6 @@ export class CachedCollection extends Emitter< const { _id } = newRecord; this.collection.upsert({ _id } as Mongo.Selector, newRecord); - this.emit('changed', newRecord as any); // TODO: investigate why this is needed if (hasUpdatedAt(newRecord) && newRecord._updatedAt > this.updatedAt) { this.updatedAt = newRecord._updatedAt; @@ -301,7 +302,6 @@ export class CachedCollection extends Emitter< if (actionTime > this.updatedAt) { this.updatedAt = actionTime; } - this.emit(action, newRecord as any); // TODO: investigate why this is needed }, timestamp: actionTime.getTime(), }); @@ -326,7 +326,6 @@ export class CachedCollection extends Emitter< if (actionTime > this.updatedAt) { this.updatedAt = actionTime; } - this.emit(action, newRecord as any); // TODO: investigate why this is needed }, timestamp: actionTime.getTime(), }); @@ -353,10 +352,22 @@ export class CachedCollection extends Emitter< this.ready.set(true); - CachedCollectionManager.onReconnect(() => { - this.trySync(); + this.reconnectionComputation?.stop(); + let wentOffline = Tracker.nonreactive(() => Meteor.status().status === 'offline'); + this.reconnectionComputation = Tracker.autorun(() => { + const { status } = Meteor.status(); + + if (status === 'offline') { + wentOffline = true; + } + + if (status === 'connected' && wentOffline) { + this.trySync(); + } }); return this.setupListener(); } + + private reconnectionComputation: Tracker.Computation | undefined; } diff --git a/apps/meteor/client/lib/cachedCollections/CachedCollectionManager.ts b/apps/meteor/client/lib/cachedCollections/CachedCollectionManager.ts new file mode 100644 index 000000000000..ca96af417930 --- /dev/null +++ b/apps/meteor/client/lib/cachedCollections/CachedCollectionManager.ts @@ -0,0 +1,22 @@ +import type { CachedCollection } from './CachedCollection'; + +class CachedCollectionManager { + private items = new Set>(); + + register(cachedCollection: CachedCollection) { + this.items.add(cachedCollection); + } + + clearAllCachesOnLogout() { + for (const item of this.items) { + item.clearCacheOnLogout(); + } + } +} + +const instance = new CachedCollectionManager(); + +export { + /** @deprecated */ + instance as CachedCollectionManager, +}; diff --git a/apps/meteor/client/lib/cachedCollections/index.ts b/apps/meteor/client/lib/cachedCollections/index.ts new file mode 100644 index 000000000000..fb99c0d3feea --- /dev/null +++ b/apps/meteor/client/lib/cachedCollections/index.ts @@ -0,0 +1,2 @@ +export { CachedCollection } from './CachedCollection'; +export { CachedCollectionManager } from './CachedCollectionManager'; diff --git a/apps/meteor/client/lib/fetchFeatures.ts b/apps/meteor/client/lib/fetchFeatures.ts index c481e8cf2f76..3814eda0f5dd 100644 --- a/apps/meteor/client/lib/fetchFeatures.ts +++ b/apps/meteor/client/lib/fetchFeatures.ts @@ -1,9 +1,4 @@ -import { CachedCollectionManager } from '../../app/ui-cached-collection/client'; import { sdk } from '../../app/utils/client/lib/SDKClient'; +import { whenLoggedIn } from './loggedIn'; -export const fetchFeatures = (): Promise => - new Promise((resolve, reject) => { - CachedCollectionManager.onLogin(() => { - sdk.call('license:getModules').then(resolve, reject); - }); - }); +export const fetchFeatures = (): Promise => whenLoggedIn().then(() => sdk.call('license:getModules')); diff --git a/apps/meteor/client/lib/loggedIn.ts b/apps/meteor/client/lib/loggedIn.ts new file mode 100644 index 000000000000..033727ed9836 --- /dev/null +++ b/apps/meteor/client/lib/loggedIn.ts @@ -0,0 +1,40 @@ +import { Accounts } from 'meteor/accounts-base'; +import { Meteor } from 'meteor/meteor'; +import { Tracker } from 'meteor/tracker'; + +const isLoggedIn = () => { + const uid = Tracker.nonreactive(() => Meteor.userId()); + return uid !== null; +}; + +export const whenLoggedIn = () => { + if (isLoggedIn()) { + return Promise.resolve(); + } + + return new Promise((resolve) => { + const subscription = Accounts.onLogin(() => { + subscription.stop(); + resolve(); + }); + }); +}; + +export const onLoggedIn = (cb: (() => () => void) | (() => Promise<() => void>) | (() => void)) => { + let cleanup: (() => void) | undefined; + const handler = async () => { + cleanup?.(); + const ret = await cb(); + if (typeof ret === 'function') { + cleanup = ret; + } + }; + + const subscription = Accounts.onLogin(handler); + if (isLoggedIn()) handler(); + + return () => { + subscription.stop(); + cleanup?.(); + }; +}; diff --git a/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts b/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts index 6f4e1c95a5fa..1b170c82e7d8 100644 --- a/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts +++ b/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts @@ -1,7 +1,7 @@ import type { ISetting } from '@rocket.chat/core-typings'; -import { CachedCollection } from '../../../app/ui-cached-collection/client'; import { sdk } from '../../../app/utils/client/lib/SDKClient'; +import { CachedCollection } from '../cachedCollections'; class PrivateSettingsCachedCollection extends CachedCollection { constructor() { diff --git a/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts b/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts index c01523252f85..6d01d13d9617 100644 --- a/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts +++ b/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts @@ -1,6 +1,6 @@ import type { ISetting } from '@rocket.chat/core-typings'; -import { CachedCollection } from '../../../app/ui-cached-collection/client'; +import { CachedCollection } from '../cachedCollections'; class PublicSettingsCachedCollection extends CachedCollection { constructor() { diff --git a/apps/meteor/client/meteorOverrides/index.ts b/apps/meteor/client/meteorOverrides/index.ts index b8e14d4138bd..baa6b2b06386 100644 --- a/apps/meteor/client/meteorOverrides/index.ts +++ b/apps/meteor/client/meteorOverrides/index.ts @@ -1,6 +1,7 @@ import './ddpOverREST'; import './totpOnCall'; import './oauthRedirectUri'; +import './unstoreLoginToken'; import './userAndUsers'; import './login/cas'; import './login/crowd'; diff --git a/apps/meteor/client/meteorOverrides/unstoreLoginToken.ts b/apps/meteor/client/meteorOverrides/unstoreLoginToken.ts new file mode 100644 index 000000000000..d1a6ffe9c9cd --- /dev/null +++ b/apps/meteor/client/meteorOverrides/unstoreLoginToken.ts @@ -0,0 +1,9 @@ +import { Accounts } from 'meteor/accounts-base'; + +import { CachedCollectionManager } from '../lib/cachedCollections'; + +const { _unstoreLoginToken } = Accounts; +Accounts._unstoreLoginToken = (...args) => { + _unstoreLoginToken.apply(Accounts, args); + CachedCollectionManager.clearAllCachesOnLogout(); +}; diff --git a/apps/meteor/client/providers/TranslationProvider.tsx b/apps/meteor/client/providers/TranslationProvider.tsx index 771e1d726204..b918c68d5787 100644 --- a/apps/meteor/client/providers/TranslationProvider.tsx +++ b/apps/meteor/client/providers/TranslationProvider.tsx @@ -11,7 +11,6 @@ import type { ReactElement, ReactNode } from 'react'; import React, { useEffect, useMemo } from 'react'; import { I18nextProvider, initReactI18next, useTranslation } from 'react-i18next'; -import { CachedCollectionManager } from '../../app/ui-cached-collection/client'; import { getURL } from '../../app/utils/client'; import { i18n, @@ -23,6 +22,7 @@ import { extractTranslationNamespaces, } from '../../app/utils/lib/i18n'; import { AppClientOrchestratorInstance } from '../apps/orchestrator'; +import { onLoggedIn } from '../lib/loggedIn'; import { isRTLScriptLanguage } from '../lib/utils/isRTLScriptLanguage'; i18n.use(I18NextHttpBackend).use(initReactI18next); @@ -198,14 +198,14 @@ const TranslationProvider = ({ children }: TranslationProviderProps): ReactEleme }); }, [language, loadLocale, availableLanguages]); - useEffect(() => { - const cb = () => { - AppClientOrchestratorInstance.getAppClientManager().initialize(); - AppClientOrchestratorInstance.load(); - }; - CachedCollectionManager.onLogin(cb); - return () => CachedCollectionManager.off('login', cb); - }, []); + useEffect( + () => + onLoggedIn(() => { + AppClientOrchestratorInstance.getAppClientManager().initialize(); + AppClientOrchestratorInstance.load(); + }), + [], + ); return ( diff --git a/apps/meteor/client/startup/incomingMessages.ts b/apps/meteor/client/startup/incomingMessages.ts index e9659cc24724..941887174985 100644 --- a/apps/meteor/client/startup/incomingMessages.ts +++ b/apps/meteor/client/startup/incomingMessages.ts @@ -2,18 +2,14 @@ import type { IMessage } from '@rocket.chat/core-typings'; import { Meteor } from 'meteor/meteor'; import { ChatMessage } from '../../app/models/client'; -import { CachedCollectionManager } from '../../app/ui-cached-collection/client'; import { sdk } from '../../app/utils/client/lib/SDKClient'; +import { onLoggedIn } from '../lib/loggedIn'; Meteor.startup(() => { - Tracker.autorun(() => { - if (!Meteor.userId()) { - return; - } - + onLoggedIn(() => { // Only event I found triggers this is from ephemeral messages // Other types of messages come from another stream - sdk.stream('notify-user', [`${Meteor.userId()}/message`], (msg: IMessage) => { + return sdk.stream('notify-user', [`${Meteor.userId()}/message`], (msg: IMessage) => { msg.u = msg.u || { username: 'rocket.cat' }; msg.private = true; @@ -21,8 +17,8 @@ Meteor.startup(() => { }); }); - CachedCollectionManager.onLogin(() => { - sdk.stream('notify-user', [`${Meteor.userId()}/subscriptions-changed`], (_action, sub) => { + onLoggedIn(() => { + return sdk.stream('notify-user', [`${Meteor.userId()}/subscriptions-changed`], (_action, sub) => { ChatMessage.update( { rid: sub.rid, diff --git a/apps/meteor/client/startup/notifications/konchatNotifications.ts b/apps/meteor/client/startup/notifications/konchatNotifications.ts index 3d5f26cae547..b3c451bfeb58 100644 --- a/apps/meteor/client/startup/notifications/konchatNotifications.ts +++ b/apps/meteor/client/startup/notifications/konchatNotifications.ts @@ -69,6 +69,7 @@ Meteor.startup(() => { }); }; }; + Tracker.autorun(() => { if (!Meteor.userId() || !settings.get('Outlook_Calendar_Enabled')) { sdk.stop('notify-user', `${Meteor.userId()}/calendar`); @@ -109,8 +110,10 @@ Meteor.startup(() => { notifyNewMessageAudio(notification.payload.rid); }); - CachedChatSubscription.on('changed', (sub): void => { - void notifyNewRoom(sub); + CachedChatSubscription.collection.find().observe({ + changed: (sub) => { + void notifyNewRoom(sub); + }, }); sdk.stream('notify-user', [`${Meteor.userId()}/subscriptions-changed`], (action, sub) => { diff --git a/apps/meteor/client/startup/roles.ts b/apps/meteor/client/startup/roles.ts index 4c54682ecded..ebccaa8d81b3 100644 --- a/apps/meteor/client/startup/roles.ts +++ b/apps/meteor/client/startup/roles.ts @@ -3,11 +3,11 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; import { Roles } from '../../app/models/client'; -import { CachedCollectionManager } from '../../app/ui-cached-collection/client'; import { sdk } from '../../app/utils/client/lib/SDKClient'; +import { onLoggedIn } from '../lib/loggedIn'; Meteor.startup(() => { - CachedCollectionManager.onLogin(async () => { + onLoggedIn(async () => { const { roles } = await sdk.rest.get('/v1/roles.list'); // if a role is checked before this collection is populated, it will return undefined Roles._collection._docs._map = new Map(roles.map((record) => [Roles._collection._docs._idStringify(record._id), record])); diff --git a/apps/meteor/client/views/root/MainLayout/Preload.tsx b/apps/meteor/client/views/root/MainLayout/Preload.tsx index cd5ba0e817db..c1e233d8a8cc 100644 --- a/apps/meteor/client/views/root/MainLayout/Preload.tsx +++ b/apps/meteor/client/views/root/MainLayout/Preload.tsx @@ -4,7 +4,6 @@ import React, { useEffect } from 'react'; import { CachedChatSubscription } from '../../../../app/models/client'; import { settings } from '../../../../app/settings/client'; -import { CachedCollectionManager } from '../../../../app/ui-cached-collection/client'; import { mainReady } from '../../../../app/ui-utils/client'; import { useReactiveVar } from '../../../hooks/useReactiveVar'; import { isSyncReady } from '../../../lib/userData'; @@ -19,7 +18,6 @@ const Preload = ({ children }: { children: ReactNode }): ReactElement => { const ready = !uid || (userDataReady && subscriptionsReady && settingsReady); useEffect(() => { - CachedCollectionManager.syncEnabled = ready; mainReady.set(ready); }, [ready]);