verdnatura-chat/app/containers/RoomItem/useUserStatus.tsx

31 lines
854 B
TypeScript
Raw Permalink Normal View History

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);
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
2023-02-14 13:47:56 +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';
}
} else if (type === 'l' && liveChatStatus) {
status = liveChatStatus;
}
}
return {
connected,
status: status as TUserStatus
};
};