@@ -6,7 +6,7 @@ import type { FindOptions, SubscriptionWithRoom } from '@rocket.chat/ui-contexts
66import { UserContext , useRouteParameter , useSearchParameter } from '@rocket.chat/ui-contexts' ;
77import { useQueryClient } from '@tanstack/react-query' ;
88import { Meteor } from 'meteor/meteor' ;
9- import type { Filter } from 'mongodb' ;
9+ import type { Filter , ObjectId } from 'mongodb' ;
1010import type { ContextType , ReactElement , ReactNode } from 'react' ;
1111import { useEffect , useMemo , useRef } from 'react' ;
1212import type { StoreApi , UseBoundStore } from 'zustand' ;
@@ -16,13 +16,12 @@ import { useDeleteUser } from './hooks/useDeleteUser';
1616import { useEmailVerificationWarning } from './hooks/useEmailVerificationWarning' ;
1717import { useReloadAfterLogin } from './hooks/useReloadAfterLogin' ;
1818import { useUpdateAvatar } from './hooks/useUpdateAvatar' ;
19- import { getUserPreference } from '../../../app/utils/client' ;
2019import { sdk } from '../../../app/utils/client/lib/SDKClient' ;
2120import { useIdleConnection } from '../../hooks/useIdleConnection' ;
2221import type { IDocumentMapStore } from '../../lib/cachedStores/DocumentMapStore' ;
2322import { applyQueryOptions } from '../../lib/cachedStores/applyQueryOptions' ;
24- import { createReactiveSubscriptionFactory } from '../../lib/createReactiveSubscriptionFactory' ;
2523import { getDdpSdk } from '../../lib/sdk/ddpSdk' ;
24+ import { settings } from '../../lib/settings' ;
2625import { userIdStore } from '../../lib/user' ;
2726import { Users , Rooms , Subscriptions } from '../../stores' ;
2827import { useSamlInviteToken } from '../../views/invite/hooks/useSamlInviteToken' ;
@@ -138,9 +137,30 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {
138137 ( ) : ContextType < typeof UserContext > => ( {
139138 userId,
140139 user,
141- queryPreference : createReactiveSubscriptionFactory (
142- < T , > ( key : string , defaultValue ?: T ) => getUserPreference ( userId , key , defaultValue ) as T ,
143- ) ,
140+ queryPreference : < T , > (
141+ key : string | ObjectId ,
142+ defaultValue ?: T ,
143+ ) : [ subscribe : ( onStoreChange : ( ) => void ) => ( ) => void , getSnapshot : ( ) => T | undefined ] => {
144+ const effectiveKey = String ( key ) ;
145+
146+ const subscribe = ( onStoreChange : ( ) => void ) : ( ( ) => void ) => {
147+ const unsubUsers = Users . use . subscribe ( onStoreChange ) ;
148+ const unsubSettings = settings . observe ( `Accounts_Default_User_Preferences_${ effectiveKey } ` , onStoreChange ) ;
149+ return ( ) => {
150+ unsubUsers ( ) ;
151+ unsubSettings ( ) ;
152+ } ;
153+ } ;
154+
155+ const getSnapshot = ( ) : T | undefined => {
156+ return (
157+ ( user ?. settings ?. preferences ?. [ effectiveKey ] as T | undefined ) ??
158+ defaultValue ??
159+ settings . peek ( `Accounts_Default_User_Preferences_${ effectiveKey } ` )
160+ ) ;
161+ } ;
162+ return [ subscribe , getSnapshot ] ;
163+ } ,
144164 querySubscription,
145165 queryRoom,
146166 querySubscriptions,
0 commit comments