Merge pull request #6698 from vitormateusalmeida/issue-6601
Fix chat input between chats
This commit is contained in:
commit
1b37c284a4
@ -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}
|
||||
|
@ -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),
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user