Fix user presence on RoomItem

This commit is contained in:
Diego Mello 2022-12-02 11:50:56 -03:00
parent c6ecfa17a3
commit b2db5500b6
1 changed files with 12 additions and 1 deletions

View File

@ -40,14 +40,25 @@ const RoomItemContainer = ({
const alert = item.alert || item.tunread?.length;
const connected = useAppSelector(state => state.meteor.connected);
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
const isDirect = !!(item.t === 'd' && id && !isGroupChat(item));
// When app reconnects, we need to fetch the rendered user's presence
useEffect(() => {
const isDirect = !!(item.t === 'd' && id && !isGroupChat(item));
if (connected && isDirect) {
getUserPresence(id);
}
}, [connected]);
/**
* The component can be recycled by FlashList.
* When rid changes and there's no user's status, we need to fetch it
*/
useEffect(() => {
if (!userStatus && isDirect) {
getUserPresence(id);
}
}, [item.rid]);
const handleOnPress = () => onPress(item);
const handleOnLongPress = () => onLongPress && onLongPress(item);