Plumb contact avatars into conversations

pull/749/head
lilia 10 years ago
parent 019a9d1fbc
commit 8e54aa1401

@ -48,7 +48,7 @@
</script> </script>
<script type='text/x-tmpl-mustache' id='message'> <script type='text/x-tmpl-mustache' id='message'>
<div class='sender'>{{ sender }}</div> <div class='sender'>{{ sender }}</div>
<img class='avatar' src='{{ contact_avatar }}'> <span class='avatar'></span>
<div class="bubble"> <div class="bubble">
<p class="content">{{ message }}</p> <p class="content">{{ message }}</p>
<div class='attachments'></div> <div class='attachments'></div>

@ -32,8 +32,10 @@
}, },
initialize: function() { initialize: function() {
this.messageCollection = new Whisper.MessageCollection();
this.contactCollection = new Whisper.ConversationCollection(); this.contactCollection = new Whisper.ConversationCollection();
this.messageCollection = new Whisper.MessageCollection([], {
conversation: this
});
}, },
validate: function(attributes, options) { validate: function(attributes, options) {

@ -42,6 +42,9 @@
}, },
isIncoming: function() { isIncoming: function() {
return this.get('type') === 'incoming'; return this.get('type') === 'incoming';
},
getContact: function() {
return this.collection.conversation.contactCollection.get(this.get('source'));
} }
}); });
@ -50,6 +53,11 @@
database : Whisper.Database, database : Whisper.Database,
storeName : 'messages', storeName : 'messages',
comparator : 'received_at', comparator : 'received_at',
initialize : function(models, options) {
if (options) {
this.conversation = options.conversation;
}
},
destroyAll : function () { destroyAll : function () {
return Promise.all(this.models.map(function(m) { return Promise.all(this.models.map(function(m) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {

@ -48,14 +48,26 @@
return text.replace(/(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi, "$1<a href='$2' target='_blank'>$2</a>"); return text.replace(/(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi, "$1<a href='$2' target='_blank'>$2</a>");
}, },
render: function() { render: function() {
var contact = this.model.getContact();
this.$el.html( this.$el.html(
Mustache.render(this.template, { Mustache.render(this.template, {
message: this.model.get('body'), message: this.model.get('body'),
timestamp: moment(this.model.get('received_at')).fromNow(), timestamp: moment(this.model.get('received_at')).fromNow(),
sender: this.model.get('source') sender: (contact && contact.getTitle()) || ''
}) })
); );
var avatar;
if (contact && contact.get('avatar')) {
avatar = new Whisper.AttachmentView({
model: contact.get('avatar')
}).render().el;
}
else {
avatar = $('<img>').attr('src', '/images/default.png');
}
this.$el.find('.avatar').append(avatar);
twemoji.parse(this.el, { base: '/components/twemoji/', size: 16 }); twemoji.parse(this.el, { base: '/components/twemoji/', size: 16 });
var content = this.$el.find('.content'); var content = this.$el.find('.content');

@ -185,11 +185,11 @@
} }
} }
.outgoing img.avatar { .outgoing .avatar {
display: none; display: none;
} }
img.avatar { .avatar img {
height: 36px; height: 36px;
width: 36px; width: 36px;
background: $grey_l; background: $grey_l;

@ -447,11 +447,11 @@ input.new-message {
.message-detail .attachments video, .message-detail .attachments video,
.message-list .attachments video { .message-list .attachments video {
background: black; } background: black; }
.message-detail .outgoing img.avatar, .message-detail .outgoing .avatar,
.message-list .outgoing img.avatar { .message-list .outgoing .avatar {
display: none; } display: none; }
.message-detail img.avatar, .message-detail .avatar img,
.message-list img.avatar { .message-list .avatar img {
height: 36px; height: 36px;
width: 36px; width: 36px;
background: #f3f3f3; background: #f3f3f3;

Loading…
Cancel
Save