From e69a3d1dbfbc6d5e4659d8603aab86f99e3e92a0 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Tue, 21 Jan 2025 15:57:14 -0300 Subject: [PATCH 1/2] refactor: remove nexcloud meteor startup & tracker --- apps/meteor/app/nextcloud/client/lib.ts | 27 +++++++++------------ apps/meteor/client/views/root/AppLayout.tsx | 3 +++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/meteor/app/nextcloud/client/lib.ts b/apps/meteor/app/nextcloud/client/lib.ts index fb7f5391bc3a9..85e1be7aa873c 100644 --- a/apps/meteor/app/nextcloud/client/lib.ts +++ b/apps/meteor/app/nextcloud/client/lib.ts @@ -1,6 +1,8 @@ import type { OauthConfig } from '@rocket.chat/core-typings'; +import { useSetting } from '@rocket.chat/ui-contexts'; import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; +import { useEffect } from 'react'; import _ from 'underscore'; import { CustomOAuth } from '../../custom-oauth/client/CustomOAuth'; @@ -21,20 +23,13 @@ const config: OauthConfig = { const Nextcloud = new CustomOAuth('nextcloud', config); -const fillServerURL = _.debounce((): void => { - const nextcloudURL = settings.get('Accounts_OAuth_Nextcloud_URL'); - if (!nextcloudURL) { - if (nextcloudURL === undefined) { - return fillServerURL(); - } - return; - } - config.serverURL = nextcloudURL.trim().replace(/\/*$/, ''); - return Nextcloud.configure(config); -}, 100); +export const useNextcloud = (): void => { + const nextcloudURL = useSetting('Accounts_OAuth_Nextcloud_URL') as string; -Meteor.startup(() => { - Tracker.autorun(() => { - return fillServerURL(); - }); -}); + useEffect(() => { + if (nextcloudURL) { + config.serverURL = nextcloudURL.trim().replace(/\/*$/, ''); + Nextcloud.configure(config); + } + }, [nextcloudURL]); +}; diff --git a/apps/meteor/client/views/root/AppLayout.tsx b/apps/meteor/client/views/root/AppLayout.tsx index 8a4485ceef7b3..789cff5083a7f 100644 --- a/apps/meteor/client/views/root/AppLayout.tsx +++ b/apps/meteor/client/views/root/AppLayout.tsx @@ -7,6 +7,7 @@ import { useEscapeKeyStroke } from './hooks/useEscapeKeyStroke'; import { useGoogleTagManager } from './hooks/useGoogleTagManager'; import { useMessageLinkClicks } from './hooks/useMessageLinkClicks'; import { useAnalytics } from '../../../app/analytics/client/loadScript'; +import { useNextcloud } from '../../../app/nextcloud/client/lib'; import { useAnalyticsEventTracking } from '../../hooks/useAnalyticsEventTracking'; import { useLoadRoomForAllowedAnonymousRead } from '../../hooks/useLoadRoomForAllowedAnonymousRead'; import { useNotifyUser } from '../../hooks/useNotifyUser'; @@ -29,6 +30,8 @@ const AppLayout = () => { useLoadRoomForAllowedAnonymousRead(); useNotifyUser(); + useNextcloud(); + const layout = useSyncExternalStore(appLayout.subscribe, appLayout.getSnapshot); return ( From 8118706dfe7b94f6431c5bd6ad4d18ba585915db Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Tue, 21 Jan 2025 16:17:34 -0300 Subject: [PATCH 2/2] fix: imports --- apps/meteor/app/nextcloud/client/lib.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/meteor/app/nextcloud/client/lib.ts b/apps/meteor/app/nextcloud/client/lib.ts index 85e1be7aa873c..22151c7ff8c29 100644 --- a/apps/meteor/app/nextcloud/client/lib.ts +++ b/apps/meteor/app/nextcloud/client/lib.ts @@ -1,12 +1,8 @@ import type { OauthConfig } from '@rocket.chat/core-typings'; import { useSetting } from '@rocket.chat/ui-contexts'; -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; import { useEffect } from 'react'; -import _ from 'underscore'; import { CustomOAuth } from '../../custom-oauth/client/CustomOAuth'; -import { settings } from '../../settings/client'; const config: OauthConfig = { serverURL: '',