Merge pull request #6698 from vitormateusalmeida/issue-6601

Fix chat input between chats
This commit is contained in:
Anton Georgiev 2019-02-11 10:39:39 -05:00 committed by GitHub
commit 1b37c284a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View File

@ -39,6 +39,7 @@ const Chat = (props) => {
actions,
intl,
shortcuts,
UnsentMessagesCollection,
} = props;
const HIDE_CHAT_AK = shortcuts.hidePrivateChat;
@ -99,6 +100,8 @@ const Chat = (props) => {
partnerIsLoggedOut={partnerIsLoggedOut}
/>
<MessageForm
UnsentMessagesCollection={UnsentMessagesCollection}
chatId={chatID}
disabled={isChatLocked}
chatAreaId={ELEMENT_ID}
chatTitle={title}

View File

@ -167,6 +167,7 @@ export default injectIntl(withTracker(({ intl }) => {
scrollPosition,
minMessageLength: CHAT_CONFIG.min_message_length,
maxMessageLength: CHAT_CONFIG.max_message_length,
UnsentMessagesCollection: ChatService.UnsentMessagesCollection,
actions: {
handleClosePrivateChat: chatId => ChatService.closePrivateChat(chatId),

View File

@ -53,18 +53,47 @@ class MessageForm extends PureComponent {
componentDidMount() {
const { mobile } = this.BROWSER_RESULTS;
this.setMessageState();
if (!mobile) {
this.textarea.focus();
}
}
componentDidUpdate(prevProps) {
const { chatName } = this.props;
const { chatId } = this.props;
const { message } = this.state;
const { mobile } = this.BROWSER_RESULTS;
if (prevProps.chatName !== chatName && !mobile) {
if (prevProps.chatId !== chatId && !mobile) {
this.textarea.focus();
}
if (prevProps.chatId !== chatId) {
this.updateUnsentMessagesCollection(prevProps.chatId, message);
this.setMessageState();
}
}
componentWillUnmount() {
const { chatId } = this.props;
const { message } = this.state;
this.updateUnsentMessagesCollection(chatId, message);
this.setMessageState();
}
setMessageState() {
const { chatId, UnsentMessagesCollection } = this.props;
const unsentMessageByChat = UnsentMessagesCollection.findOne({ chatId });
this.setState({ message: unsentMessageByChat ? unsentMessageByChat.message : '' });
}
updateUnsentMessagesCollection(chatId, message) {
const { UnsentMessagesCollection } = this.props;
UnsentMessagesCollection.upsert(
{ chatId },
{ $set: { message } },
);
}
handleMessageKeyDown(e) {
@ -103,6 +132,7 @@ class MessageForm extends PureComponent {
);
}
this.setState({
message,
error,

View File

@ -22,6 +22,8 @@ const PUBLIC_CHAT_CLEAR = CHAT_CONFIG.system_messages_keys.chat_clear;
const ScrollCollection = new Mongo.Collection(null);
const UnsentMessagesCollection = new Mongo.Collection(null);
// session for closed chat list
const CLOSED_CHAT_LIST_KEY = 'closedChatList';
@ -332,4 +334,5 @@ export default {
maxTimestampReducer,
maxNumberReducer,
getLastMessageTimestampFromChatList,
UnsentMessagesCollection,
};