 
   getInitialState: ->
     return {
-      currentList: 0
+      currentListIndex: 0
     }
 
   _onSend: (content) ->
-    currentMessageList = @props.messageLists[@state.currentList]
-    previousId = currentMessageList[currentMessageList.length - 1]
-    parentId = @props.messages[previousId].metadata.ParentId
-    @props.sendMessage @props.threadId, content, 0, parentId
+    getParentId = (listIndex) =>
+      currentMessageList = @props.messageLists[listIndex]
+      previousId = currentMessageList[currentMessageList.length - 1]
+      return @props.messages[previousId].metadata.ParentId
+
+    if @state.currentListIndex >= @props.messageLists.length
+      # We have a new fork. Send a type 1 message first
+      # TODO: Let this fork from any branch
+      parentId = getParentId 0
+      @props.sendMessage(@props.threadId, '', 1, parentId).done (response) =>
+        if response.ok
+          parentId = response.body.message.id
+          @props.sendMessage @props.threadId, content, 0, parentId
+
+    else
+      parentId = getParentId @state.currentListIndex
+      @props.sendMessage @props.threadId, content, 0, parentId
+
+  _onCurrentListIndexUpdate: ->
+    currentListIndex = parseInt @refs.currentListIndexTextField.getValue(), 10
+    @setState {currentListIndex}
 
   # Return if we have the message
   _hasMessage: (messageId) ->

React = require 'react'
{Paper} = require 'material-ui'

ChatBox = require './thread/chat_box'



  _renderMessage: (messageId) ->
    {metadata, data} = @props.messages[messageId]
    # Don't render fork messages
    if metadata.type != 0
      return ''

    username = "Unknown"
    if metadata.AuthorId of @props.users
      username = @props.users[metadata.AuthorId].username
