2020-08-27 20:11:15 -07:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-10-14 10:23:51 -07:00
|
|
|
import { connect } from 'react-redux';
|
2020-08-27 20:11:15 -07:00
|
|
|
import Column from '../../components/column';
|
|
|
|
import ColumnHeader from '../../components/column_header';
|
2021-10-14 10:23:51 -07:00
|
|
|
import { launchChat } from 'soapbox/actions/chats';
|
2020-08-27 20:11:15 -07:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import ChatList from './components/chat_list';
|
2020-09-17 22:28:54 -07:00
|
|
|
import AudioToggle from 'soapbox/features/chats/components/audio_toggle';
|
2021-10-14 10:23:51 -07:00
|
|
|
import AccountSearch from 'soapbox/components/account_search';
|
2021-11-03 18:35:40 -07:00
|
|
|
import Pullable from 'soapbox/components/pullable';
|
2020-08-27 20:11:15 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'column.chats', defaultMessage: 'Chats' },
|
2021-10-14 10:23:51 -07:00
|
|
|
searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Start a chat with…' },
|
2020-08-27 20:11:15 -07:00
|
|
|
});
|
|
|
|
|
2021-10-14 10:23:51 -07:00
|
|
|
export default @connect()
|
|
|
|
@injectIntl
|
2020-08-27 20:11:15 -07:00
|
|
|
class ChatIndex extends React.PureComponent {
|
|
|
|
|
2021-10-14 10:23:51 -07:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2020-08-27 20:11:15 -07:00
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
2021-10-14 10:23:51 -07:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2020-08-27 20:11:15 -07:00
|
|
|
};
|
|
|
|
|
2021-10-14 10:23:51 -07:00
|
|
|
handleSuggestion = accountId => {
|
|
|
|
this.props.dispatch(launchChat(accountId, this.context.router.history, true));
|
|
|
|
}
|
2020-08-27 20:11:15 -07:00
|
|
|
|
|
|
|
handleClickChat = (chat) => {
|
|
|
|
this.context.router.history.push(`/chats/${chat.get('id')}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Column label={intl.formatMessage(messages.title)}>
|
|
|
|
<ColumnHeader
|
|
|
|
icon='comment'
|
|
|
|
title={intl.formatMessage(messages.title)}
|
|
|
|
/>
|
2021-10-14 10:23:51 -07:00
|
|
|
|
|
|
|
<div className='column__switch'>
|
|
|
|
<AudioToggle />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<AccountSearch
|
|
|
|
placeholder={intl.formatMessage(messages.searchPlaceholder)}
|
|
|
|
onSelected={this.handleSuggestion}
|
|
|
|
/>
|
2020-08-27 20:11:15 -07:00
|
|
|
|
2021-11-03 18:35:40 -07:00
|
|
|
<Pullable>
|
|
|
|
<ChatList
|
|
|
|
onClickChat={this.handleClickChat}
|
|
|
|
emptyMessage={<FormattedMessage id='chat_panels.main_window.empty' defaultMessage="No chats found. To start a chat, visit a user's profile." />}
|
|
|
|
/>
|
|
|
|
</Pullable>
|
2020-08-27 20:11:15 -07:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|