2015-09-07 14:53:43 -07:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-02-23 13:17:50 -08:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-03-23 14:01:18 -07:00
|
|
|
var ContactView = Whisper.View.extend({
|
2015-02-17 18:03:05 -08:00
|
|
|
className: 'contact-detail',
|
2015-09-04 13:06:17 -07:00
|
|
|
templateName: 'contact-detail',
|
2015-02-17 18:03:05 -08:00
|
|
|
initialize: function(options) {
|
|
|
|
this.conflict = options.conflict;
|
2015-10-02 12:28:40 -07:00
|
|
|
this.errors = _.reject(options.errors, function(e) {
|
|
|
|
return (e.name === 'IncomingIdentityKeyError' ||
|
2016-02-16 10:43:44 -08:00
|
|
|
e.name === 'OutgoingIdentityKeyError' ||
|
|
|
|
e.name === 'OutgoingMessageError' ||
|
|
|
|
e.name === 'SendMessageNetworkError');
|
2015-10-02 12:28:40 -07:00
|
|
|
});
|
2016-02-14 22:41:52 -08:00
|
|
|
|
2015-02-17 18:03:05 -08:00
|
|
|
},
|
2015-03-23 14:01:18 -07:00
|
|
|
render_attributes: function() {
|
|
|
|
return {
|
2015-06-18 17:05:00 -07:00
|
|
|
name : this.model.getTitle(),
|
|
|
|
avatar : this.model.getAvatar(),
|
2016-02-17 11:59:20 -08:00
|
|
|
errors : this.errors
|
2015-03-23 14:01:18 -07:00
|
|
|
};
|
2015-02-17 18:03:05 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-08 15:01:29 -08:00
|
|
|
Whisper.MessageDetailView = Whisper.View.extend({
|
2016-03-21 15:37:53 -07:00
|
|
|
className: 'message-detail panel',
|
2015-12-08 15:01:29 -08:00
|
|
|
templateName: 'message-detail',
|
2015-02-23 13:17:50 -08:00
|
|
|
initialize: function(options) {
|
|
|
|
this.view = new Whisper.MessageView({model: this.model});
|
2015-11-05 20:11:28 -08:00
|
|
|
this.view.render();
|
2015-02-23 13:17:50 -08:00
|
|
|
this.conversation = options.conversation;
|
2015-03-18 16:26:55 -07:00
|
|
|
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
2015-02-23 13:17:50 -08:00
|
|
|
},
|
2015-03-05 15:54:23 -08: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-09-30 14:21:19 -07:00
|
|
|
renderContact: function(contact) {
|
2016-02-17 11:59:20 -08:00
|
|
|
var view = new ContactView({
|
2015-09-30 14:21:19 -07:00
|
|
|
model: contact,
|
2015-09-30 14:27:18 -07:00
|
|
|
errors: this.errors[contact.id]
|
2015-10-10 16:41:44 -07:00
|
|
|
}).render();
|
2016-02-17 11:59:20 -08:00
|
|
|
this.$('.contacts').append(view.el);
|
|
|
|
|
|
|
|
var conflict = this.model.getKeyConflict(contact.id);
|
2016-02-14 16:46:28 -08:00
|
|
|
if (conflict) {
|
2016-02-17 11:59:20 -08:00
|
|
|
this.renderConflict(contact, conflict);
|
2016-02-14 16:46:28 -08:00
|
|
|
}
|
2015-09-30 14:21:19 -07:00
|
|
|
},
|
2016-02-17 11:59:20 -08:00
|
|
|
renderConflict: function(contact, conflict) {
|
|
|
|
var view = new Whisper.KeyConflictDialogueView({
|
|
|
|
model: conflict,
|
|
|
|
contact: contact,
|
|
|
|
conversation: this.conversation
|
|
|
|
}).render();
|
|
|
|
this.$('.conflicts').append(view.el);
|
|
|
|
},
|
2015-02-23 13:17:50 -08:00
|
|
|
render: function() {
|
2015-10-05 15:06:49 -07:00
|
|
|
this.errors = _.groupBy(this.model.get('errors'), 'number');
|
2016-02-16 10:43:44 -08:00
|
|
|
var unknownErrors = this.errors['undefined'];
|
|
|
|
if (unknownErrors) {
|
|
|
|
unknownErrors = unknownErrors.filter(function(e) {
|
|
|
|
return (e.name !== 'MessageError');
|
|
|
|
});
|
2016-02-14 16:46:28 -08:00
|
|
|
}
|
2015-12-08 15:01:29 -08:00
|
|
|
this.$el.html(Mustache.render(_.result(this, 'template', ''), {
|
2015-02-17 18:03:05 -08:00
|
|
|
sent_at : moment(this.model.get('sent_at')).toString(),
|
2015-12-20 23:32:39 -08:00
|
|
|
received_at : this.model.isIncoming() ? moment(this.model.get('received_at')).toString() : null,
|
2016-01-08 19:36:34 +01:00
|
|
|
tofrom : this.model.isIncoming() ? i18n('from') : i18n('to'),
|
2016-02-16 10:43:44 -08:00
|
|
|
errors : unknownErrors,
|
2015-12-24 22:55:53 -08:00
|
|
|
title : i18n('messageDetail'),
|
|
|
|
sent : i18n('sent'),
|
|
|
|
received : i18n('received'),
|
2016-01-08 06:19:09 -08:00
|
|
|
errorLabel : i18n('error'),
|
2016-02-16 10:41:10 -08:00
|
|
|
hasConflict : this.model.hasKeyConflicts()
|
2015-02-23 13:17:50 -08:00
|
|
|
}));
|
2015-11-05 20:11:28 -08:00
|
|
|
this.view.$el.prependTo(this.$('.message-container'));
|
2015-02-17 18:03:05 -08:00
|
|
|
|
2015-03-23 16:12:25 -07:00
|
|
|
if (this.model.isOutgoing()) {
|
2015-10-08 06:13:36 -07:00
|
|
|
this.conversation.contactCollection.reject(function(c) {
|
|
|
|
return c.id === textsecure.storage.user.getNumber();
|
2015-10-10 16:41:44 -07:00
|
|
|
}).forEach(this.renderContact.bind(this));
|
2015-03-23 16:12:25 -07:00
|
|
|
} else {
|
2015-09-30 14:21:19 -07:00
|
|
|
this.renderContact(
|
|
|
|
this.conversation.contactCollection.get(this.model.get('source'))
|
|
|
|
);
|
2015-03-23 16:12:25 -07:00
|
|
|
}
|
2015-02-23 13:17:50 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|