Regression: Fix RoomItem's loading status (#4835)
This commit is contained in:
parent
f34b5b5c82
commit
9cf6981a27
|
@ -2,13 +2,13 @@ import React, { useEffect, useReducer, useRef } from 'react';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import { useAppSelector } from '../../lib/hooks';
|
|
||||||
import { getUserPresence } from '../../lib/methods';
|
import { getUserPresence } from '../../lib/methods';
|
||||||
import { isGroupChat } from '../../lib/methods/helpers';
|
import { isGroupChat } from '../../lib/methods/helpers';
|
||||||
import { formatDate } from '../../lib/methods/helpers/room';
|
import { formatDate } from '../../lib/methods/helpers/room';
|
||||||
import { IRoomItemContainerProps } from './interfaces';
|
import { IRoomItemContainerProps } from './interfaces';
|
||||||
import RoomItem from './RoomItem';
|
import RoomItem from './RoomItem';
|
||||||
import { ROW_HEIGHT, ROW_HEIGHT_CONDENSED } from './styles';
|
import { ROW_HEIGHT, ROW_HEIGHT_CONDENSED } from './styles';
|
||||||
|
import { useUserStatus } from './useUserStatus';
|
||||||
|
|
||||||
export { ROW_HEIGHT, ROW_HEIGHT_CONDENSED };
|
export { ROW_HEIGHT, ROW_HEIGHT_CONDENSED };
|
||||||
|
|
||||||
|
@ -42,11 +42,11 @@ const RoomItemContainer = React.memo(
|
||||||
const isRead = getIsRead(item);
|
const isRead = getIsRead(item);
|
||||||
const date = item.roomUpdatedAt && formatDate(item.roomUpdatedAt);
|
const date = item.roomUpdatedAt && formatDate(item.roomUpdatedAt);
|
||||||
const alert = item.alert || item.tunread?.length;
|
const alert = item.alert || item.tunread?.length;
|
||||||
const connected = useAppSelector(state => state.meteor.connected);
|
|
||||||
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
|
|
||||||
const [_, forceUpdate] = useReducer(x => x + 1, 1);
|
const [_, forceUpdate] = useReducer(x => x + 1, 1);
|
||||||
const roomSubscription = useRef<Subscription | null>(null);
|
const roomSubscription = useRef<Subscription | null>(null);
|
||||||
|
|
||||||
|
const { connected, status } = useUserStatus(item.t, item?.visitor?.status, id);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const init = () => {
|
const init = () => {
|
||||||
if (item?.observe) {
|
if (item?.observe) {
|
||||||
|
@ -85,8 +85,6 @@ const RoomItemContainer = React.memo(
|
||||||
accessibilityLabel = `, ${I18n.t('last_message')} ${date}`;
|
accessibilityLabel = `, ${I18n.t('last_message')} ${date}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = item.t === 'l' ? item.visitor?.status || item.v?.status : userStatus;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RoomItem
|
<RoomItem
|
||||||
name={name}
|
name={name}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
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);
|
||||||
|
const userStatus = useAppSelector(state => state.activeUsers[id || '']?.status);
|
||||||
|
let status = 'loading';
|
||||||
|
if (connected) {
|
||||||
|
if (type === 'd') {
|
||||||
|
status = userStatus || 'loading';
|
||||||
|
} else if (type === 'l' && liveChatStatus) {
|
||||||
|
status = liveChatStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
connected,
|
||||||
|
status: status as TUserStatus
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue