From b24dad23ea4eb414eed90a3ffbff86b33bb029ca Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 27 Mar 2018 19:04:55 -0400 Subject: [PATCH] Fix search view conversation reset bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When searching for an existing conversation using a phone number, it’s possible to click on ‘Start conversation…’ and have that new dummy entry overwrite the existing conversation. This change ensures we are always showing a dummy conversation model that is not part of the conversation collection. Adding it is always idempotent as it goes through `getOrCreateAndWait`. --- Gruntfile.js | 1 + js/views/conversation_search_view.js | 31 ++++++++++++---------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index efae449abee1..78cba0c41a9c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -106,6 +106,7 @@ module.exports = function(grunt) { '!js/logging.js', '!js/backup.js', '!js/modules/**/*.js', + '!js/views/conversation_search_view.js', '!js/views/debug_log_view.js', '!js/signal_protocol_store.js', '!js/database.js', diff --git a/js/views/conversation_search_view.js b/js/views/conversation_search_view.js index 15649e9330fd..7a0cbb114322 100644 --- a/js/views/conversation_search_view.js +++ b/js/views/conversation_search_view.js @@ -89,32 +89,27 @@ this.new_contact_view.undelegateEvents(); this.new_contact_view.$el.hide(); } - // Creates a view to display a new contact + const model = new Whisper.Conversation({ type: 'private' }); this.new_contact_view = new Whisper.NewContactView({ el: this.$new_contact, - model: ConversationController.dangerouslyCreateAndAdd({ - type: 'private', - }), + model, }).render(); }, - createConversation() { - if (this.new_contact_view.model.isValid()) { - // NOTE: Temporarily allow `then` until we convert the entire file - // to `async` / `await`: - // eslint-disable-next-line more/no-then - ConversationController.getOrCreateAndWait( - this.new_contact_view.model.id, - 'private' - ).then((conversation) => { - this.trigger('open', conversation); - this.initNewContact(); - this.resetTypeahead(); - }); - } else { + async createConversation() { + const isValidNumber = this.new_contact_view.model.isValid(); + if (!isValidNumber) { this.new_contact_view.$('.number').text(i18n('invalidNumberError')); this.$input.focus(); + return; } + + const newConversationId = this.new_contact_view.model.id; + const conversation = + await ConversationController.getOrCreateAndWait(newConversationId, 'private'); + this.trigger('open', conversation); + this.initNewContact(); + this.resetTypeahead(); }, reset() {