 
   update: (data) ->
     _.extend(this, data.user)
-    @courses = _.map data.courses, (course) -> new Course(course)
+    @courses = _.map data.courses, (course) => new Course(@, course)
     @channel.emit('change')
 
   logout: ->

  is_customer_service: false
  name: null
  profile_url: null

User =


    @channel.emit('change')

  getCourse: (collectionUUID) ->
    _.findWhere( @courses, ecosystem_book_uuid: collectionUUID )

  findOrCreateCourse: (collectionUUID) ->
    @getCourse(collectionUUID) or (
      course = new Course(@, ecosystem_book_uuid: collectionUUID)
      @courses.push(course)
      course
    )

  ensureStatusLoaded: ->
    api.channel.emit("user.send.statusUpdate") unless @isLoggedIn()

  isLoggedIn: -> !!@profile_url

  onCourseUpdate: (course) ->
    @channel.emit('change')

api.channel.on 'user.receive.*', ({data}) ->
  User.update(loaded: true)
