Skip to content

Commit

Permalink
Merge branch 'develop' into update-slack-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
casalsgh committed Oct 25, 2023
2 parents a8bb615 + 6c79953 commit 66e4db5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions apps/meteor/client/hooks/useLicense.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import type { Serialized } from '@rocket.chat/core-typings';
import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks';
import type { OperationResult } from '@rocket.chat/rest-typings';
import { useEndpoint, useSingleStream } from '@rocket.chat/ui-contexts';
import type { UseQueryResult } from '@tanstack/react-query';
import type { QueryClient, UseQueryResult } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';

type LicenseDataType = Awaited<OperationResult<'GET', '/v1/licenses.info'>>['license'];

const invalidateQueryClientLicenses = (() => {
let timeout: ReturnType<typeof setTimeout> | undefined;

return (queryClient: QueryClient) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = undefined;
queryClient.invalidateQueries(['licenses', 'getLicenses']);
}, 5000);
};
})();

export const useLicense = (): UseQueryResult<Serialized<LicenseDataType>> => {
const getLicenses = useEndpoint('GET', '/v1/licenses.info');

const queryClient = useQueryClient();

const invalidate = useDebouncedCallback(
() => {
queryClient.invalidateQueries(['licenses', 'getLicenses']);
},
5000,
[],
);

const notify = useSingleStream('notify-all');

useEffect(() => notify('license', () => invalidate()), [notify, invalidate]);
useEffect(() => notify('license', () => invalidateQueryClientLicenses(queryClient)), [notify, queryClient]);

return useQuery(['licenses', 'getLicenses'], () => getLicenses({}), {
staleTime: Infinity,
Expand Down
2 changes: 1 addition & 1 deletion ee/packages/license/src/v2/convertToV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const convertToV3 = (v2: ILicenseV2): ILicenseV3 => {
},
grantedModules: [
...new Set(
v2.modules
['hide-watermark', ...v2.modules]
.map((licenseModule) => (isBundle(licenseModule) ? getBundleModules(licenseModule) : [licenseModule]))
.reduce((prev, curr) => [...prev, ...curr], [])
.map((licenseModule) => ({ module: licenseModule as LicenseModule })),
Expand Down

0 comments on commit 66e4db5

Please sign in to comment.