From 3fc8f56c63da78bfaaf2a05ef42ca62b4b57d4e8 Mon Sep 17 00:00:00 2001 From: trazyn Date: Thu, 26 Jul 2018 00:26:00 +0800 Subject: [PATCH] Non-blocking send message #65 #67 --- src/js/components/MessageInput/index.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/js/components/MessageInput/index.js b/src/js/components/MessageInput/index.js index a24281a..d40292c 100644 --- a/src/js/components/MessageInput/index.js +++ b/src/js/components/MessageInput/index.js @@ -24,10 +24,6 @@ export default class MessageInput extends Component { canisend() { var user = this.props.user; - if (this.blocking) { - return false; - } - if ( true && user.length === 1 @@ -40,9 +36,6 @@ export default class MessageInput extends Component { return true; } - // Prevent duplicate message - blocking = false; - async handleEnter(e) { var message = this.refs.input.value.trim(); var user = this.props.user; @@ -55,10 +48,8 @@ export default class MessageInput extends Component { || e.charCode !== 13 ) return; - this.blocking = true; - // You can not send message to yourself - await Promise.all( + Promise.all( user.filter(e => e.UserName !== this.props.me.UserName).map( async e => { let res = await this.props.sendMessage( @@ -70,8 +61,6 @@ export default class MessageInput extends Component { true ); - this.refs.input.value = ''; - if (!res) { await this.props.showMessage(batch ? `Send message to ${e.NickName} is failed!` : 'Failed to send message.'); } @@ -80,7 +69,8 @@ export default class MessageInput extends Component { } ) ); - this.blocking = false; + + this.refs.input.value = ''; } state = {