Handle command input call message

This commit is contained in:
virvar 2016-04-08 18:43:09 +03:00
parent 5e38d5589a
commit c1dd4a9ab9
2 changed files with 22 additions and 15 deletions

View File

@ -17,7 +17,7 @@
set-chat-command-request]] set-chat-command-request]]
[syng-im.handlers.server :as server] [syng-im.handlers.server :as server]
[syng-im.handlers.contacts :as contacts-service] [syng-im.handlers.contacts :as contacts-service]
[syng-im.handlers.suggestions :refer [get-command]]
[syng-im.handlers.sign-up :as sign-up-service] [syng-im.handlers.sign-up :as sign-up-service]
[syng-im.models.chats :refer [create-chat]] [syng-im.models.chats :refer [create-chat]]
@ -128,20 +128,22 @@
(register-handler :send-chat-msg (register-handler :send-chat-msg
(fn [db [action chat-id text]] (fn [db [action chat-id text]]
(log/debug action "chat-id" chat-id "text" text) (log/debug action "chat-id" chat-id "text" text)
(let [msg (if (= chat-id "console") (if-let [command (get-command text)]
(sign-up-service/send-console-msg text) (dispatch [:set-chat-command (:command command)])
(let [{msg-id :msg-id (let [msg (if (= chat-id "console")
{from :from (sign-up-service/send-console-msg text)
to :to} :msg} (api/send-user-msg {:to chat-id (let [{msg-id :msg-id
:content text})] {from :from
{:msg-id msg-id to :to} :msg} (api/send-user-msg {:to chat-id
:from from :content text})]
:to to {:msg-id msg-id
:content text :from from
:content-type text-content-type :to to
:outgoing true}))] :content text
(save-message chat-id msg) :content-type text-content-type
(signal-chat-updated db chat-id)))) :outgoing true}))]
(save-message chat-id msg)
(signal-chat-updated db chat-id)))))
(register-handler :send-chat-command (register-handler :send-chat-command
(fn [db [action chat-id command content]] (fn [db [action chat-id command content]]

View File

@ -11,3 +11,8 @@
;; TODO change 'commands' to 'suggestions' ;; TODO change 'commands' to 'suggestions'
(filterv #(.startsWith (:text %) text) commands) (filterv #(.startsWith (:text %) text) commands)
[])) []))
(defn get-command [text]
(when (= (get text 0) "!")
;; TODO change 'commands' to 'suggestions'
(first (filter #(= (:text %) text) commands))))