import React from 'react'; import { Text, View, Platform, TouchableOpacity } from 'react-native'; import Icon from 'react-native-vector-icons/Ionicons'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { HeaderBackButton } from 'react-navigation'; import realm from '../../../lib/realm'; import Avatar from '../../../containers/Avatar'; import { STATUS_COLORS } from '../../../constants/colors'; import styles from './styles'; @connect(state => ({ user: state.login.user, baseUrl: state.settings.Site_Url, activeUsers: state.activeUsers })) export default class extends React.Component { static propTypes = { navigation: PropTypes.object.isRequired, user: PropTypes.object.isRequired, baseUrl: PropTypes.string, activeUsers: PropTypes.object } constructor(props) { super(props); this.state = { room: {}, roomName: props.navigation.state.params.name }; this.rid = props.navigation.state.params.room.rid; this.room = realm.objects('subscriptions').filtered('rid = $0', this.rid); this.room.addListener(this.updateState); } componentDidMount() { this.updateState(); } componentWillUnmount() { this.room.removeAllListeners(); } getUserStatus() { const userId = this.rid.replace(this.props.user.id, '').trim(); return this.props.activeUsers[userId] || 'offline'; } getUserStatusLabel() { const status = this.getUserStatus(); return status.charAt(0).toUpperCase() + status.slice(1); } updateState = () => { this.setState({ room: this.room[0] }); }; isDirect = () => this.state.room && this.state.room.t === 'd'; renderLeft = () => this.props.navigation.goBack(null)} tintColor='#292E35' title='Back' titleStyle={{ display: 'none' }} />; renderTitle() { if (!this.state.roomName) { return null; } let accessibilityLabel = this.state.roomName; if (this.isDirect()) { accessibilityLabel += `, ${ this.getUserStatusLabel() }`; } return ( {this.isDirect() ? : null } {this.state.roomName} {this.isDirect() ? {this.getUserStatusLabel()} : null } ); } renderRight = () => ( {}} accessibilityLabel='Room actions' accessibilityTraits='button' > ); render() { return ( {this.renderLeft()} {this.renderTitle()} {this.renderRight()} ); } }