bigbuffet-rw/app/soapbox/features/chats/components/chat.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-08-25 09:33:51 -07:00
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import Avatar from '../../../components/avatar';
import DisplayName from '../../../components/display_name';
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-08-27 13:43:19 -07:00
import { shortNumberFormat } from 'soapbox/utils/numbers';
import emojify from 'soapbox/features/emoji/emoji';
2020-08-25 09:33:51 -07:00
export default class Chat extends ImmutablePureComponent {
2020-08-25 09:33:51 -07:00
static propTypes = {
2020-08-25 15:24:47 -07:00
chat: ImmutablePropTypes.map.isRequired,
2020-08-25 09:33:51 -07:00
onClick: PropTypes.func,
};
handleClick = () => {
2020-08-25 15:24:47 -07:00
this.props.onClick(this.props.chat);
2020-08-25 09:33:51 -07:00
}
render() {
2020-08-25 15:24:47 -07:00
const { chat } = this.props;
if (!chat) return null;
const account = chat.get('account');
2020-08-27 13:43:19 -07:00
const unreadCount = chat.get('unread');
const content = chat.getIn(['last_message', 'content']);
const parsedContent = content ? emojify(content) : '';
2020-08-25 09:33:51 -07:00
return (
<div className='account'>
<button className='floating-link' onClick={this.handleClick} />
<div className='account__wrapper'>
<div key={account.get('id')} className='account__display-name'>
<div className='account__avatar-wrapper'>
<Avatar account={account} size={36} />
</div>
<DisplayName account={account} />
<span
className='chat__last-message'
dangerouslySetInnerHTML={{ __html: parsedContent }}
/>
2020-08-27 13:43:19 -07:00
{unreadCount > 0 && <i className='icon-with-badge__badge'>{shortNumberFormat(unreadCount)}</i>}
2020-08-25 09:33:51 -07:00
</div>
</div>
</div>
);
}
}