Skip to content

Commit

Permalink
Non-blocking send message trazyn#65 trazyn#67
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Jul 25, 2018
1 parent f03b4ea commit 3fc8f56
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/js/components/MessageInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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.');
}
Expand All @@ -80,7 +69,8 @@ export default class MessageInput extends Component {
}
)
);
this.blocking = false;

this.refs.input.value = '';
}

state = {
Expand Down

0 comments on commit 3fc8f56

Please sign in to comment.