 
   deselectMessages:->
     @selection = {}
-  
+
   sendMessage:(messageDetails, callback)->
-    log "I just send a new message: ", messageDetails
+    # log "I just send a new message: ", messageDetails
     bongo.api.JPrivateMessage.create messageDetails, callback
-  
+
   prepareMessage:(formOutput, callback)=>
     {body, subject, recipients} = formOutput
-    
+
     to = recipients.join ' '
-    
+
     @sendMessage {to, body, subject}, (err, message)->
       new KDNotificationView
         title     : if err then "There was an error sending your message - try again" else "Message Sent!"

      options :
        name : 'Inbox'
      data : @mainView
    
  initAndBringToFront:(options,callback)->
    initApplication options, ->
      @bringToFront() 
      callback()
  
  initApplication:(options, callback)->
    callback()
  
  fetchMessages:(options, callback)->
    # log "FETCH MESSAGES INTERNAL"
    {currentDelegate} = KD.getSingleton('mainController').getVisitor()
    currentDelegate.fetchMail? options, callback
  
  fetchAutoCompleteForToField:(inputValue,blacklist,callback)->
    bongo.api.JAccount.byRelevance inputValue,{blacklist},(err,accounts)->
      callback accounts  

  loadView:(mainView)->
    mainView.createCommons()
    mainView.createTabs()
    
    {currentDelegate} = KD.getSingleton('mainController').getVisitor()

    currentDelegate.fetchPrivateChannel (err, channel)->
      console.log channel

    # mainView.inboxMessagesList.on 'ReceivedClickElsewhere', =>
    #   @deselectMessages()

          , callback
          disownItem item for own id, item of items
        (pubInst, modal) =>
          # log modal
          disownAll @selection, =>
            # log "2", modal
            for own id, {item, paneView} of @selection
              item.destroy()
              paneView.destroy()
              @deselectMessages()
            modal.destroy()
            newMessageBar.disableMessageActionButtons()

    newMessageBar.registerListener
      KDEventTypes: 'MessageShouldBeMarkedAsUnread'
      listener    : @
      callback    : =>
        for own id, {item, data} of @selection
          # log 'marking unread'
          data.unmark 'read', (err)=>
            log err if err
            item.setClass 'unread' unless err
            newMessageBar.disableMessageActionButtons()

  goToNotifications:(notification)->
    @getView().showTab "notifications"
    @mainView.propagateEvent KDEventType : 'NotificationIsSelected', {item: notification, event} if notification?

  goToMessages:(message)->
    @getView().showTab "messages"
    @mainView.propagateEvent KDEventType : "MessageIsSelected", {item: message, event} if message?
