       name: "topics"
       unclosable: true
       subItemClass: ChannelListItemView
-      items: [
-        {name: "erlang", status: "99 online"}
-        {name: "nodejs", status: "10 online"}
-        {name: "python", status: "25 online"}
-      ]
 
   ###
   # Called by ChatController to create a tab view for new channel


  pistachio:->
    """
    <div class='meta'>
      <span class="author-wrapper">{{#(author)}}</span>
      <span class='time'>{{$.timeago #(meta.createdAt)}}</span>
    </div>
    <div>{{#(body)}}</div>
    """

class ChannelListItemView extends KDListItemView

    @joinChannel 'public'

  joinChannel: (name) ->
    return @channels[name] if @channels[name]

    view = @getOptions().view
    channelPaneInstance = view.addChannelTab name
    channelName = "client-#{name}"

    channel = new Channel 
      name: name
      view: channelPaneInstance

    # Presence received has format [key, "bind" || "unbind"]
    mq.presence @username, name, ([presence, status]) =>
      if status is "bind"
        channel.addOnlineUser presence
      else if status is "unbind"
        channel.removeOfflineUser presence    

    channel.view.on "ChatMessageSent", (messageBody) =>
      @parseMessageForChannels messageBody
      @broadcastOwnMessage channel, messageBody

    @broadcaster.on channelName, (msg) ->
      channel.messageReceived msg

    @channels[name] = channel

  parseMessageForChannels: (message) ->
    topicExp = /#([\w]+)/g
    while match = topicExp.exec message
      channelName = match[1]
      channel = @joinChannel channelName
      @broadcastOwnMessage channel, message

  broadcastOwnMessage: (channel, messageBody) ->
    chatItem = 
      author: @username
      body: messageBody
      meta: {createdAt: new Date()}

    channelMQName = "client-#{channel.name}"
    @broadcaster.emit channelMQName, JSON.stringify(chatItem)
    chatItem.author = "me"
    channel.messageReceived chatItem

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

