 
   render: =>
     @$el.html @template
-    @messageListView = new MessageListView collection: @model.get('messages')
+    @messageListView = new MessageListView collection: @model.messages
     @messageListView.$el = @.$('.messages')
     @messageListView.render()
     @messageListView.scrollToBottom()

class Message extends Backbone.Model

class Messages extends Backbone.Collection
  model: Message

class Conversation extends Backbone.Model
  urlRoot: '/bb/conversations'

  getViewUrl: ->
    '/bb/c/' + @get('id') + '/'

  parse: (response, options) ->
    response.messages = new Messages response.messages
    return response

class Conversations extends Backbone.Collection
  model: Conversation
  url: '/bb/conversations'

class ConversationItemView extends Backbone.View
  className: 'conversation'
  template: _.template $('#conversation-view').html()

  render: ->
    @$el.html @template()
    this

class ConversationListView extends Backbone.View
  template: _.template $('#conversation-list-view').html()

  initialize: ->
    @collection = new Conversations
    @listenTo @collection, 'update', @render
    @collection.fetch()
    return

  render: =>

    data = _.object _.map $(event.target).serializeArray(), _.values
    message = new Message text: data.text
    message.url = "/bb/conversations/#{@id}/messages"
    message.save null,
      beforeSend: (xhr) ->
        xhr.setRequestHeader 'X-CSRFToken', data.csrfmiddlewaretoken
      success: =>
        @$el.find('textarea') .val ''
