2023-01-24 13:03:48 +00:00
|
|
|
import { TUserStatus } from '../../definitions';
|
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
|
|
|
import { RoomTypes } from '../../lib/methods';
|
|
|
|
|
|
|
|
export const useUserStatus = (
|
|
|
|
type: RoomTypes,
|
|
|
|
liveChatStatus?: TUserStatus,
|
|
|
|
id?: string
|
|
|
|
): { connected: boolean; status: TUserStatus } => {
|
|
|
|
const connected = useAppSelector(state => state.meteor.connected);
|
2023-02-14 13:47:56 +00:00
|
|
|
const presenceDisabled = useAppSelector(state => state.settings.Presence_broadcast_disabled);
|
2023-01-24 13:03:48 +00:00
|
|
|
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
|
2023-02-14 13:47:56 +00:00
|
|
|
|
2023-01-24 13:03:48 +00:00
|
|
|
let status = 'loading';
|
|
|
|
if (connected) {
|
|
|
|
if (type === 'd') {
|
2023-02-14 13:47:56 +00:00
|
|
|
if (presenceDisabled) {
|
|
|
|
status = 'disabled';
|
|
|
|
} else {
|
|
|
|
status = userStatus || 'loading';
|
|
|
|
}
|
2023-01-24 13:03:48 +00:00
|
|
|
} else if (type === 'l' && liveChatStatus) {
|
|
|
|
status = liveChatStatus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
connected,
|
|
|
|
status: status as TUserStatus
|
|
|
|
};
|
|
|
|
};
|