2024-10-12 19:53:34 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(in-package #:live-chat-routes)
|
|
|
|
|
|
|
|
;; Define a app for routing
|
|
|
|
(defparameter *app* (make-instance 'ningle:app))
|
|
|
|
|
|
|
|
;; Route to render the chat UI
|
|
|
|
(setf (ningle:route *app* "/" :method :GET)
|
|
|
|
#'(lambda (params)
|
|
|
|
(declare (ignore params))
|
2024-10-14 05:34:03 -04:00
|
|
|
(live-chat-ui:render-chat-ui))
|
2024-10-12 19:53:34 -04:00
|
|
|
|
2024-10-14 05:34:03 -04:00
|
|
|
;; Route for chat messages
|
|
|
|
(ningle:route *app* "/chat-messages" :method :GET)
|
2024-10-12 19:53:34 -04:00
|
|
|
#'(lambda (params)
|
|
|
|
(declare (ignore params))
|
2024-10-14 05:34:03 -04:00
|
|
|
(live-chat-ui:render-chat-messages))
|
2024-10-12 19:53:34 -04:00
|
|
|
|
2024-10-14 05:34:03 -04:00
|
|
|
;; Route for posting messages
|
|
|
|
(ningle:route *app* "/post-message" :method :POST)
|
2024-10-12 19:53:34 -04:00
|
|
|
#'(lambda (params)
|
|
|
|
(let ((message (cdr (assoc "message" params :test 'equal))))
|
|
|
|
(when (and message (not (string= message "")))
|
2024-10-14 05:34:03 -04:00
|
|
|
(live-chat-ws:handle-post-message message)))
|
2024-10-12 19:53:34 -04:00
|
|
|
(live-chat-ui:render-chat-messages)))
|