11import { setTimeout , clearTimeout } from 'node:timers' ;
22
33import type { IPresence , IBrokerNode } from '@rocket.chat/core-services' ;
4- import { License , ServiceClass , Settings , StatusVisibility } from '@rocket.chat/core-services' ;
4+ import { License , ServiceClass , Settings } from '@rocket.chat/core-services' ;
55import type { IUser } from '@rocket.chat/core-typings' ;
66import { UserStatus } from '@rocket.chat/core-typings' ;
77import { cronJobs } from '@rocket.chat/cron' ;
88import { Logger } from '@rocket.chat/logger' ;
99import { Users , UsersSessions } from '@rocket.chat/models' ;
1010
1111import { PresenceReaper } from './lib/PresenceReaper' ;
12+ import { STATUS_VISIBILITY_SETTING_ID , StatusVisibilityGate } from './lib/StatusVisibilityGate' ;
1213import { normalizeStatusText } from './lib/normalizeStatusText' ;
1314import { type ClaimUpdate , processPresence } from './lib/presenceEngine' ;
1415
@@ -38,7 +39,7 @@ export class Presence extends ServiceClass implements IPresence {
3839
3940 private broadcastEnabled = true ;
4041
41- private statusVisibilityEnabled = false ;
42+ private statusVisibility = new StatusVisibilityGate ( ) ;
4243
4344 private hasPresenceLicense = false ;
4445
@@ -65,8 +66,8 @@ export class Presence extends ServiceClass implements IPresence {
6566 onUpdate : ( userIds ) => this . handleReaperUpdates ( userIds ) ,
6667 } ) ;
6768
68- this . onSettingChanged ( 'Accounts_StatusVisibility_Enabled' , async ( { setting } ) : Promise < void > => {
69- this . statusVisibilityEnabled = setting . value === true ;
69+ this . onSettingChanged ( STATUS_VISIBILITY_SETTING_ID , async ( { setting } ) : Promise < void > => {
70+ this . statusVisibility . setEnabled ( setting . value ) ;
7071 } ) ;
7172
7273 this . onEvent ( 'watch.instanceStatus' , async ( { clientAction, id, diff } ) : Promise < void > => {
@@ -123,7 +124,7 @@ export class Presence extends ServiceClass implements IPresence {
123124 try {
124125 await Settings . set ( 'Presence_broadcast_disabled' , false ) ;
125126
126- this . statusVisibilityEnabled = ( await Settings . get < boolean > ( 'Accounts_StatusVisibility_Enabled' ) ) === true ;
127+ await this . statusVisibility . start ( ) ;
127128 this . hasScalabilityLicense = await License . hasModule ( 'scalability' ) ;
128129 this . hasPresenceLicense = await License . hasModule ( 'unlimited-presence' ) ;
129130 this . hasLicense = this . hasPresenceLicense || this . hasScalabilityLicense ;
@@ -428,16 +429,14 @@ export class Presence extends ServiceClass implements IPresence {
428429 return ;
429430 }
430431
431- if ( this . statusVisibilityEnabled ) {
432- void StatusVisibility . hasRestrictions ( user . _id )
433- . catch ( ( ) => true )
434- . then ( ( hasVisibilityRestrictions ) =>
435- this . api ?. broadcast ( 'presence.status' , {
436- user,
437- previousStatus,
438- hasVisibilityRestrictions,
439- } ) ,
440- ) ;
432+ if ( this . statusVisibility . isEnabled ( ) ) {
433+ void this . statusVisibility . hasRestrictions ( user . _id ) . then ( ( hasVisibilityRestrictions ) =>
434+ this . api ?. broadcast ( 'presence.status' , {
435+ user,
436+ previousStatus,
437+ hasVisibilityRestrictions,
438+ } ) ,
439+ ) ;
441440
442441 return ;
443442 }
0 commit comments