Merge pull request #705 from GustavoNunes/feature/slash-command-char-#687

chat: change command char from ! to /  #687
This commit is contained in:
Jarrad 2017-01-12 15:57:52 +07:00 committed by GitHub
commit 00d7a6a0f4
7 changed files with 19 additions and 12 deletions

View File

@ -1,5 +1,7 @@
(ns status-im.chat.constants) (ns status-im.chat.constants)
(def command-char "/")
(def input-height 56) (def input-height 56)
(def max-input-height 66) (def max-input-height 66)
(def min-input-height 22) (def min-input-height 22)

View File

@ -5,6 +5,7 @@
[clojure.string :as string] [clojure.string :as string]
[status-im.components.styles :refer [default-chat-color]] [status-im.components.styles :refer [default-chat-color]]
[status-im.chat.suggestions :as suggestions] [status-im.chat.suggestions :as suggestions]
[status-im.chat.constants :as chat-consts]
[status-im.protocol.core :as protocol] [status-im.protocol.core :as protocol]
[status-im.data-store.chats :as chats] [status-im.data-store.chats :as chats]
[status-im.data-store.contacts :as contacts] [status-im.data-store.contacts :as contacts]
@ -170,7 +171,7 @@
(fn [{:keys [current-chat-id]} [_ text]] (fn [{:keys [current-chat-id]} [_ text]]
;; fixes https://github.com/status-im/status-react/issues/594 ;; fixes https://github.com/status-im/status-react/issues/594
;; todo: revisit with more clever solution ;; todo: revisit with more clever solution
(let [text' (if (= text "! ") "!" text)] (let [text' (if (= text (str chat-consts/command-char " ")) chat-consts/command-char text)]
(if (console? current-chat-id) (if (console? current-chat-id)
(dispatch [::check-input-for-commands text']) (dispatch [::check-input-for-commands text'])
(dispatch [::check-suggestions current-chat-id text'])))))) (dispatch [::check-suggestions current-chat-id text']))))))
@ -468,7 +469,7 @@
(register-handler :switch-command-suggestions! (register-handler :switch-command-suggestions!
(u/side-effect! (u/side-effect!
(fn [db] (fn [db]
(let [text (if (suggestions/typing-command? db) "" "!")] (let [text (if (suggestions/typing-command? db) "" chat-consts/command-char)]
(dispatch [:set-chat-input-text text]))))) (dispatch [:set-chat-input-text text])))))
(defn remove-chat (defn remove-chat

View File

@ -1,6 +1,7 @@
(ns status-im.chat.suggestions (ns status-im.chat.suggestions
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[status-im.db :as db] [status-im.db :as db]
[status-im.chat.constants :as chat-consts]
[status-im.models.commands :refer [get-commands [status-im.models.commands :refer [get-commands
get-chat-command-request get-chat-command-request
get-chat-command-to-message-id]] get-chat-command-to-message-id]]
@ -8,11 +9,11 @@
[clojure.string :as s])) [clojure.string :as s]))
(defn suggestion? [text] (defn suggestion? [text]
(= (get text 0) "!")) (= (get text 0) chat-consts/command-char))
(defn can-be-suggested? [text] (defn can-be-suggested? [text]
(fn [{:keys [name]}] (fn [{:keys [name]}]
(.startsWith (str "!" name) text))) (.startsWith (str chat-consts/command-char name) text)))
(defn get-suggestions (defn get-suggestions
[{:keys [current-chat-id] :as db} text] [{:keys [current-chat-id] :as db} text]
@ -43,7 +44,7 @@
(re-matches #"^![^\s]+\s" message))] (re-matches #"^![^\s]+\s" message))]
(let [suggestion-text' (s/trim suggestion-text)] (let [suggestion-text' (s/trim suggestion-text)]
(->> (get-commands db) (->> (get-commands db)
(filter #(= suggestion-text' (->> % second :name (str "!")))) (filter #(= suggestion-text' (->> % second :name (str chat-consts/command-char))))
first)))) first))))
(defn typing-command? [db] (defn typing-command? [db]

View File

@ -5,6 +5,7 @@
icon icon
text text
touchable-highlight]] touchable-highlight]]
[status-im.chat.constants :as chat-consts]
[status-im.chat.styles.input :as st])) [status-im.chat.styles.input :as st]))
(defn set-input-message [message] (defn set-input-message [message]
@ -23,4 +24,4 @@
(let [width (.. event -nativeEvent -layout -width)] (let [width (.. event -nativeEvent -layout -width)]
(when (not= icon-width width) (when (not= icon-width width)
(dispatch [:set :command-icon-width width]))))} (dispatch [:set :command-icon-width width]))))}
[text {:style st/command-text} (str "!" (:name command))]]]) [text {:style st/command-text} (str chat-consts/command-char (:name command))]]])

