From e999473f193bb4f7344fb3c903a1f62657022ecb Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg <scott@nonnenberg.com> Date: Thu, 4 Jan 2018 16:51:00 -0800 Subject: [PATCH] Preserve disabled state in the middle of sending message (#1937) * Preserve disabled state in send-message field on click Also: get consistent in treatment of 'disabled' property. * Add some comments explaining how audio recording dismissal works --- js/views/conversation_view.js | 27 +++++++++++++++++---------- js/views/recorder_view.js | 3 +++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 44563c137..f36be0302 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -393,6 +393,9 @@ captureAudio: function(e) { e.preventDefault(); + // Note - clicking anywhere will close the audio capture panel, due to + // the onClick handler in InboxView, which calls its closeRecording method. + if (this.captureAudioView) { this.captureAudioView.remove(); this.captureAudioView = null; @@ -404,7 +407,7 @@ view.on('closed', this.endCaptureAudio.bind(this)); view.$el.appendTo(this.$('.capture-audio')); - this.$('.send-message').attr('disabled','disabled'); + this.$('.send-message').attr('disabled', true); this.$('.microphone').hide(); }, handleAudioCapture: function(blob) { @@ -584,7 +587,11 @@ }, focusMessageField: function() { - this.$messageField.prop('disabled', false); + this.$messageField.focus(); + }, + + focusMessageFieldAndClearDisabled: function() { + this.$messageField.removeAttr('disabled'); this.$messageField.focus(); }, @@ -888,7 +895,7 @@ this.checkUnverifiedSendMessage(e, {force: true}); }.bind(this), reject: function() { - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); }.bind(this) }); @@ -899,7 +906,7 @@ checkUnverifiedSendMessage: function(e, options) { e.preventDefault(); this.sendStart = Date.now(); - this.$messageField.prop('disabled', true); + this.$messageField.attr('disabled', true); options = options || {}; _.defaults(options, {force: false}); @@ -920,7 +927,7 @@ this.showSendConfirmationDialog(e, contacts); }.bind(this)).catch(function(error) { - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); console.log( 'checkUnverifiedSendMessage error:', error && error.stack ? error.stack : error @@ -945,7 +952,7 @@ this.showSendConfirmationDialog(e, contacts); }.bind(this)).catch(function(error) { - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); console.log( 'checkUntrustedSendMessage error:', error && error.stack ? error.stack : error @@ -1008,7 +1015,7 @@ if (toast) { toast.$el.insertAfter(this.$el); toast.render(); - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); return; } @@ -1021,15 +1028,15 @@ console.log('Send pre-checks took', sendDelta, 'milliseconds'); this.model.sendMessage(message, attachments); input.val(""); - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); this.forceUpdateMessageFieldSize(e); this.fileInput.deleteFiles(); }.bind(this)).catch(function() { console.log('Error pulling attached files before send'); - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); }.bind(this)); } else { - this.focusMessageField(); + this.focusMessageFieldAndClearDisabled(); } }, diff --git a/js/views/recorder_view.js b/js/views/recorder_view.js index 2fbe2ed84..b8ee2e114 100644 --- a/js/views/recorder_view.js +++ b/js/views/recorder_view.js @@ -28,6 +28,9 @@ this.$('.time').text(minutes + ':' + seconds); }, close: function() { + // Note: the 'close' event can be triggered by InboxView, when the user clicks + // anywhere outside the recording pane. + if (this.recorder.isRecording()) { this.recorder.cancelRecording(); }