2017-05-27 05:30:22 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-06-21 06:40:28 +00:00
|
|
|
import ChatTitle from './ChatTitle';
|
|
|
|
import Search from './Search';
|
|
|
|
import MessageBox from './MessageBox';
|
|
|
|
import MessageInput from './MessageInput';
|
|
|
|
import UserList from './UserList';
|
2017-05-27 05:30:22 +00:00
|
|
|
|
|
|
|
export default class Chat extends Component {
|
|
|
|
handleCloseClick = () => {
|
|
|
|
const { tab, part, closePrivateChat, disconnect } = this.props;
|
|
|
|
|
|
|
|
if (tab.isChannel()) {
|
|
|
|
part([tab.name], tab.server);
|
|
|
|
} else if (tab.name) {
|
|
|
|
closePrivateChat(tab.server, tab.name);
|
|
|
|
} else {
|
|
|
|
disconnect(tab.server);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSearch = phrase => {
|
|
|
|
const { tab, searchMessages } = this.props;
|
|
|
|
if (tab.isChannel()) {
|
|
|
|
searchMessages(tab.server, tab.name, phrase);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
handleNickClick = nick => {
|
|
|
|
const { tab, openPrivateChat, select } = this.props;
|
|
|
|
openPrivateChat(tab.server, nick);
|
|
|
|
select(tab.server, nick);
|
|
|
|
};
|
|
|
|
|
2017-06-12 04:18:32 +00:00
|
|
|
handleTitleChange = title => {
|
|
|
|
const { setServerName, tab } = this.props;
|
|
|
|
setServerName(title, tab.server);
|
|
|
|
};
|
|
|
|
|
2017-06-21 05:23:07 +00:00
|
|
|
handleNickChange = nick => {
|
|
|
|
const { setNick, tab } = this.props;
|
|
|
|
setNick(nick, tab.server, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
handleNickEditDone = nick => {
|
|
|
|
const { setNick, tab } = this.props;
|
|
|
|
setNick(nick, tab.server);
|
|
|
|
};
|
|
|
|
|
2017-05-27 05:30:22 +00:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
channel,
|
|
|
|
currentInputHistoryEntry,
|
|
|
|
hasMoreMessages,
|
|
|
|
messages,
|
|
|
|
nick,
|
|
|
|
search,
|
|
|
|
showUserList,
|
2017-07-02 01:31:00 +00:00
|
|
|
status,
|
2017-05-27 05:30:22 +00:00
|
|
|
tab,
|
|
|
|
title,
|
|
|
|
users,
|
|
|
|
|
2017-06-06 22:04:37 +00:00
|
|
|
addFetchedMessages,
|
2017-05-27 05:30:22 +00:00
|
|
|
fetchMessages,
|
|
|
|
inputActions,
|
|
|
|
runCommand,
|
|
|
|
sendMessage,
|
|
|
|
toggleSearch,
|
|
|
|
toggleUserList
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let chatClass;
|
|
|
|
if (tab.isChannel()) {
|
|
|
|
chatClass = 'chat-channel';
|
|
|
|
} else if (tab.name) {
|
|
|
|
chatClass = 'chat-private';
|
|
|
|
} else {
|
|
|
|
chatClass = 'chat-server';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={chatClass}>
|
|
|
|
<ChatTitle
|
|
|
|
channel={channel}
|
2017-07-02 01:31:00 +00:00
|
|
|
status={status}
|
2017-05-27 05:30:22 +00:00
|
|
|
tab={tab}
|
|
|
|
title={title}
|
|
|
|
onCloseClick={this.handleCloseClick}
|
2017-06-12 04:18:32 +00:00
|
|
|
onTitleChange={this.handleTitleChange}
|
2017-05-27 05:30:22 +00:00
|
|
|
onToggleSearch={toggleSearch}
|
|
|
|
onToggleUserList={toggleUserList}
|
|
|
|
/>
|
2018-04-05 23:46:22 +00:00
|
|
|
<Search search={search} onSearch={this.handleSearch} />
|
2017-05-27 05:30:22 +00:00
|
|
|
<MessageBox
|
|
|
|
hasMoreMessages={hasMoreMessages}
|
|
|
|
messages={messages}
|
|
|
|
tab={tab}
|
2017-06-06 22:04:37 +00:00
|
|
|
onAddMore={addFetchedMessages}
|
2017-05-27 05:30:22 +00:00
|
|
|
onFetchMore={fetchMessages}
|
|
|
|
onNickClick={this.handleNickClick}
|
|
|
|
/>
|
|
|
|
<MessageInput
|
|
|
|
currentHistoryEntry={currentInputHistoryEntry}
|
|
|
|
nick={nick}
|
|
|
|
tab={tab}
|
|
|
|
onCommand={runCommand}
|
|
|
|
onMessage={sendMessage}
|
2017-06-21 05:23:07 +00:00
|
|
|
onNickChange={this.handleNickChange}
|
|
|
|
onNickEditDone={this.handleNickEditDone}
|
2017-05-27 05:30:22 +00:00
|
|
|
{...inputActions}
|
|
|
|
/>
|
|
|
|
<UserList
|
|
|
|
showUserList={showUserList}
|
|
|
|
users={users}
|
|
|
|
onNickClick={this.handleNickClick}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|