Last active
July 17, 2017 09:08
-
-
Save lucasscariot/cb58e1c08b413e923330c7b93a927391 to your computer and use it in GitHub Desktop.
Forest - Conversation Smart View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import Ember from 'ember'; | |
import SmartViewMixin from 'client/mixins/smart-view-mixin'; | |
export default Ember.Component.extend(SmartViewMixin.default, { | |
conversations: function () { | |
this.set('currentConversation', this.get('records.firstObject')); | |
this.set('currentConversation', this.get('records.firstObject')); | |
return this.get('records'); | |
}.property('records'), | |
messages: function () { | |
let rightSenderId; | |
return this | |
.get('currentConversation') | |
.query('forest-messages', {}) | |
.then((messages) => { | |
rightSenderId = messages.get('lastObject.forest-sender.forest-_id'); | |
this.set('messages', messages | |
.map((message) => { | |
if (rightSenderId === message.get('forest-sender.forest-_id')) { | |
message.set('pos', 'right'); | |
} else { message.set('pos', 'left'); } | |
return message; | |
})); | |
}); | |
}.property('currentConversation'), | |
actions: { | |
switchConversation: function (conversation) { | |
this.set('currentConversation', conversation); | |
let rightSenderId; | |
conversation | |
.query('forest-messages', {}) | |
.then((messages) => { | |
rightSenderId = messages.get('lastObject.forest-sender.forest-_id'); | |
this.set('messages', messages | |
.map((message) => { | |
if (rightSenderId === message.get('forest-sender.forest-_id')) { | |
message.set('pos', 'right'); | |
} else { message.set('pos', 'left'); } | |
return message; | |
})); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment