2022-06-13 20:16:20 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { shallowEqual, useSelector } from 'react-redux';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2022-06-13 20:16:20 +00:00
|
|
|
import { IApplicationState, TUserStatus, IOmnichannelSource, IVisitor } from '../../definitions';
|
|
|
|
import { useDimensions } from '../../dimensions';
|
2021-04-07 18:31:25 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-01-18 15:04:40 +00:00
|
|
|
import RoomHeader from './RoomHeader';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IRoomHeaderContainerProps {
|
2022-06-13 20:16:20 +00:00
|
|
|
title?: string;
|
|
|
|
subtitle?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
type: string;
|
2022-06-13 20:16:20 +00:00
|
|
|
prid?: string;
|
|
|
|
tmid?: string;
|
|
|
|
teamMain?: boolean;
|
|
|
|
roomUserId?: string | null;
|
|
|
|
onPress: Function;
|
|
|
|
parentTitle?: string;
|
|
|
|
isGroupChat?: boolean;
|
|
|
|
testID?: string;
|
2022-04-15 02:27:36 +00:00
|
|
|
sourceType?: IOmnichannelSource;
|
2022-06-13 20:16:20 +00:00
|
|
|
visitor?: IVisitor;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2022-06-13 20:16:20 +00:00
|
|
|
const RoomHeaderContainer = React.memo(
|
|
|
|
({
|
|
|
|
isGroupChat,
|
|
|
|
onPress,
|
|
|
|
parentTitle,
|
|
|
|
prid,
|
|
|
|
roomUserId,
|
|
|
|
subtitle: subtitleProp,
|
|
|
|
teamMain,
|
|
|
|
testID,
|
|
|
|
title,
|
|
|
|
tmid,
|
|
|
|
type,
|
|
|
|
sourceType,
|
|
|
|
visitor
|
|
|
|
}: IRoomHeaderContainerProps) => {
|
|
|
|
let subtitle: string | undefined;
|
|
|
|
let status: TUserStatus = 'offline';
|
|
|
|
let statusText: string | undefined;
|
|
|
|
const { width, height } = useDimensions();
|
2018-12-21 10:55:35 +00:00
|
|
|
|
2022-06-13 20:16:20 +00:00
|
|
|
const connecting = useSelector((state: IApplicationState) => state.meteor.connecting || state.server.loading);
|
|
|
|
const usersTyping = useSelector((state: IApplicationState) => state.usersTyping, shallowEqual);
|
|
|
|
const connected = useSelector((state: IApplicationState) => state.meteor.connected);
|
2023-02-14 13:47:56 +00:00
|
|
|
const presenceDisabled = useSelector((state: IApplicationState) => state.settings.Presence_broadcast_disabled);
|
2022-06-13 20:16:20 +00:00
|
|
|
const activeUser = useSelector(
|
|
|
|
(state: IApplicationState) => (roomUserId ? state.activeUsers?.[roomUserId] : undefined),
|
|
|
|
shallowEqual
|
|
|
|
);
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
if (connecting) {
|
|
|
|
subtitle = I18n.t('Connecting');
|
|
|
|
} else if (!connected) {
|
|
|
|
subtitle = I18n.t('Waiting_for_network');
|
|
|
|
} else {
|
|
|
|
subtitle = subtitleProp;
|
|
|
|
}
|
|
|
|
|
2022-06-13 20:16:20 +00:00
|
|
|
if (connected) {
|
|
|
|
if ((type === 'd' || (tmid && roomUserId)) && activeUser) {
|
2023-02-14 13:47:56 +00:00
|
|
|
if (presenceDisabled) {
|
|
|
|
status = 'disabled';
|
|
|
|
} else {
|
|
|
|
const { status: statusActiveUser, statusText: statusTextActiveUser } = activeUser;
|
|
|
|
status = statusActiveUser;
|
|
|
|
statusText = statusTextActiveUser;
|
|
|
|
}
|
2022-06-13 20:16:20 +00:00
|
|
|
} else if (type === 'l' && visitor?.status) {
|
|
|
|
const { status: statusVisitor } = visitor;
|
|
|
|
status = statusVisitor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 18:40:08 +00:00
|
|
|
return (
|
2021-04-07 18:31:25 +00:00
|
|
|
<RoomHeader
|
2019-04-08 12:35:28 +00:00
|
|
|
prid={prid}
|
2019-04-17 17:01:03 +00:00
|
|
|
tmid={tmid}
|
2019-04-08 12:35:28 +00:00
|
|
|
title={title}
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle={type === 'd' ? statusText : subtitle}
|
2019-04-08 12:35:28 +00:00
|
|
|
type={type}
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain={teamMain}
|
2019-04-08 12:35:28 +00:00
|
|
|
status={status}
|
2020-06-17 17:35:58 +00:00
|
|
|
width={width}
|
|
|
|
height={height}
|
2019-04-08 12:35:28 +00:00
|
|
|
usersTyping={usersTyping}
|
2020-10-30 17:35:07 +00:00
|
|
|
parentTitle={parentTitle}
|
2021-03-31 17:47:17 +00:00
|
|
|
isGroupChat={isGroupChat}
|
2021-04-07 18:31:25 +00:00
|
|
|
testID={testID}
|
|
|
|
onPress={onPress}
|
2022-04-15 02:27:36 +00:00
|
|
|
sourceType={sourceType}
|
2019-04-08 12:35:28 +00:00
|
|
|
/>
|
2018-10-31 18:40:08 +00:00
|
|
|
);
|
|
|
|
}
|
2022-06-13 20:16:20 +00:00
|
|
|
);
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-06-13 20:16:20 +00:00
|
|
|
export default RoomHeaderContainer;
|