2023-08-29 19:15:26 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
import Status from './Status';
|
2022-03-25 20:05:49 +00:00
|
|
|
import { IStatus } from './definition';
|
2022-05-13 15:01:34 +00:00
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
2023-08-29 19:15:26 +00:00
|
|
|
import { getUserPresence } from '../../lib/methods';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2023-08-29 19:15:26 +00:00
|
|
|
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';
|
|
|
|
}
|
2023-08-29 19:15:26 +00:00
|
|
|
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';
|
2023-08-29 19:15:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (connected && statusState === 'loading') {
|
|
|
|
getUserPresence(id);
|
|
|
|
}
|
|
|
|
}, [connected, statusState]);
|
|
|
|
|
|
|
|
return <Status size={size} style={style} status={status ?? statusState} {...props} />;
|
2022-03-25 20:05:49 +00:00
|
|
|
};
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-25 20:05:49 +00:00
|
|
|
export default StatusContainer;
|