Skip to content

Commit c0c8301

Browse files
authored
fix: show disabled status when Presence_broadcast_disabled is enabled (RocketChat#40051)
1 parent 9760d84 commit c0c8301

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

.changeset/long-years-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes user status indicator to show disabled state when presence broadcast is turned off
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { UserStatus } from '@rocket.chat/core-typings';
2+
3+
import { Presence } from './presence';
4+
5+
jest.mock('meteor/meteor', () => ({
6+
Meteor: {
7+
subscribe: jest.fn(),
8+
},
9+
}));
10+
11+
const mockGet = jest.fn();
12+
13+
jest.mock('../../app/utils/client/lib/SDKClient', () => ({
14+
sdk: {
15+
rest: {
16+
get: (...args: unknown[]) => mockGet(...args),
17+
},
18+
},
19+
}));
20+
21+
describe('Presence fallback status', () => {
22+
beforeEach(() => {
23+
jest.clearAllMocks();
24+
jest.useFakeTimers();
25+
Presence.store.clear();
26+
});
27+
28+
afterEach(() => {
29+
jest.useRealTimers();
30+
});
31+
32+
it('should use DISABLED as fallback when status is set to disabled', async () => {
33+
mockGet.mockResolvedValue({ users: [] });
34+
Presence.setStatus('disabled');
35+
36+
Presence.listen('user1', jest.fn());
37+
await jest.advanceTimersByTimeAsync(500);
38+
39+
expect(Presence.store.get('user1')?.status).toBe(UserStatus.DISABLED);
40+
});
41+
42+
it('should use OFFLINE as fallback when status is set to enabled', async () => {
43+
mockGet.mockResolvedValue({ users: [] });
44+
Presence.setStatus('enabled');
45+
46+
Presence.listen('user1', jest.fn());
47+
await jest.advanceTimersByTimeAsync(500);
48+
49+
expect(Presence.store.get('user1')?.status).toBe(UserStatus.OFFLINE);
50+
});
51+
});

apps/meteor/client/lib/presence.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const getPresence = ((): ((uid: UserPresence['_id']) => void) => {
7373

7474
const { users } = await sdk.rest.get('/v1/users.presence', params);
7575

76+
const fallbackStatus = status === 'disabled' ? UserStatus.DISABLED : UserStatus.OFFLINE;
77+
7678
users.forEach((user) => {
7779
if (!store.has(user._id)) {
7880
notify(user);
@@ -81,7 +83,7 @@ const getPresence = ((): ((uid: UserPresence['_id']) => void) => {
8183
});
8284

8385
currentUids.forEach((uid) => {
84-
notify({ _id: uid, status: UserStatus.OFFLINE });
86+
notify({ _id: uid, status: fallbackStatus });
8587
});
8688

8789
currentUids.clear();

apps/meteor/server/modules/listeners/listeners.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export class ListenersModule {
162162
return;
163163
}
164164

165+
if (settings.get('Presence_broadcast_disabled')) {
166+
return;
167+
}
168+
165169
notifications.notifyUserInThisInstance(_id, 'userData', {
166170
type: 'updated',
167171
id: _id,

0 commit comments

Comments
 (0)