-- | Get a message from the user and send it to all listeners.
postSendR :: YesodChat master => Handler master ()
postSendR = lift chatIdent >>= traverse_ f
    where f ident = do
                Chat chan <- getYesod
                body      <- lift (runInputGet $ ireq textField "message")
                message   <- lift $ chatCreateMsg ident body

                -- Set nginx-specific header for eventsource to work.
                addHeader "X-Accel-Buffering" "no"

                -- Send an event to all listeners with the user's name and message.
                liftIO $ writeChan chan $ ServerEvent Nothing Nothing
                                          [chatRenderMsg message]

-- | Send an eventstream response with all messages streamed in.
postSendR :: YesodChat master => Handler master ()
postSendR = lift chatIdent >>= traverse_ f
    where f ident = do
                Chat chan <- getYesod
                body      <- lift (runInputGet $ ireq textField "message")
                message   <- lift $ chatCreateMsg ident body

                -- Set nginx-specific header for eventsource to work.
                addHeader "X-Accel-Buffering" "no"

                -- Send an event to all listeners with the user's name and message.
                liftIO $ writeChan chan $ ServerEvent Nothing Nothing
                                          [chatRenderMsg message]

-- | Send an eventstream response with all messages streamed in.
postSendR = lift chatIdent >>= traverse_ f
    where f ident = do
                Chat chan <- getYesod
                body      <- lift (runInputGet $ ireq textField "message")
                message   <- lift $ chatCreateMsg ident body

                -- Set nginx-specific header for eventsource to work.
                addHeader "X-Accel-Buffering" "no"

                -- Send an event to all listeners with the user's name and message.
                liftIO $ writeChan chan $ ServerEvent Nothing Nothing
                                          [chatRenderMsg message]

-- | Send an eventstream response with all messages streamed in.