Skip to content

Commit

Permalink
Improve UI around Voice Message limits
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-signal authored and scottnonnenberg-signal committed Feb 21, 2020
1 parent 148aede commit 2138395
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
15 changes: 15 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@
"message": "Original message found, but not loaded. Scroll up to load it.",
"description": "Shown in toast if user clicks on quote references messages not loaded in view, but in database"
},
"voiceRecordingInterruptedMax": {
"message": "Voice message recording stopped because the maximum time limit was reached.",
"description": "Confirmation dialog message for when the voice recording is interrupted due to max time limit"
},
"voiceRecordingInterruptedBlur": {
"message": "Voice message recording stopped because you switched to another app.",
"description": "Confirmation dialog message for when the voice recording is interrupted due to app losing focus"
},
"voiceNoteLimit": {
"message": "Voice messages are limited to five minutes. Recording will stop if you switch to another app.",
"description": "Shown in toast to warn user about limited time and that window must be in focus"
},
"voiceNoteMustBeOnlyAttachment": {
"message": "A voice message must have only one attachment.",
"description": "Shown in toast if tries to record a voice note with any staged attachments"
Expand Down Expand Up @@ -863,6 +875,9 @@
"cancel": {
"message": "Cancel"
},
"discard": {
"message": "Discard"
},
"failedToSend": {
"message": "Failed to send to some recipients. Check your network connection."
},
Expand Down
21 changes: 21 additions & 0 deletions js/views/conversation_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
return { toastMessage: i18n('messageFoundButNotLoaded') };
},
});
Whisper.VoiceNoteLimit = Whisper.ToastView.extend({
render_attributes() {
return { toastMessage: i18n('voiceNoteLimit') };
},
});
Whisper.VoiceNoteMustBeOnlyAttachmentToast = Whisper.ToastView.extend({
render_attributes() {
return { toastMessage: i18n('voiceNoteMustBeOnlyAttachment') };
Expand Down Expand Up @@ -1650,6 +1655,8 @@
return;
}

this.showToast(Whisper.VoiceNoteLimit);

// Note - clicking anywhere will close the audio capture panel, due to
// the onClick handler in InboxView, which calls its closeRecording method.

Expand All @@ -1663,6 +1670,7 @@
const view = this.captureAudioView;
view.render();
view.on('send', this.handleAudioCapture.bind(this));
view.on('confirm', this.handleAudioConfirm.bind(this));
view.on('closed', this.endCaptureAudio.bind(this));
view.$el.appendTo(this.$('.capture-audio'));
view.$('.finish').focus();
Expand All @@ -1671,6 +1679,19 @@
this.disableMessageField();
this.$('.microphone').hide();
},
handleAudioConfirm(blob, lostFocus) {
const dialog = new Whisper.ConfirmationDialogView({
cancelText: i18n('discard'),
message: lostFocus ? i18n('voiceRecordingInterruptedBlur') : i18n('voiceRecordingInterruptedMax'),
okText: i18n('sendAnyway'),
resolve: async () => {
await this.handleAudioCapture(blob);
},
});

this.$el.prepend(dialog.el);
dialog.focusCancel();
},
async handleAudioCapture(blob) {
if (this.hasFiles()) {
throw new Error('A voice note cannot be sent with other attachments');
Expand Down
10 changes: 10 additions & 0 deletions js/views/recorder_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
close: 'close',
},
onSwitchAway() {
this.lostFocus = true;
this.recorder.finishRecording();
this.close();
},
handleKeyDown(event) {
Expand Down Expand Up @@ -89,11 +91,14 @@
handleBlob(recorder, blob) {
if (blob && this.clickedFinish) {
this.trigger('send', blob);
} else if (blob) {
this.trigger('confirm', blob, this.lostFocus);
} else {
this.close();
}
},
start() {
this.lostFocus = false;
this.clickedFinish = false;
this.context = new AudioContext();
this.input = this.context.createGain();
Expand All @@ -103,6 +108,7 @@
});
this.recorder.onComplete = this.handleBlob.bind(this);
this.recorder.onError = this.onError.bind(this);
this.recorder.onTimeout = this.onTimeout.bind(this);
navigator.webkitGetUserMedia(
{ audio: true },
stream => {
Expand All @@ -113,6 +119,10 @@
);
this.recorder.startRecording();
},
onTimeout() {
this.recorder.finishRecording();
this.close();
},
onError(error) {
// Protect against out-of-band errors, which can happen if the user revokes media
// permissions after successfully accessing the microphone.
Expand Down
4 changes: 2 additions & 2 deletions ts/util/lint/exceptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@
"rule": "jQuery-$(",
"path": "js/views/recorder_view.js",
"line": " this.$('.time').text(`${minutes}:${seconds}`);",
"lineNumber": 49,
"lineNumber": 50,
"reasonCategory": "usageTrusted",
"updated": "2018-09-19T21:59:32.770Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -802,7 +802,7 @@
"rule": "jQuery-$(",
"path": "js/views/recorder_view.js",
"line": " $(window).off('blur', this.onSwitchAwayBound);",
"lineNumber": 80,
"lineNumber": 81,
"reasonCategory": "usageTrusted",
"updated": "2018-10-11T19:22:47.331Z",
"reasonDetail": "Operating on already-existing DOM elements"
Expand Down

0 comments on commit 2138395

Please sign in to comment.