 Channel instance.
 ###
 TOPICREGEX = /#([\w-]+)/g
+MENTIONREGEX = /@([\w-]+)/g
+
 class Chat12345 extends AppController
   {mq} = bongo
   PUBLIC = 'public'

      else if status is "unbind"
        channel.removeOfflineUser presence    

    channel.view.on "ChatMessageSent", (messageBody) =>
      @parseMessageForChannels messageBody, channel
      @broadcastOwnMessage messageBody, channel 
      if name isnt PUBLIC
        @broadcastOwnMessage messageBody, @channels[PUBLIC], channel

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

    @channels[name] = channel

  parseMessageForChannels: (message, fromChannel) ->
    while match = TOPICREGEX.exec message
      channelName = match[1]
      channel = @joinChannel channelName
      @broadcastOwnMessage message, channel, fromChannel

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

    chatItem.channel = "#"+fromChannel.name if fromChannel

    channelMQName = "client-#{toChannel.name}"
    @broadcaster.emit channelMQName, JSON.stringify(chatItem)


  loadView:(mainView)->
    @joinChannel PUBLIC
    @joinChannel "@#{@username}"

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

    view = @getOptions().view
    channelPaneInstance = view.addChannelTab name

    # When the tab is closed, remove the channel reference
    # and sign the user off from the channel
    channelPaneInstance.on "KDObjectWillBeDestroyed", =>
      delete @channels[name]
      mq.presenceOff @username, name
