diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 253342baee..4023473b83 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -68,7 +68,7 @@ (update-input-text db text)) (defn update-command [db [_ text]] - (let [{:keys [command]} (suggestions/check-suggestion db text)] + (let [[command] (suggestions/check-suggestion db text)] (commands/set-chat-command db command))) (register-handler :set-chat-input-text @@ -99,7 +99,7 @@ (defn prepare-message [{:keys [identity current-chat-id] :as db} _] (let [text (get-in db [:chats current-chat-id :input-text]) - {:keys [command]} (suggestions/check-suggestion db (str text " ")) + [command] (suggestions/check-suggestion db (str text " ")) message (check-author-direction db current-chat-id {:msg-id (random/id) diff --git a/src/status_im/chat/suggestions.cljs b/src/status_im/chat/suggestions.cljs index c5a0a8a53b..842a64ea32 100644 --- a/src/status_im/chat/suggestions.cljs +++ b/src/status_im/chat/suggestions.cljs @@ -20,10 +20,7 @@ [{:keys [current-chat-id] :as db} text] (let [commands (get-in db [:chats current-chat-id :commands])] (if (suggestion? text) - ;; TODO change 'commands' to 'suggestions' - (->> commands - vals - (filter (can-be-suggested? text))) + (filter (fn [[_ v]] ((can-be-suggested? text) v)) commands) []))) (defn get-command [db text] @@ -55,10 +52,10 @@ (defn check-suggestion [db message] (when-let [suggestion-text (when (string? message) (re-matches #"^![^\s]+\s" message))] - (let [suggestion-text' (s/trim suggestion-text) - [suggestion] (filter #(= suggestion-text' (:text %)) - (get-commands db))] - suggestion))) + (let [suggestion-text' (s/trim suggestion-text)] + (->> (get-commands db) + (filter #(= suggestion-text' (->> % second :name (str "!")))) + first)))) (defn typing-command? [db] (-> db diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index 2b550dc7bf..039f949c9b 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -32,7 +32,7 @@ [content-suggestions-view] [view st/command-input-container [view (st/command-text-container command) - [text {:style st/command-text} (:text command)]] + [text {:style st/command-text} (str "!" (:name command))]] [text-input (merge {:style st/command-input :autoFocus true :onChangeText set-input-message diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index ceb430fc76..0b6494acf8 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -73,7 +73,7 @@ (dispatch [:set-response-chat-command msg-id (:command command)])) (defn label [{:keys [command]}] - (->> (name command) + (->> (when command (name command)) (str "request-"))) (defn message-content-command-request diff --git a/src/status_im/chat/views/staged_command.cljs b/src/status_im/chat/views/staged_command.cljs index be8c811459..92f72b0508 100644 --- a/src/status_im/chat/views/staged_command.cljs +++ b/src/status_im/chat/views/staged_command.cljs @@ -16,7 +16,7 @@ [view st/staged-command-background [view st/staged-command-info-container [view (st/staged-command-text-container command) - [text {:style st/staged-command-text} (:text command)]] + [text {:style st/staged-command-text} (str "!" (:name command))]] [touchable-highlight {:style st/staged-command-cancel :onPress #(cancel-command-input staged-command)} [image {:source res/icon-close-gray diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 039554d390..67c55ff148 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -14,17 +14,18 @@ (dispatch [:set-chat-command command])) (defn suggestion-list-item - [{:keys [description] - label :name - :as suggestion}] - [touchable-highlight - {:onPress #(set-command-input (keyword label))} - [view st/suggestion-container - [view st/suggestion-sub-container - [view (st/suggestion-background suggestion) - [text {:style st/suggestion-text} label]] - [text {:style st/value-text} label] - [text {:style st/description-text} description]]]]) + [[command {:keys [description] + name :name + :as suggestion}]] + (let [label (str "!" name)] + [touchable-highlight + {:onPress #(set-command-input command)} + [view st/suggestion-container + [view st/suggestion-sub-container + [view (st/suggestion-background suggestion) + [text {:style st/suggestion-text} label]] + [text {:style st/value-text} label] + [text {:style st/description-text} description]]]])) (defn render-row [row _ _] (list-item [suggestion-list-item row])) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index 66e2528ea5..75811d9656 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -51,11 +51,28 @@ (defn json->clj [json] (js->clj (.parse js/JSON json) :keywordize-keys true)) +;; todo remove this +(def res {:commands {:location {:description "Send location" + :color "#9a5dcf" + :name "location"} + :phone {:description "Send phone number" + :color "#5fc48d" + :name "phone"} + :help {:description "Help" :color "#9a5dcf" :name "help"}} + :responses {:money {:description "Send money" :color "#5fc48d" :name "money"} + :confirmation-code {:description "Confirmation code" + :color "#7099e6" + :name "confirmationCode"} + :keypair-password {:description "" + :color "#7099e6" + :name "keypair-password"}}}) + (defn parse-commands! [_ [identity file]] (parse file (fn [result] (let [commands (json->clj result)] - (dispatch [::add-commands identity file commands]))) + ;; todo use commands from jail + (dispatch [::add-commands identity file res]))) #(dispatch [::loading-failed! identity ::error-in-jail %]))) (defn validate-hash diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index acb9be9b6c..2fd7e586c4 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -96,7 +96,6 @@ (remove #(identities (:whisper-identity %))) (map #(vector (:whisper-identity %) %)) (into {}))] - (println new-contacts') (-> db (update :contacts merge new-contacts') (assoc :new-contacts (vals new-contacts'))))) diff --git a/src/status_im/handlers/content_suggestions.cljs b/src/status_im/handlers/content_suggestions.cljs index f4457f931f..b8c193a8eb 100644 --- a/src/status_im/handlers/content_suggestions.cljs +++ b/src/status_im/handlers/content_suggestions.cljs @@ -14,7 +14,7 @@ (defn get-content-suggestions [db command text] (or (when command - (when-let [command-suggestions ((:command command) suggestions)] + (when-let [command-suggestions ((keyword (:name command)) suggestions)] (filterv (fn [s] (and (.startsWith (:value s) (or text "")) (not= (:value s) text))) diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 48e808bf12..84b53d47e5 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -35,16 +35,6 @@ :icon {:uri "icon_lock_gray"} :suggestion true :handler #(dispatch [:sign-up-confirm %])} - {:command :send - :text "!send" - :description (label :t/send-command-description) - :color "#9a5dcf" - :suggestion true} - {:command :request - :text "!request" - :description (label :t/request-command-description) - :color "#48ba30" - :suggestion true} {:command :keypair-password :text "!keypair-password" :description (label :t/keypair-password-command-description) @@ -59,13 +49,11 @@ :color "#9a5dcf" :suggestion true}]) -(defn get-commands [db] - ;; todo: temp. must be '(get db :commands)' - ;; (get db :commands) - commands) +(defn get-commands [{:keys [current-chat-id] :as db}] + (or (get-in db [:chats current-chat-id :commands]) {})) (defn get-command [db command-key] - (first (filter #(= command-key (:command %)) (get-commands db)))) + ((get-commands db) command-key)) (defn find-command [commands command-key] (first (filter #(= command-key (:command %)) commands))) @@ -126,4 +114,4 @@ (update content :command #(find-command commands (keyword %)))) (defn parse-command-request [commands content] - (update content :command #(find-command commands (keyword %)))) + (update content :command #((keyword %) commands)))