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,
|
actions,
|
||||||
intl,
|
intl,
|
||||||
shortcuts,
|
shortcuts,
|
||||||
|
UnsentMessagesCollection,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const HIDE_CHAT_AK = shortcuts.hidePrivateChat;
|
const HIDE_CHAT_AK = shortcuts.hidePrivateChat;
|
||||||
@ -99,6 +100,8 @@ const Chat = (props) => {
|
|||||||
partnerIsLoggedOut={partnerIsLoggedOut}
|
partnerIsLoggedOut={partnerIsLoggedOut}
|
||||||
/>
|
/>
|
||||||
<MessageForm
|
<MessageForm
|
||||||
|
UnsentMessagesCollection={UnsentMessagesCollection}
|
||||||
|
chatId={chatID}
|
||||||
disabled={isChatLocked}
|
disabled={isChatLocked}
|
||||||
chatAreaId={ELEMENT_ID}
|
chatAreaId={ELEMENT_ID}
|
||||||
chatTitle={title}
|
chatTitle={title}
|
||||||
|
@ -167,6 +167,7 @@ export default injectIntl(withTracker(({ intl }) => {
|
|||||||
scrollPosition,
|
scrollPosition,
|
||||||
minMessageLength: CHAT_CONFIG.min_message_length,
|
minMessageLength: CHAT_CONFIG.min_message_length,
|
||||||
maxMessageLength: CHAT_CONFIG.max_message_length,
|
maxMessageLength: CHAT_CONFIG.max_message_length,
|
||||||
|
UnsentMessagesCollection: ChatService.UnsentMessagesCollection,
|
||||||
actions: {
|
actions: {
|
||||||
handleClosePrivateChat: chatId => ChatService.closePrivateChat(chatId),
|
handleClosePrivateChat: chatId => ChatService.closePrivateChat(chatId),
|
||||||
|
|
||||||
|
@ -53,18 +53,47 @@ class MessageForm extends PureComponent {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { mobile } = this.BROWSER_RESULTS;
|
const { mobile } = this.BROWSER_RESULTS;
|
||||||
|
|
||||||
|
this.setMessageState();
|
||||||
|
|
||||||
if (!mobile) {
|
if (!mobile) {
|
||||||
this.textarea.focus();
|
this.textarea.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const { chatName } = this.props;
|
const { chatId } = this.props;
|
||||||
|
const { message } = this.state;
|
||||||
const { mobile } = this.BROWSER_RESULTS;
|
const { mobile } = this.BROWSER_RESULTS;
|
||||||
|
|
||||||
if (prevProps.chatName !== chatName && !mobile) {
|
if (prevProps.chatId !== chatId && !mobile) {
|
||||||
this.textarea.focus();
|
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) {
|
handleMessageKeyDown(e) {
|
||||||
@ -103,6 +132,7 @@ class MessageForm extends PureComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
message,
|
message,
|
||||||
error,
|
error,
|
||||||
|
@ -22,6 +22,8 @@ const PUBLIC_CHAT_CLEAR = CHAT_CONFIG.system_messages_keys.chat_clear;
|
|||||||
|
|
||||||
const ScrollCollection = new Mongo.Collection(null);
|
const ScrollCollection = new Mongo.Collection(null);
|
||||||
|
|
||||||
|
const UnsentMessagesCollection = new Mongo.Collection(null);
|
||||||
|
|
||||||
// session for closed chat list
|
// session for closed chat list
|
||||||
const CLOSED_CHAT_LIST_KEY = 'closedChatList';
|
const CLOSED_CHAT_LIST_KEY = 'closedChatList';
|
||||||
|
|
||||||
@ -332,4 +334,5 @@ export default {
|
|||||||
maxTimestampReducer,
|
maxTimestampReducer,
|
||||||
maxNumberReducer,
|
maxNumberReducer,
|
||||||
getLastMessageTimestampFromChatList,
|
getLastMessageTimestampFromChatList,
|
||||||
|
UnsentMessagesCollection,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user