View File

@ -12,6 +12,7 @@
touchable-highlight touchable-highlight
get-dimensions]] get-dimensions]]
[status-im.components.animation :as anim] [status-im.components.animation :as anim]
[status-im.chat.constants :as chat-consts]
[status-im.chat.views.request-message :refer [message-content-command-request]] [status-im.chat.views.request-message :refer [message-content-command-request]]
[status-im.chat.styles.message :as st] [status-im.chat.styles.message :as st]
[status-im.chat.styles.command-pill :as pill-st] [status-im.chat.styles.command-pill :as pill-st]
@ -127,7 +128,7 @@
[view (pill-st/pill command) [view (pill-st/pill command)
[text {:style pill-st/pill-text [text {:style pill-st/pill-text
:font :default} :font :default}
(str (if (= :command type) "!" "?") name)]]] (str (if (= :command type) chat-consts/command-char "?") name)]]]
(when icon-path (when icon-path
[view st/command-image-view [view st/command-image-view
[icon icon-path st/command-image]]) [icon icon-path st/command-image]])

View File

@ -10,6 +10,7 @@
dismiss-keyboard!]] dismiss-keyboard!]]
[status-im.components.animation :as anim] [status-im.components.animation :as anim]
[status-im.chat.styles.plain-message :as st] [status-im.chat.styles.plain-message :as st]
[status-im.chat.constants :as chat-consts]
[status-im.constants :refer [response-input-hiding-duration]])) [status-im.constants :refer [response-input-hiding-duration]]))
(defn set-input-message [message] (defn set-input-message [message]
@ -20,7 +21,7 @@
(defn message-valid? [ message] (defn message-valid? [ message]
(and (pos? (count message)) (and (pos? (count message))
(not= "!" message))) (not= chat-consts/command-char message)))
(defn button-animation-logic [{:keys [command? val]}] (defn button-animation-logic [{:keys [command? val]}]
(fn [_] (fn [_]

View File

@ -19,7 +19,7 @@
[status-im.components.drag-drop :as drag] [status-im.components.drag-drop :as drag]
[status-im.utils.platform :refer [ios?]] [status-im.utils.platform :refer [ios?]]
[status-im.chat.suggestions-responder :as resp] [status-im.chat.suggestions-responder :as resp]
[status-im.chat.constants :as c] [status-im.chat.constants :as chat-consts]
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[status-im.chat.views.response :as response])) [status-im.chat.views.response :as response]))
@ -49,7 +49,7 @@
[[command {:keys [title description] [[command {:keys [title description]
name :name name :name
:as suggestion}]] :as suggestion}]]
(let [label (str "!" name)] (let [label (str chat-consts/command-char name)]
[touchable-highlight [touchable-highlight
{:onPress #(set-command-input command) {:onPress #(set-command-input command)
:style st/suggestion-highlight} :style st/suggestion-highlight}
@ -124,8 +124,8 @@
(into [animated-view {:style (st/container h @input-margin)}] elements))}))) (into [animated-view {:style (st/container h @input-margin)}] elements))})))
(defview suggestion-container [] (defview suggestion-container []
(let [h (anim/create-value c/input-height)] (let [h (anim/create-value chat-consts/input-height)]
[container h [container h
[header h] [header h]
[suggestions-view] [suggestions-view]
[view {:height c/input-height}]])) [view {:height chat-consts/input-height}]]))