diff --git a/.gitignore b/.gitignore index 81c8fbfbec..84569ba529 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,5 @@ target/ # Figwheel # -figwheel_server.log \ No newline at end of file +figwheel_server.log +.nrepl-port diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 83fbd67e02..d5fc0361f3 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -56,5 +56,5 @@ (dispatch [:load-user-phone-number]) (dispatch [:load-syng-contacts]) ;; TODO execute on first run only - ;; (dispatch [:set-sign-up-chat]) + (dispatch [:set-sign-up-chat]) (.registerComponent app-registry "SyngIm" #(r/reactify-component app-root))) diff --git a/src/syng_im/components/chat/chat_message.cljs b/src/syng_im/components/chat/chat_message.cljs index ca52ed8d95..bcdda29b9f 100644 --- a/src/syng_im/components/chat/chat_message.cljs +++ b/src/syng_im/components/chat/chat_message.cljs @@ -12,7 +12,8 @@ [syng-im.navigation :refer [nav-pop]] [syng-im.resources :as res] [syng-im.constants :refer [text-content-type - content-type-command]])) + content-type-command + content-type-command-request]])) (defn message-date [{:keys [date]}] @@ -66,45 +67,80 @@ (defn message-content-command [content] (let [{:keys [command content]} (commands/parse-command-msg-content content)] [view {:style {:flexDirection "column"}} - [view {:style {:margin 10 + [view {:style {:marginTop -5 + :marginLeft 0 :backgroundColor (:color command) :borderRadius 10}} - [text {:style {:marginTop -2 + [text {:style {:marginTop 0 :marginHorizontal 10 :fontSize 14 :fontFamily "Avenir-Roman" - :color "white"}} + :color "white"}} (:text command)]] - [text {:style {:marginTop -2 - :marginHorizontal 10 - :fontSize 14 - :fontFamily "Avenir-Roman" - :color "black"}} + [text {:style {:marginTop 5 + :marginHorizontal 0 + :fontSize 14 + :fontFamily "Avenir-Roman" + :color "black"}} ;; TODO isn't smart - (if (= (:command command) :keypair-password) - "******" - content)]])) + (if (= (:command command) :keypair-password) + "******" + content)]])) + +(defn set-chat-command [command] + (dispatch [:set-chat-command (:command command)])) + +(defn message-content-command-request [content outgoing] + (let [{:keys [command content]} (commands/parse-command-request-msg-content content)] + [view {:style {:marginTop 10}} + [view {:style (merge {:borderRadius 6 + :paddingVertical 12 + :paddingHorizontal 16} + (if outgoing + {:backgroundColor "#D3EEEF"} + {:backgroundColor "#FBF6E3"}))} + [text {:style {:fontSize 14 + :fontFamily "Avenir-Roman" + :color "#4A5258"}} + content]] + [touchable-highlight {:style {:position "absolute" + :top -15 + :left 20} + :onPress (fn [] + (set-chat-command command))} + [view {:style {:width 30 + :height 30 + :borderRadius 50 + :backgroundColor (:color command)}} + [image {:source res/att + :style {:width 17 + :height 14 + :position "absolute" + :top 8 + :left 6}}]]]])) (defn message-content [{:keys [content-type content outgoing]}] - [view {:style (merge {:borderRadius 6} - (if (= content-type text-content-type) - {:paddingVertical 12 - :paddingHorizontal 16} - {:paddingVertical 14 - :paddingHorizontal 10}) - (if outgoing - {:backgroundColor "#D3EEEF"} - {:backgroundColor "#FBF6E3"}))} - (cond - (= content-type text-content-type) - [text {:style {:fontSize 14 - :fontFamily "Avenir-Roman" - :color "#4A5258"}} - content] - (= content-type content-type-command) - [message-content-command content] - :else [message-content-audio {:content content - :content-type content-type}])]) + (if (= content-type content-type-command-request) + [message-content-command-request content outgoing] + [view {:style (merge {:borderRadius 6} + (if (= content-type text-content-type) + {:paddingVertical 12 + :paddingHorizontal 16} + {:paddingVertical 14 + :paddingHorizontal 10}) + (if outgoing + {:backgroundColor "#D3EEEF"} + {:backgroundColor "#FBF6E3"}))} + (cond + (= content-type text-content-type) + [text {:style {:fontSize 14 + :fontFamily "Avenir-Roman" + :color "#4A5258"}} + content] + (= content-type content-type-command) + [message-content-command content] + :else [message-content-audio {:content content + :content-type content-type}])])) (defn message-delivery-status [{:keys [delivery-status]}] [view {:style {:flexDirection "row" diff --git a/src/syng_im/components/chat/input/simple_command.cljs b/src/syng_im/components/chat/input/simple_command.cljs index 3e84760747..1e8926925a 100644 --- a/src/syng_im/components/chat/input/simple_command.cljs +++ b/src/syng_im/components/chat/input/simple_command.cljs @@ -69,8 +69,7 @@ :onChangeText (fn [new-text] (set-input-message new-text)) :onSubmitEditing (fn [e] - (send-command chat-id command message) - (set-input-message nil))} + (send-command chat-id command message))} input-options) message]]] [touchable-highlight {:style {:marginTop 14 @@ -79,7 +78,7 @@ :right 20 :bottom 20} :onPress (fn [] - (cancel-command-input))} + (send-command chat-id command message))} [image {:source res/att :style {:width 34 :height 28}}]]])))) diff --git a/src/syng_im/components/chat/plain_message_input.cljs b/src/syng_im/components/chat/plain_message_input.cljs index 476aa1b13e..0784f693c2 100644 --- a/src/syng_im/components/chat/plain_message_input.cljs +++ b/src/syng_im/components/chat/plain_message_input.cljs @@ -37,7 +37,7 @@ :fontSize 14 :fontFamily "Avenir-Roman" :color "#9CBFC0"} - :autoFocus true + :autoFocus false :placeholder "Type your message here" :onChangeText (fn [new-text] (set-input-message new-text)) diff --git a/src/syng_im/constants.cljs b/src/syng_im/constants.cljs index dd6729fe43..f4662dd6e6 100644 --- a/src/syng_im/constants.cljs +++ b/src/syng_im/constants.cljs @@ -7,3 +7,4 @@ (def text-content-type "text/plain") (def content-type-command "command") +(def content-type-command-request "command-request") diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index fc462f3ea7..370ac2dd1d 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -144,7 +144,8 @@ (register-handler :send-chat-command (fn [db [action chat-id command content]] (log/debug action "chat-id" chat-id "command" command "content" content) - (let [msg (if (= chat-id "console") + (let [db (set-chat-input-text db nil) + msg (if (= chat-id "console") (sign-up-service/send-console-command command content) ;; TODO handle command, now sends as plain message (let [{msg-id :msg-id diff --git a/src/syng_im/handlers/sign_up.cljs b/src/syng_im/handlers/sign_up.cljs index ecfbd8fd9a..2a844a146b 100644 --- a/src/syng_im/handlers/sign_up.cljs +++ b/src/syng_im/handlers/sign_up.cljs @@ -6,27 +6,35 @@ [syng-im.utils.logging :as log] [syng-im.utils.random :as random] [syng-im.constants :refer [text-content-type - content-type-command]])) + content-type-command + content-type-command-request]])) (defn intro [db] - (dispatch [:received-msg {:msg-id "1" - :content "Hello there! It's Syng, a Dapp browser in your phone." - :content-type text-content-type - :outgoing false - :from "console" - :to "me"}]) - (dispatch [:received-msg {:msg-id "2" - :content "Syng uses a highly secure key-pair authentication type to provide you a reliable way to access your account" - :content-type text-content-type - :outgoing false - :from "console" - :to "me"}]) - (dispatch [:received-msg {:msg-id "3" - :content "A key pair has been generated and saved to your device. Create a password to secure your key" - :content-type text-content-type - :outgoing false - :from "console" - :to "me"}]) + (dispatch [:received-msg + {:msg-id "1" + :content "Hello there! It's Syng, a Dapp browser in your phone." + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}]) + (dispatch [:received-msg + {:msg-id "2" + :content (str "Syng uses a highly secure key-pair authentication type " + "to provide you a reliable way to access your account") + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}]) + (dispatch [:received-msg + {:msg-id "3" + :content (commands/format-command-request-msg-content + :keypair-password + (str "A key pair has been generated and saved to your device. " + "Create a password to secure your key")) + :content-type content-type-command-request + :outgoing false + :from "console" + :to "me"}]) (dispatch [:set-chat-command :keypair-password]) db) @@ -38,8 +46,95 @@ :content-type text-content-type :outgoing true}) +(defn- handle-password [content] + ;; TODO validate and save password + (dispatch [:received-msg + {:msg-id "4" + :content (str "OK great! Your password has been saved. Just to let you " + "know, you can always change it in the Console, by the way, " + "it's me, the Console, nice to meet you!") + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}]) + (dispatch [:received-msg + {:msg-id "5" + :content (str "I'll generate a passphrase for you so you can restore your " + "access or log in from another device") + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}]) + (dispatch [:received-msg + {:msg-id "6" + :content "Here's your passphrase:" + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}]) + ;; TODO generate passphrase + (let [passphrase (str "The brash businessman's braggadocio and public squabbing with " + "candidates in the US presidential election")] + (dispatch [:received-msg + {:msg-id "7" + :content passphrase + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}])) + (dispatch [:received-msg + {:msg-id "8" + :content "Make sure you had securely written it down" + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}]) + ;; TODO highlight '!phone' + (dispatch [:received-msg + {:msg-id "9" + :content (commands/format-command-request-msg-content + :phone + (str "Your phone number is also required to use the app. Type the " + "exclamation mark or hit the icon to open the command list " + "and choose the !phone command") ) + :content-type content-type-command-request + :outgoing false + :from "console" + :to "me"}])) + +(defn- handle-phone [content] + ;; TODO validate and save phone number + ;; send phone to server + (dispatch [:received-msg + {:msg-id "10" + :content (commands/format-command-request-msg-content + :confirmation-code + (str "Thanks! We've sent you a text message with a confirmation " + "code. Please provide that code to confirm your phone number")) + :content-type content-type-command-request + :outgoing false + :from "console" + :to "me"}])) + +(defn- handle-confirmation-code [content] + ;; TODO validate confirmation code + ;; send code to server + (dispatch [:received-msg + {:msg-id "10" + :content "Thanks!" + :content-type text-content-type + :outgoing false + :from "console" + :to "me"}])) + ;; TODO store command key in a separate field (defn send-console-command [command content] + (when (= command :keypair-password) + (handle-password content)) + (when (= command :phone) + (handle-phone content)) + (when (= command :confirmation-code) + (handle-confirmation-code content)) {:msg-id (random/id) :from "me" :to "console" diff --git a/src/syng_im/models/commands.cljs b/src/syng_im/models/commands.cljs index 780f651a2c..de44474d58 100644 --- a/src/syng_im/models/commands.cljs +++ b/src/syng_im/models/commands.cljs @@ -21,6 +21,11 @@ :description "Send phone number" :color "#48ba30" :suggestion true} + {:command :confirmation-code + :text "!confirmationCode" + :description "Send confirmation code" + :color "#019af0" + :suggestion true} {:command :send :text "!send" :description "Send location" @@ -59,6 +64,11 @@ (defn format-command-msg-content [command content] (map-to-str {:command (name command) :content content})) -;; TODO temp (defn parse-command-msg-content [content] (update (str-to-map content) :command #(get-command (keyword %)))) + +(defn format-command-request-msg-content [command content] + (map-to-str {:command (name command) :content content})) + +(defn parse-command-request-msg-content [content] + (update (str-to-map content) :command #(get-command (keyword %))))