The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/hooks/usePresence.ts

30 lines
767 B

import { useMemo } from 'react';
import { useSubscription } from 'use-subscription';
import { Presence, UserPresence } from '../lib/presence';
type Presence = 'online' | 'offline' | 'busy' | 'away' | 'loading';
/**
* Hook to fetch and subscribe users presence
*
* @param uid - User Id
* @returns UserPresence
* @public
*/
export const usePresence = (uid: string): UserPresence | undefined => {
const subscription = useMemo(
() => ({
getCurrentValue: (): UserPresence | undefined => (uid ? Presence.store.get(uid) : undefined),
subscribe: (callback: any): any => {
uid && Presence.listen(uid, callback);
return (): void => {
uid && Presence.stop(uid, callback);
};
},
}),
[uid],
);
return useSubscription(subscription);
};