Skip to content

Commit de8a406

Browse files
committed
refactor(presence): route stream-user-presence subscribe through DDPSDK when ready
The stream-user-presence 'subscription' is used as a fire-and-forget command channel: each call hands the server an added/removed list of user ids and the server keeps its own tracking; the client never calls stop(). Same behaviour applies when we route it through DDPSDK instead of Meteor.subscribe, so wrap the call in a helper that picks ddpSdk.client.subscribe while the SDK is authenticated and falls back to Meteor.subscribe otherwise.
1 parent 4695aa7 commit de8a406

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

apps/meteor/client/lib/presence.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ import { Emitter } from '@rocket.chat/emitter';
55
import { Meteor } from 'meteor/meteor';
66

77
import { sdk } from '../../app/utils/client/lib/SDKClient';
8+
import { getDdpSdk } from './sdk/ddpSdk';
9+
10+
const subscribeUserPresence = (payload: { added?: string[]; removed?: string[] }): void => {
11+
const ddp = getDdpSdk();
12+
if (ddp.connection.status === 'connected' && ddp.account.uid) {
13+
// Fire the command-style subscription over our SDK; it has no lifecycle
14+
// (the server registers the added/removed uids and moves on), matching
15+
// Meteor.subscribe's behaviour here.
16+
ddp.client.subscribe('stream-user-presence', '', payload);
17+
return;
18+
}
19+
Meteor.subscribe('stream-user-presence', '', payload);
20+
};
821

922
type InternalEvents = {
1023
remove: IUser['_id'];
@@ -55,7 +68,7 @@ const getPresence = ((): ((uid: UserPresence['_id']) => void) => {
5568
const ids = Array.from(currentUids);
5669
const removed = Array.from(deletedUids);
5770

58-
Meteor.subscribe('stream-user-presence', '', {
71+
subscribeUserPresence({
5972
...(ids.length > 0 && { added: Array.from(currentUids) }),
6073
...(removed.length && { removed: Array.from(deletedUids) }),
6174
});

0 commit comments

Comments
 (0)