import React, { Component } from 'react'; import classnames from 'classnames'; import _ from 'lodash'; export default class ChatTile extends Component { render() { const { props } = this; let inviteNum = 0; let msgNum = 0; let inviteCircle = `~${window.ship}/i`; let propNumbers = _.get(props, 'data.numbers.chat.numbers', false); let propConfigs = _.get(props, 'data.config.chat.configs', false); if (propNumbers && propConfigs) { let numbers = {}; for (let i = 0; i < propNumbers.length; i++) { let num = propNumbers[i]; numbers[num.circle] = num.length; } let configs = Object.keys(propConfigs); for (let i = 0; i < configs.length; i++) { let key = configs[i]; let host = key.split('/')[0]; if (!propConfigs[key]) { break; } if (!(key in numbers)) { break; } let red = propConfigs[key].red; if (key === inviteCircle) { inviteNum = inviteNum - red + numbers[key]; } else if (host === `~${window.ship}`) { msgNum = msgNum - red + numbers[key]; } else { msgNum = msgNum + numbers[key]; } } } let invSuffix = (inviteNum === 1) ? ( Invite ) : ( Invites ); let numInvElem = (inviteNum > 0) ? (

{inviteNum} {invSuffix}

) : (
); let msgSuffix = (msgNum === 1) ? ( New Message ) : ( New Messages ); let numMsgElem = (msgNum > 0) ? (

{msgNum} {msgSuffix}

) : (
); return (

Chat

{numInvElem} {numMsgElem}
); } } window.chatTile = ChatTile;