Add select command button
This commit is contained in:
parent
b27fdfe96c
commit
a530cbbb65
|
@ -42,3 +42,4 @@ target/
|
||||||
# Figwheel
|
# Figwheel
|
||||||
#
|
#
|
||||||
figwheel_server.log
|
figwheel_server.log
|
||||||
|
.nrepl-port
|
||||||
|
|
|
@ -56,5 +56,5 @@
|
||||||
(dispatch [:load-user-phone-number])
|
(dispatch [:load-user-phone-number])
|
||||||
(dispatch [:load-syng-contacts])
|
(dispatch [:load-syng-contacts])
|
||||||
;; TODO execute on first run only
|
;; 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)))
|
(.registerComponent app-registry "SyngIm" #(r/reactify-component app-root)))
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
[syng-im.navigation :refer [nav-pop]]
|
[syng-im.navigation :refer [nav-pop]]
|
||||||
[syng-im.resources :as res]
|
[syng-im.resources :as res]
|
||||||
[syng-im.constants :refer [text-content-type
|
[syng-im.constants :refer [text-content-type
|
||||||
content-type-command]]))
|
content-type-command
|
||||||
|
content-type-command-request]]))
|
||||||
|
|
||||||
|
|
||||||
(defn message-date [{:keys [date]}]
|
(defn message-date [{:keys [date]}]
|
||||||
|
@ -66,17 +67,18 @@
|
||||||
(defn message-content-command [content]
|
(defn message-content-command [content]
|
||||||
(let [{:keys [command content]} (commands/parse-command-msg-content content)]
|
(let [{:keys [command content]} (commands/parse-command-msg-content content)]
|
||||||
[view {:style {:flexDirection "column"}}
|
[view {:style {:flexDirection "column"}}
|
||||||
[view {:style {:margin 10
|
[view {:style {:marginTop -5
|
||||||
|
:marginLeft 0
|
||||||
:backgroundColor (:color command)
|
:backgroundColor (:color command)
|
||||||
:borderRadius 10}}
|
:borderRadius 10}}
|
||||||
[text {:style {:marginTop -2
|
[text {:style {:marginTop 0
|
||||||
:marginHorizontal 10
|
:marginHorizontal 10
|
||||||
:fontSize 14
|
:fontSize 14
|
||||||
:fontFamily "Avenir-Roman"
|
:fontFamily "Avenir-Roman"
|
||||||
:color "white"}}
|
:color "white"}}
|
||||||
(:text command)]]
|
(:text command)]]
|
||||||
[text {:style {:marginTop -2
|
[text {:style {:marginTop 5
|
||||||
:marginHorizontal 10
|
:marginHorizontal 0
|
||||||
:fontSize 14
|
:fontSize 14
|
||||||
:fontFamily "Avenir-Roman"
|
:fontFamily "Avenir-Roman"
|
||||||
:color "black"}}
|
:color "black"}}
|
||||||
|
@ -85,7 +87,41 @@
|
||||||
"******"
|
"******"
|
||||||
content)]]))
|
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]}]
|
(defn message-content [{:keys [content-type content outgoing]}]
|
||||||
|
(if (= content-type content-type-command-request)
|
||||||
|
[message-content-command-request content outgoing]
|
||||||
[view {:style (merge {:borderRadius 6}
|
[view {:style (merge {:borderRadius 6}
|
||||||
(if (= content-type text-content-type)
|
(if (= content-type text-content-type)
|
||||||
{:paddingVertical 12
|
{:paddingVertical 12
|
||||||
|
@ -104,7 +140,7 @@
|
||||||
(= content-type content-type-command)
|
(= content-type content-type-command)
|
||||||
[message-content-command content]
|
[message-content-command content]
|
||||||
:else [message-content-audio {:content content
|
:else [message-content-audio {:content content
|
||||||
:content-type content-type}])])
|
:content-type content-type}])]))
|
||||||
|
|
||||||
(defn message-delivery-status [{:keys [delivery-status]}]
|
(defn message-delivery-status [{:keys [delivery-status]}]
|
||||||
[view {:style {:flexDirection "row"
|
[view {:style {:flexDirection "row"
|
||||||
|
|
|
@ -69,8 +69,7 @@
|
||||||
:onChangeText (fn [new-text]
|
:onChangeText (fn [new-text]
|
||||||
(set-input-message new-text))
|
(set-input-message new-text))
|
||||||
:onSubmitEditing (fn [e]
|
:onSubmitEditing (fn [e]
|
||||||
(send-command chat-id command message)
|
(send-command chat-id command message))}
|
||||||
(set-input-message nil))}
|
|
||||||
input-options)
|
input-options)
|
||||||
message]]]
|
message]]]
|
||||||
[touchable-highlight {:style {:marginTop 14
|
[touchable-highlight {:style {:marginTop 14
|
||||||
|
@ -79,7 +78,7 @@
|
||||||
:right 20
|
:right 20
|
||||||
:bottom 20}
|
:bottom 20}
|
||||||
:onPress (fn []
|
:onPress (fn []
|
||||||
(cancel-command-input))}
|
(send-command chat-id command message))}
|
||||||
[image {:source res/att
|
[image {:source res/att
|
||||||
:style {:width 34
|
:style {:width 34
|
||||||
:height 28}}]]]))))
|
:height 28}}]]]))))
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
:fontSize 14
|
:fontSize 14
|
||||||
:fontFamily "Avenir-Roman"
|
:fontFamily "Avenir-Roman"
|
||||||
:color "#9CBFC0"}
|
:color "#9CBFC0"}
|
||||||
:autoFocus true
|
:autoFocus false
|
||||||
:placeholder "Type your message here"
|
:placeholder "Type your message here"
|
||||||
:onChangeText (fn [new-text]
|
:onChangeText (fn [new-text]
|
||||||
(set-input-message new-text))
|
(set-input-message new-text))
|
||||||
|
|
|
@ -7,3 +7,4 @@
|
||||||
|
|
||||||
(def text-content-type "text/plain")
|
(def text-content-type "text/plain")
|
||||||
(def content-type-command "command")
|
(def content-type-command "command")
|
||||||
|
(def content-type-command-request "command-request")
|
||||||
|
|
|
@ -144,7 +144,8 @@
|
||||||
(register-handler :send-chat-command
|
(register-handler :send-chat-command
|
||||||
(fn [db [action chat-id command content]]
|
(fn [db [action chat-id command content]]
|
||||||
(log/debug action "chat-id" chat-id "command" command "content" 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)
|
(sign-up-service/send-console-command command content)
|
||||||
;; TODO handle command, now sends as plain message
|
;; TODO handle command, now sends as plain message
|
||||||
(let [{msg-id :msg-id
|
(let [{msg-id :msg-id
|
||||||
|
|
|
@ -6,24 +6,32 @@
|
||||||
[syng-im.utils.logging :as log]
|
[syng-im.utils.logging :as log]
|
||||||
[syng-im.utils.random :as random]
|
[syng-im.utils.random :as random]
|
||||||
[syng-im.constants :refer [text-content-type
|
[syng-im.constants :refer [text-content-type
|
||||||
content-type-command]]))
|
content-type-command
|
||||||
|
content-type-command-request]]))
|
||||||
|
|
||||||
(defn intro [db]
|
(defn intro [db]
|
||||||
(dispatch [:received-msg {:msg-id "1"
|
(dispatch [:received-msg
|
||||||
|
{:msg-id "1"
|
||||||
:content "Hello there! It's Syng, a Dapp browser in your phone."
|
:content "Hello there! It's Syng, a Dapp browser in your phone."
|
||||||
:content-type text-content-type
|
:content-type text-content-type
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
(dispatch [:received-msg {:msg-id "2"
|
(dispatch [:received-msg
|
||||||
:content "Syng uses a highly secure key-pair authentication type to provide you a reliable way to access your account"
|
{: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
|
:content-type text-content-type
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
(dispatch [:received-msg {:msg-id "3"
|
(dispatch [:received-msg
|
||||||
:content "A key pair has been generated and saved to your device. Create a password to secure your key"
|
{:msg-id "3"
|
||||||
:content-type text-content-type
|
: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
|
:outgoing false
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
|
@ -38,8 +46,95 @@
|
||||||
:content-type text-content-type
|
:content-type text-content-type
|
||||||
:outgoing true})
|
: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
|
;; TODO store command key in a separate field
|
||||||
(defn send-console-command [command content]
|
(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)
|
{:msg-id (random/id)
|
||||||
:from "me"
|
:from "me"
|
||||||
:to "console"
|
:to "console"
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
:description "Send phone number"
|
:description "Send phone number"
|
||||||
:color "#48ba30"
|
:color "#48ba30"
|
||||||
:suggestion true}
|
:suggestion true}
|
||||||
|
{:command :confirmation-code
|
||||||
|
:text "!confirmationCode"
|
||||||
|
:description "Send confirmation code"
|
||||||
|
:color "#019af0"
|
||||||
|
:suggestion true}
|
||||||
{:command :send
|
{:command :send
|
||||||
:text "!send"
|
:text "!send"
|
||||||
:description "Send location"
|
:description "Send location"
|
||||||
|
@ -59,6 +64,11 @@
|
||||||
(defn format-command-msg-content [command content]
|
(defn format-command-msg-content [command content]
|
||||||
(map-to-str {:command (name command) :content content}))
|
(map-to-str {:command (name command) :content content}))
|
||||||
|
|
||||||
;; TODO temp
|
|
||||||
(defn parse-command-msg-content [content]
|
(defn parse-command-msg-content [content]
|
||||||
(update (str-to-map content) :command #(get-command (keyword %))))
|
(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 %))))
|
||||||
|
|
Loading…
Reference in New Issue