2018-12-21 10:55:35 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-10-31 18:40:08 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
import RoomHeader from './RoomHeader';
|
|
|
|
import { withDimensions } from '../../dimensions';
|
|
|
|
import I18n from '../../i18n';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
class RoomHeaderContainer extends Component {
|
2018-10-31 18:40:08 +00:00
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle: PropTypes.string,
|
2018-10-31 18:40:08 +00:00
|
|
|
type: PropTypes.string,
|
2019-04-08 12:35:28 +00:00
|
|
|
prid: PropTypes.string,
|
2019-04-17 17:01:03 +00:00
|
|
|
tmid: PropTypes.string,
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain: PropTypes.bool,
|
2019-09-16 20:26:32 +00:00
|
|
|
usersTyping: PropTypes.string,
|
2019-04-17 17:01:03 +00:00
|
|
|
status: PropTypes.string,
|
2020-03-30 20:19:01 +00:00
|
|
|
statusText: PropTypes.string,
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting: PropTypes.bool,
|
2020-07-06 20:56:28 +00:00
|
|
|
connected: PropTypes.bool,
|
2020-04-01 12:28:54 +00:00
|
|
|
roomUserId: PropTypes.string,
|
2019-11-25 20:01:17 +00:00
|
|
|
widthOffset: PropTypes.number,
|
2021-04-07 18:31:25 +00:00
|
|
|
onPress: PropTypes.func,
|
2020-06-17 17:35:58 +00:00
|
|
|
width: PropTypes.number,
|
2020-10-30 17:35:07 +00:00
|
|
|
height: PropTypes.number,
|
2021-03-31 17:47:17 +00:00
|
|
|
parentTitle: PropTypes.string,
|
2021-04-07 18:31:25 +00:00
|
|
|
isGroupChat: PropTypes.bool,
|
|
|
|
testID: PropTypes.string
|
2018-10-31 18:40:08 +00:00
|
|
|
};
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
2018-12-21 10:55:35 +00:00
|
|
|
const {
|
2021-04-07 18:31:25 +00:00
|
|
|
type, title, subtitle, status, statusText, connecting, connected, onPress, usersTyping, width, height
|
2018-12-21 10:55:35 +00:00
|
|
|
} = this.props;
|
|
|
|
if (nextProps.type !== type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.title !== title) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-30 20:19:01 +00:00
|
|
|
if (nextProps.subtitle !== subtitle) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.status !== status) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-30 20:19:01 +00:00
|
|
|
if (nextProps.statusText !== statusText) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-30 19:31:51 +00:00
|
|
|
if (nextProps.connecting !== connecting) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
if (nextProps.connected !== connected) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-17 17:35:58 +00:00
|
|
|
if (nextProps.width !== width) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-06-17 17:35:58 +00:00
|
|
|
if (nextProps.height !== height) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.usersTyping, usersTyping)) {
|
2019-04-29 16:03:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-04-07 18:31:25 +00:00
|
|
|
if (nextProps.onPress !== onPress) {
|
2019-11-25 20:01:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-31 18:40:08 +00:00
|
|
|
render() {
|
|
|
|
const {
|
2021-03-31 17:47:17 +00:00
|
|
|
title,
|
|
|
|
subtitle: subtitleProp,
|
|
|
|
type,
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain,
|
2021-03-31 17:47:17 +00:00
|
|
|
prid,
|
|
|
|
tmid,
|
|
|
|
widthOffset,
|
|
|
|
status = 'offline',
|
|
|
|
statusText,
|
|
|
|
connecting,
|
|
|
|
connected,
|
|
|
|
usersTyping,
|
2021-04-07 18:31:25 +00:00
|
|
|
onPress,
|
2021-03-31 17:47:17 +00:00
|
|
|
roomUserId,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
parentTitle,
|
2021-04-07 18:31:25 +00:00
|
|
|
isGroupChat,
|
|
|
|
testID
|
2018-10-31 18:40:08 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
let subtitle;
|
|
|
|
if (connecting) {
|
|
|
|
subtitle = I18n.t('Connecting');
|
|
|
|
} else if (!connected) {
|
|
|
|
subtitle = I18n.t('Waiting_for_network');
|
|
|
|
} else {
|
|
|
|
subtitle = subtitleProp;
|
|
|
|
}
|
|
|
|
|
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}
|
2019-04-17 17:01:03 +00:00
|
|
|
widthOffset={widthOffset}
|
2020-04-01 12:28:54 +00:00
|
|
|
roomUserId={roomUserId}
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting={connecting}
|
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}
|
2019-04-08 12:35:28 +00:00
|
|
|
/>
|
2018-10-31 18:40:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2020-03-30 20:19:01 +00:00
|
|
|
let statusText;
|
2020-05-08 17:36:10 +00:00
|
|
|
let status = 'offline';
|
2020-10-30 17:35:07 +00:00
|
|
|
const {
|
|
|
|
roomUserId, type, visitor = {}, tmid
|
|
|
|
} = ownProps;
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
if (state.meteor.connected) {
|
2020-10-30 17:35:07 +00:00
|
|
|
if ((type === 'd' || (tmid && roomUserId)) && state.activeUsers[roomUserId]) {
|
2020-05-08 17:36:10 +00:00
|
|
|
({ status, statusText } = state.activeUsers[roomUserId]);
|
|
|
|
} else if (type === 'l' && visitor?.status) {
|
|
|
|
({ status } = visitor);
|
2019-08-07 13:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2020-07-06 20:56:28 +00:00
|
|
|
connecting: state.meteor.connecting || state.server.loading,
|
|
|
|
connected: state.meteor.connected,
|
2019-09-16 20:26:32 +00:00
|
|
|
usersTyping: state.usersTyping,
|
2020-03-30 20:19:01 +00:00
|
|
|
status,
|
|
|
|
statusText
|
2019-08-07 13:51:34 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
export default connect(mapStateToProps)(withDimensions(RoomHeaderContainer));
|