/client/src/Conversation.js
enyo.kind({
name: "Conversation",
kind: "FittableRows",
classes: "conversation",
properties: {
jid: '',
name: '',
},
components: [
{kind: "onyx.Toolbar", components: [
{kind: "PresenceCircle"},
{name: "conversationJid", content: 'None'}
]},
{name: "messageList", kind: "DataList", fit: 1, components: [
{components: [
{name: "messageItem", kind: "MessageItem"}
], bindings: [
{from: "model.message", to: "$.messageItem.message"},
{from: "model.receivedTimestamp", to: "$.messageItem.receivedTimestamp"},
{from: "model.outbound", to: "$.messageItem.outbound"}
]}
]},
{kind: "onyx.Toolbar", classes: "table-fit", components: [
{components: [
{kind: "onyx.Grabber"},
]},
{kind: "onyx.InputDecorator", alwaysLooksFocused: true, classes: "conversation-input-decorator table-fit-fill", components: [
{name: "conversationInput", kind: "onyx.Input", classes: "conversation-input", onkeypress: "inputKeypress"}
]}
]},
{kind: "Signals", onMessageReceived: "messageReceived"}
],
create: function() {
this.inherited(arguments);
this.updateConversationList();
},
setJid: function(jid) {
this.jid = jid;
this.$.messageList.set('collection', conversationStore.getConversationCollection(jid));
this.$.conversationJid.setContent(jid);
this.$.messageList.reset();
this.updateConversationList();
},
setName: function(name) {
this.name = name;
this.$.conversationJid.setContent(name || this.jid);
},
updateConversationList: function() {
this.$.messageList.refresh();
/*
setTimeout(function() {
var lastIndex = this.$.messageList.data().length - 1;
this.$.messageList.scrollToIndex(lastIndex);
}.bind(this), 0);
*/
},
messageReceived: function(inSender, inEvent) {
if (inEvent.jid == this.jid) {
this.updateConversationList();
}
},
inputKeypress: function(inSender, inEvent) {
if (inEvent.keyCode == 13) {
var message = this.$.conversationInput.getValue();
this.$.conversationInput.setValue('');
var data = {
outbound: true,
jid: this.jid,
receivedTimestamp: (new Date()).getTime(),
message: message
};
conversationStore.appendConversation(this.jid, data);
enyo.Signals.send('onMessageSent', data);
this.updateConversationList();
}
}
});