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';
|
|
|
|
import { responsive } from 'react-native-responsive-ui';
|
|
|
|
import equal from 'deep-equal';
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
import database from '../../../lib/realm';
|
|
|
|
import Header from './Header';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
|
|
|
@responsive
|
2019-04-08 12:35:28 +00:00
|
|
|
@connect((state, ownProps) => {
|
2018-10-31 18:40:08 +00:00
|
|
|
let status = '';
|
2019-04-08 12:35:28 +00:00
|
|
|
const { rid, type } = ownProps;
|
|
|
|
if (type === 'd') {
|
2018-11-05 12:00:58 +00:00
|
|
|
if (state.login.user && state.login.user.id) {
|
|
|
|
const { id: loggedUserId } = state.login.user;
|
2019-04-08 12:35:28 +00:00
|
|
|
const userId = rid.replace(loggedUserId, '').trim();
|
2018-11-05 12:00:58 +00:00
|
|
|
if (userId === loggedUserId) {
|
|
|
|
status = state.login.user.status; // eslint-disable-line
|
|
|
|
} else {
|
|
|
|
const user = state.activeUsers[userId];
|
|
|
|
status = (user && user.status) || 'offline';
|
|
|
|
}
|
2018-10-31 18:40:08 +00:00
|
|
|
}
|
2018-11-05 12:00:58 +00:00
|
|
|
}
|
2018-10-31 18:40:08 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
status
|
|
|
|
};
|
|
|
|
})
|
2018-12-21 10:55:35 +00:00
|
|
|
export default class RoomHeaderView extends Component {
|
2018-10-31 18:40:08 +00:00
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
2019-04-08 12:35:28 +00:00
|
|
|
prid: PropTypes.string,
|
|
|
|
rid: PropTypes.string,
|
2018-10-31 18:40:08 +00:00
|
|
|
window: PropTypes.object,
|
|
|
|
status: PropTypes.string
|
|
|
|
};
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.usersTyping = database.memoryDatabase.objects('usersTyping').filtered('rid = $0', props.rid);
|
|
|
|
this.state = {
|
|
|
|
usersTyping: this.usersTyping.slice() || []
|
|
|
|
};
|
|
|
|
this.usersTyping.addListener(this.updateState);
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const { usersTyping } = this.state;
|
2018-12-21 10:55:35 +00:00
|
|
|
const {
|
2019-04-08 12:35:28 +00:00
|
|
|
type, title, status, window
|
2018-12-21 10:55:35 +00:00
|
|
|
} = this.props;
|
|
|
|
if (nextProps.type !== type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.title !== title) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.status !== status) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.window.width !== window.width) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.window.height !== window.height) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
if (!equal(nextState.usersTyping, usersTyping)) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-27 20:06:57 +00:00
|
|
|
// componentDidUpdate(prevProps) {
|
|
|
|
// if (isIOS) {
|
|
|
|
// const { usersTyping } = this.props;
|
|
|
|
// if (!equal(prevProps.usersTyping, usersTyping)) {
|
|
|
|
// LayoutAnimation.easeInEaseOut();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
updateState = () => {
|
|
|
|
this.setState({ usersTyping: this.usersTyping.slice() });
|
2018-10-31 18:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { usersTyping } = this.state;
|
2018-10-31 18:40:08 +00:00
|
|
|
const {
|
2019-04-08 12:35:28 +00:00
|
|
|
window, title, type, status, prid
|
2018-10-31 18:40:08 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<Header
|
|
|
|
prid={prid}
|
|
|
|
title={title}
|
|
|
|
type={type}
|
|
|
|
status={status}
|
|
|
|
width={window.width}
|
|
|
|
height={window.height}
|
|
|
|
usersTyping={usersTyping}
|
|
|
|
/>
|
2018-10-31 18:40:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|