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