Skip to content

Commit 89a59b8

Browse files
authored
refactor(client): drop the Settings.watch method (RocketChat#40495)
1 parent 9eb2780 commit 89a59b8

6 files changed

Lines changed: 7 additions & 13 deletions

File tree

apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ export const formattingButtons: ReadonlyArray<FormattingButton> = [
101101
}
102102
},
103103
link: 'https://khan.github.io/KaTeX/function-support.html',
104-
condition: () => settings.watch('Katex_Enabled') ?? true,
104+
condition: () => settings.peek('Katex_Enabled') ?? true,
105105
},
106106
] as const;

apps/meteor/app/utils/client/getRoomAvatarURL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getAvatarURL } from './getAvatarURL';
44
import { settings } from '../../../client/lib/settings';
55

66
export const getRoomAvatarURL = ({ roomId, cache = '' }: { roomId: IRoom['_id']; cache: IRoom['avatarETag'] }) => {
7-
const externalSource = (settings.watch('Accounts_RoomAvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
7+
const externalSource = (settings.peek('Accounts_RoomAvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
88
if (externalSource && typeof externalSource === 'string') {
99
return externalSource.replace('{roomId}', roomId);
1010
}

apps/meteor/app/utils/client/getURL.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const getURL = function (
1414
cloudDeepLinkUrl?: string,
1515
cacheKey?: boolean,
1616
): string {
17-
const cdnPrefix = settings.watch('CDN_PREFIX') || '';
18-
const siteUrl = settings.watch('Site_Url') || '';
17+
const cdnPrefix = settings.peek('CDN_PREFIX') || '';
18+
const siteUrl = settings.peek('Site_Url') || '';
1919

2020
if (cacheKey) {
2121
path += `${path.includes('?') ? '&' : '?'}cacheKey=${Info.version}`;

apps/meteor/app/utils/client/lib/getUserPreference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export function getUserPreference<TValue>(
4343
defaultValue?: TValue,
4444
): TValue {
4545
const user = typeof userIdOrUser === 'string' ? Users.state.get(userIdOrUser) : userIdOrUser;
46-
return user?.settings?.preferences?.[key] ?? defaultValue ?? settings.watch(`Accounts_Default_User_Preferences_${key}`);
46+
return user?.settings?.preferences?.[key] ?? defaultValue ?? settings.peek(`Accounts_Default_User_Preferences_${key}`);
4747
}

apps/meteor/app/utils/client/restrictions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { settings } from '../../../client/lib/settings';
22
import { fileUploadIsValidContentTypeFromSettings } from '../lib/restrictions';
33

44
export const fileUploadIsValidContentType = function (type: string | undefined, customWhiteList?: string): boolean {
5-
const blackList = settings.watch<string>('FileUpload_MediaTypeBlackList') ?? 'image/svg+xml';
6-
const whiteList = customWhiteList ?? settings.watch<string>('FileUpload_MediaTypeWhiteList') ?? '';
5+
const blackList = settings.peek<string>('FileUpload_MediaTypeBlackList') ?? 'image/svg+xml';
6+
const whiteList = customWhiteList ?? settings.peek<string>('FileUpload_MediaTypeWhiteList') ?? '';
77

88
return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList);
99
};

apps/meteor/client/lib/settings/settings.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import type { SettingValue } from '@rocket.chat/core-typings';
22

3-
import { watch } from '../../meteor/watch';
43
import { PublicSettings } from '../../stores';
54

65
type SettingCallback = (key: string, value: SettingValue) => void;
76

87
class Settings {
98
private readonly store = PublicSettings.use;
109

11-
/** Get a setting value Tracker-reactively */
12-
watch<TValue = any>(_id: string): TValue | undefined {
13-
return watch(this.store, (state) => state.get(_id)?.value) as TValue | undefined;
14-
}
15-
1610
/** Get a setting value non-reactively */
1711
peek<TValue = any>(_id: string): TValue | undefined {
1812
return this.store.getState().get(_id)?.value as TValue | undefined;

0 commit comments

Comments
 (0)