   loadView:(mainView)->
     @joinChannel "@#{@username}"
     @joinChannel PUBLIC
-    #@joinChannel "#koding"
 
   joinChannel: (name) ->
-    return @channels[name] if @channels[name]
-
     view = @getOptions().view
     channelPaneInstance = view.addChannelTab name
+
+    if channel = @channels[name]      
+      return channel
 
     # When the tab is closed, remove the channel reference
     # and sign the user off from the channel

class Channel extends KDEventEmitter
  constructor: (options = {}, data) ->
    @messages = []
    @participants = {}
    @name = options.name
    @view = options.view

  addOnlineUser: (name) ->
    bongo.api.JAccount.one "profile.nickname" : name, (err, account)=>

  newMessage: (message) ->
    @chatController.getListView().addItem message

  isActive: ->
    @getDomElement().hasClass "active"

  setUnreadCount: (count) ->
    if count > 0
      title = "#{@name} (<span class='unread'>#{count}</span>)"
    else
      title = "#{@name}"

    @tabHandle.getDomElement().find("b").html title

class ChatListItemView extends KDListItemView
  viewAppended: ->
    @setTemplate @pistachio()
