Refactor Contact and Conflict views

Untangle these two views into their component parts, consolidating all
the key conflict logic in the key conflict view. Contact view now simply
renders basic contact info and miscellaneous errors but not conflicts or
message errors.

// FREEBIE
This commit is contained in:
lilia 2016-02-17 11:59:20 -08:00
parent 1e1b87bbbd
commit 4ab2e25df6
5 changed files with 100 additions and 116 deletions

View file

@ -7,14 +7,18 @@
window.Whisper = window.Whisper || {};
Whisper.KeyConflictDialogueView = Whisper.View.extend({
className: 'key-conflict-dialogue clearfix',
templateName: 'key-conflict-dialogue',
className: 'key-conflict-dialogue clearfix',
initialize: function(options) {
this.contact = options.contact;
this.conflict = options.conflict;
this.conversation = options.conversation;
},
events: {
'click .verify': 'triggerVerify',
'click .resolve': 'resolve'
'click .conflict': 'showDialog',
'click .cancel' : 'cancel',
'click .verify' : 'triggerVerify',
'click .resolve' : 'resolve'
},
triggerVerify: function() {
this.trigger('verify', {identityKey: this.model.identityKey});
@ -24,10 +28,24 @@
this.remove();
this.conversation.resolveConflicts(this.model);
},
showDialog: function() {
this.$('.conflict').hide();
this.$('.cancel, .content').show();
},
cancel: function() {
this.$('.cancel, .content').hide();
this.$('.conflict').show();
},
render_attributes: function() {
return {
message: i18n('identityChanged'),
resolve: i18n('acceptNewKey'),
name : this.contact.getTitle(),
avatar : this.contact.getAvatar(),
conflict : this.conflict,
verify : i18n('verify'),
cancel : i18n('cancel'),
newIdentity : i18n('newIdentity'),
message : i18n('identityChanged'),
resolve : i18n('acceptNewKey'),
verifyContact: i18n('verifyContact')
};
}

View file

@ -18,29 +18,11 @@
});
},
events: {
'click .conflict': 'triggerConflict',
'click .cancel' : 'cancel'
},
triggerConflict: function() {
this.$el.trigger('conflict', {conflict: this.conflict, el: this.el});
this.$('.cancel').show();
this.$('.conflict').hide();
},
cancel: function() {
this.$('.key-conflict-dialogue').remove();
this.$('.cancel').hide();
this.$('.conflict').show();
},
render_attributes: function() {
return {
name : this.model.getTitle(),
avatar : this.model.getAvatar(),
conflict : this.conflict,
errors : this.errors,
verify : i18n('verify'),
cancel : i18n('cancel'),
newIdentity: i18n('newIdentity')
errors : this.errors
};
}
});
@ -57,7 +39,6 @@
},
events: {
'click .back': 'goBack',
'conflict': 'conflictDialogue',
'click .retry': 'retryMessage',
},
goBack: function() {
@ -84,19 +65,6 @@
return this.conversation.contactCollection.models;
}
},
conflictDialogue: function(e, data) {
var view = new Whisper.KeyConflictDialogueView({
model: data.conflict,
conversation: this.conversation
});
view.render().$el.appendTo(data.el);
this.listenTo(view, 'verify', function(data) {
this.verify(data.identityKey);
});
this.listenTo(view, 'resolve', function() {
this.render();
});
},
retryMessage: function() {
var retrys = _.filter(this.model.get('errors'), function(e) {
return (e.name === 'MessageError' ||
@ -108,18 +76,33 @@
}.bind(this));
},
renderContact: function(contact) {
var conflict = this.model.getKeyConflict(contact.id);
var v = new ContactView({
var view = new ContactView({
model: contact,
conflict: conflict,
errors: this.errors[contact.id]
}).render();
this.$('.contacts').append(view.el);
var conflict = this.model.getKeyConflict(contact.id);
if (conflict) {
this.$('.conflicts').append(v.el);
} else {
this.$('.contacts').append(v.el);
this.renderConflict(contact, conflict);
}
},
renderConflict: function(contact, conflict) {
var view = new Whisper.KeyConflictDialogueView({
model: conflict,
contact: contact,
conversation: this.conversation
}).render();
this.$('.conflicts').append(view.el);
this.listenTo(view, 'verify', function(data) {
this.verify(conflict.identityKey);
});
/*
this.listenTo(view, 'resolve', function() {
this.render();
});
*/
},
render: function() {
this.errors = _.groupBy(this.model.get('errors'), 'number');
var hasRetry = _.find(this.model.get('errors'), function(e) {