app/assets/javascripts/backbone/views/chat/message.js.coffee
00f00dbe
 Xmpp.Views.Chat ||= {}
 
 class Xmpp.Views.Chat.MessageView extends Backbone.View
   template: JST["backbone/templates/chat/message"]
   className: 'message-box'
 
   initialize: (parts) ->
     _.bindAll(this)
 
     @user = parts.user
aa33d796
     @dateSent = parts.date
00f00dbe
     @message = parts.message
 
   render: ->
aa33d796
     $(@el).html(@template(username: @user.get('name'), avatar: @user.get('avatar'), date: @formatTime(), message: @message))
     return this
 
   formatTime:  ->
     nowDate = new Date()
     if (nowDate.getDate() != @dateSent.getDate() &&
         nowDate.getMonth() != @dateSent.getMonth() &&
         nowDate.getFullYear() != @dateSent.getFullYear())
       return @dateSent.getFullYear() + '/' + (@dateSent.getMonth()+1) + '/' + @dateSent.getDate() +
         ' @ ' + @dateSent.getHours() + ':' + @dateSent.getMinutes()
 
     return @dateSent.getHours() + ':' + @dateSent.getMinutes()