2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-02-23 21:17:50 +00:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-03-23 21:01:18 +00:00
|
|
|
var ContactView = Whisper.View.extend({
|
2015-02-18 02:03:05 +00:00
|
|
|
className: 'contact-detail',
|
2015-09-04 20:06:17 +00:00
|
|
|
templateName: 'contact-detail',
|
2015-02-18 02:03:05 +00:00
|
|
|
initialize: function(options) {
|
|
|
|
this.conflict = options.conflict;
|
2015-10-03 01:31:07 +00:00
|
|
|
this.retry = _.find(options.errors, function(e) {
|
|
|
|
return (e.name === 'OutgoingMessageError' ||
|
|
|
|
e.name === 'SendMessageNetworkError');
|
|
|
|
});
|
2015-10-02 19:28:40 +00:00
|
|
|
this.errors = _.reject(options.errors, function(e) {
|
|
|
|
return (e.name === 'IncomingIdentityKeyError' ||
|
2015-10-03 01:31:07 +00:00
|
|
|
e.name === 'OutgoingIdentityKeyError' ||
|
|
|
|
e.name === 'OutgoingMessageError' ||
|
|
|
|
e.name === 'SendMessageNetworkError');
|
2015-10-02 19:28:40 +00:00
|
|
|
});
|
2015-02-18 02:03:05 +00:00
|
|
|
},
|
|
|
|
events: {
|
2015-10-03 01:31:07 +00:00
|
|
|
'click .conflict': 'triggerConflict',
|
|
|
|
'click .retry': 'triggerRetry'
|
2015-02-18 02:03:05 +00:00
|
|
|
},
|
|
|
|
triggerConflict: function() {
|
|
|
|
this.$el.trigger('conflict', {conflict: this.conflict});
|
|
|
|
},
|
2015-10-03 01:31:07 +00:00
|
|
|
triggerRetry: function() {
|
|
|
|
this.$el.trigger('retry', {error: this.retry});
|
|
|
|
},
|
2015-03-23 21:01:18 +00:00
|
|
|
render_attributes: function() {
|
|
|
|
return {
|
2015-06-19 00:05:00 +00:00
|
|
|
name : this.model.getTitle(),
|
|
|
|
avatar : this.model.getAvatar(),
|
2015-09-30 21:27:18 +00:00
|
|
|
conflict : this.conflict,
|
2015-10-03 01:31:07 +00:00
|
|
|
retry : this.retry,
|
2015-09-30 21:27:18 +00:00
|
|
|
errors : this.errors
|
2015-03-23 21:01:18 +00:00
|
|
|
};
|
2015-02-18 02:03:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Whisper.MessageDetailView = Backbone.View.extend({
|
2015-02-23 21:17:50 +00:00
|
|
|
className: 'message-detail',
|
2015-03-05 23:25:49 +00:00
|
|
|
template: $('#message-detail').html(),
|
2015-02-23 21:17:50 +00:00
|
|
|
initialize: function(options) {
|
|
|
|
this.view = new Whisper.MessageView({model: this.model});
|
|
|
|
this.conversation = options.conversation;
|
2015-03-18 23:26:55 +00:00
|
|
|
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
2015-02-23 21:17:50 +00:00
|
|
|
},
|
|
|
|
events: {
|
2015-02-27 02:10:04 +00:00
|
|
|
'click .back': 'goBack',
|
2015-10-03 01:31:07 +00:00
|
|
|
'conflict': 'conflictDialogue',
|
|
|
|
'retry': 'retryMessage',
|
2015-02-23 21:17:50 +00:00
|
|
|
},
|
|
|
|
goBack: function() {
|
|
|
|
this.trigger('back');
|
|
|
|
},
|
2015-07-20 21:15:38 +00:00
|
|
|
verify: function(their_key) {
|
|
|
|
textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber()).then(function(our_key) {
|
|
|
|
var view = new Whisper.KeyVerificationView({
|
|
|
|
model: { their_key: their_key, your_key: our_key }
|
|
|
|
});
|
|
|
|
this.$el.hide();
|
|
|
|
view.render().$el.insertAfter(this.el);
|
|
|
|
this.listenTo(view, 'back', function() {
|
|
|
|
view.remove();
|
|
|
|
this.$el.show();
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
2015-02-27 02:10:04 +00:00
|
|
|
},
|
2015-03-05 23:54:23 +00:00
|
|
|
contacts: function() {
|
|
|
|
if (this.model.isIncoming()) {
|
|
|
|
var number = this.model.get('source');
|
|
|
|
return [this.conversation.contactCollection.get(number)];
|
|
|
|
} else {
|
|
|
|
return this.conversation.contactCollection.models;
|
|
|
|
}
|
|
|
|
},
|
2015-02-18 02:03:05 +00:00
|
|
|
conflictDialogue: function(e, data) {
|
|
|
|
var view = new Whisper.KeyConflictDialogueView({
|
|
|
|
model: data.conflict,
|
|
|
|
conversation: this.conversation
|
|
|
|
});
|
|
|
|
view.render().$el.appendTo(this.$el);
|
|
|
|
this.listenTo(view, 'verify', function(data) {
|
2015-07-20 21:15:38 +00:00
|
|
|
this.verify(data.identityKey);
|
2015-02-18 02:03:05 +00:00
|
|
|
});
|
|
|
|
this.listenTo(view, 'resolve', function() {
|
|
|
|
this.render();
|
|
|
|
});
|
|
|
|
},
|
2015-10-03 01:31:07 +00:00
|
|
|
retryMessage: function(e, data) {
|
|
|
|
this.model.resend(data.error.number);
|
|
|
|
},
|
2015-09-30 21:21:19 +00:00
|
|
|
renderContact: function(contact) {
|
|
|
|
var v = new ContactView({
|
|
|
|
model: contact,
|
2015-09-30 21:27:18 +00:00
|
|
|
conflict: this.model.getKeyConflict(contact.id),
|
|
|
|
errors: this.errors[contact.id]
|
2015-09-30 21:21:19 +00:00
|
|
|
}).render().$el.appendTo(this.$('.contacts'));
|
|
|
|
},
|
2015-02-23 21:17:50 +00:00
|
|
|
render: function() {
|
2015-10-05 22:06:49 +00:00
|
|
|
this.errors = _.groupBy(this.model.get('errors'), 'number');
|
2015-02-23 21:17:50 +00:00
|
|
|
this.$el.html(Mustache.render(this.template, {
|
2015-02-18 02:03:05 +00:00
|
|
|
sent_at : moment(this.model.get('sent_at')).toString(),
|
|
|
|
received_at : moment(this.model.get('received_at')).toString(),
|
|
|
|
tofrom : this.model.isIncoming() ? 'From' : 'To',
|
2015-09-30 21:27:18 +00:00
|
|
|
errors : this.errors['undefined']
|
2015-02-23 21:17:50 +00:00
|
|
|
}));
|
2015-03-28 01:47:58 +00:00
|
|
|
this.view.render().$el.prependTo(this.$('.message-container'));
|
2015-02-18 02:03:05 +00:00
|
|
|
|
2015-03-23 23:12:25 +00:00
|
|
|
if (this.model.isOutgoing()) {
|
2015-09-30 21:21:19 +00:00
|
|
|
this.conversation.contactCollection.each(this.renderContact.bind(this));
|
2015-03-23 23:12:25 +00:00
|
|
|
} else {
|
2015-09-30 21:21:19 +00:00
|
|
|
this.renderContact(
|
|
|
|
this.conversation.contactCollection.get(this.model.get('source'))
|
|
|
|
);
|
2015-03-23 23:12:25 +00:00
|
|
|
}
|
2015-02-23 21:17:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|