Fix search view conversation reset bug
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`.
This commit is contained in:
parent
d6ea158e46
commit
b24dad23ea
2 changed files with 14 additions and 18 deletions
|
@ -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',
|
||||
|
|
|
@ -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) => {
|
||||
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();
|
||||
});
|
||||
} else {
|
||||
this.new_contact_view.$('.number').text(i18n('invalidNumberError'));
|
||||
this.$input.focus();
|
||||
}
|
||||
},
|
||||
|
||||
reset() {
|
||||
|
|
Loading…
Reference in a new issue