 				nextBeforeTimestamp: null
 				newMessage: null
 		}
+		
+		justSent = false	
+		ide.socket.on "new-chat-message", (message) =>
+			if message.user.id == ide.$scope.user.id and justSent
+				# Nothing to do
+			else
+				ide.$scope.$apply () ->
+					appendMessage(message)
+			justSent = false
 			
-		ide.socket.on "new-chat-message", (message) =>
-			ide.$scope.$apply () ->
-				chat.state.newMessage = message
-				appendMessage(message)
+		chat.sendMessage = (message) ->
+			body = 
+				content: message
+				_csrf : window.csrfToken
+			justSent = true
+			appendMessage({
+				user: ide.$scope.user
+				content: message
+				timestamp: Date.now()
+			})
+			return $http.post(MESSAGES_URL, body)
 			
 		chat.loadMoreMessages = () ->
 			return if chat.state.atEnd

				prependMessage(message)
				
		appendMessage = (message) ->
			lastMessage = chat.state.messages[chat.state.messages.length - 1]
			shouldGroup = lastMessage? and
				lastMessage.user.id == message.user.id and

					contents: [message.content]
				})
					
		return chat