Rocket.Chat.ReactNative/app/containers/Status/index.tsx

33 lines
950 B
TypeScript
Raw Normal View History

import React, { useEffect } from 'react';
import Status from './Status';
import { IStatus } from './definition';
import { useAppSelector } from '../../lib/hooks';
import { getUserPresence } from '../../lib/methods';
const StatusContainer = ({ id, style, status, size = 32, ...props }: IStatus): React.ReactElement => {
const connected = useAppSelector(state => state.meteor.connected);
const statusState = useAppSelector(state => {
2023-02-14 13:47:56 +00:00
if (state.settings.Presence_broadcast_disabled) {
return 'disabled';
}
if (state.meteor.connected && state.activeUsers[id]) {
return state.activeUsers[id].status;
}
if (!state.meteor.connected) {
return 'offline';
2023-02-14 13:47:56 +00:00
}
return 'loading';
});
useEffect(() => {
if (connected && statusState === 'loading') {
getUserPresence(id);
}
}, [connected, statusState]);
return <Status size={size} style={style} status={status ?? statusState} {...props} />;
};
export default StatusContainer;