Show console chat on first run

Former-commit-id: e04a6eec4f
This commit is contained in:
virvar 2016-04-08 12:17:10 +03:00
parent e40439000e
commit 628827fbdd
6 changed files with 55 additions and 34 deletions

View File

@ -12,6 +12,7 @@
[syng-im.components.chats.chats-list :refer [chats-list]] [syng-im.components.chats.chats-list :refer [chats-list]]
[syng-im.components.chats.new-group :refer [new-group]] [syng-im.components.chats.new-group :refer [new-group]]
[syng-im.utils.logging :as log] [syng-im.utils.logging :as log]
[syng-im.utils.utils :refer [toast]]
[syng-im.navigation :as nav] [syng-im.navigation :as nav]
[syng-im.utils.encryption])) [syng-im.utils.encryption]))
@ -32,18 +33,23 @@
(add-event-listener "hardwareBackPress" new-listener))))) (add-event-listener "hardwareBackPress" new-listener)))))
(defn app-root [] (defn app-root []
[navigator {:initial-route (clj->js {:view-id :chat-list}) (let [signed-up-atom (subscribe [:signed-up])]
:render-scene (fn [route nav] (fn []
(log/debug "route" route) (let [signed-up @signed-up-atom]
(when true ;; nav/*nav-render* [navigator {:initial-route (clj->js {:view-id :chat-list})
(let [{:keys [view-id]} (js->clj route :keywordize-keys true) :render-scene (fn [route nav]
view-id (keyword view-id)] (log/debug "route" route)
(init-back-button-handler! nav) (when true ;; nav/*nav-render*
(case view-id (if signed-up
:chat-list (r/as-element [chats-list {:navigator nav}]) (let [{:keys [view-id]} (js->clj route :keywordize-keys true)
:new-group (r/as-element [new-group {:navigator nav}]) view-id (keyword view-id)]
:contact-list (r/as-element [contact-list {:navigator nav}]) (init-back-button-handler! nav)
:chat (r/as-element [chat {:navigator nav}])))))}]) (case view-id
:chat-list (r/as-element [chats-list {:navigator nav}])
:new-group (r/as-element [new-group {:navigator nav}])
:contact-list (r/as-element [contact-list {:navigator nav}])
:chat (r/as-element [chat {:navigator nav}])))
(r/as-element [chat {:navigator nav}]))))}]))))
(defn init [] (defn init []
(dispatch-sync [:initialize-db]) (dispatch-sync [:initialize-db])
@ -51,6 +57,5 @@
(dispatch [:initialize-protocol]) (dispatch [:initialize-protocol])
(dispatch [:load-user-phone-number]) (dispatch [:load-user-phone-number])
(dispatch [:load-syng-contacts]) (dispatch [:load-syng-contacts])
;; TODO execute on first run only (dispatch-sync [:init-console-chat])
(dispatch [:set-sign-up-chat])
(.registerComponent app-registry "SyngIm" #(r/reactify-component app-root))) (.registerComponent app-registry "SyngIm" #(r/reactify-component app-root)))

View File

@ -2,8 +2,8 @@
(def ethereum-rpc-url "http://localhost:8545") (def ethereum-rpc-url "http://localhost:8545")
;; (def server-address "http://rpc0.syng.im:20000/") (def server-address "http://rpc0.syng.im:20000/")
(def server-address "http://10.0.3.2:3000/") ;; (def server-address "http://10.0.3.2:3000/")
(def text-content-type "text/plain") (def text-content-type "text/plain")
(def content-type-command "command") (def content-type-command "command")

View File

@ -12,7 +12,8 @@
:command nil} :command nil}
:chats {} :chats {}
:chats-updated-signal 0 :chats-updated-signal 0
:new-group #{}}) :new-group #{}
:signed-up false})
(def protocol-initialized-path [:protocol-initialized]) (def protocol-initialized-path [:protocol-initialized])

View File

@ -195,10 +195,6 @@
(fn [db [_ phone-number handler]] (fn [db [_ phone-number handler]]
(server/sign-up db phone-number handler))) (server/sign-up db phone-number handler)))
(register-handler :set-confirmation-code
(fn [db [_ value]]
(assoc db :confirmation-code value)))
(register-handler :sign-up-confirm (register-handler :sign-up-confirm
(fn [db [_ confirmation-code handler]] (fn [db [_ confirmation-code handler]]
(server/sign-up-confirm confirmation-code handler) (server/sign-up-confirm confirmation-code handler)
@ -224,11 +220,13 @@
(dispatch [:navigate-to navigator {:view-id :chat}]) (dispatch [:navigate-to navigator {:view-id :chat}])
db))) db)))
(register-handler :set-sign-up-chat (register-handler :init-console-chat
(fn [db [_]] (fn [db [_]]
(-> db (sign-up-service/init db)))
(set-current-chat-id "console")
sign-up-service/intro))) (register-handler :set-signed-up
(fn [db [_ signed-up]]
(sign-up-service/set-signed-up db signed-up)))
;; -- Chat -------------------------------------------------------------- ;; -- Chat --------------------------------------------------------------

View File

@ -1,6 +1,9 @@
(ns syng-im.handlers.sign-up (ns syng-im.handlers.sign-up
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.persistence.simple-kv-store :as kv]
[syng-im.protocol.state.storage :as s]
[syng-im.db :as db] [syng-im.db :as db]
[syng-im.models.chat :refer [set-current-chat-id]]
[syng-im.models.commands :as commands] [syng-im.models.commands :as commands]
[syng-im.utils.utils :refer [log on-error http-post toast]] [syng-im.utils.utils :refer [log on-error http-post toast]]
[syng-im.utils.logging :as log] [syng-im.utils.logging :as log]
@ -18,6 +21,10 @@
:content-type text-content-type :content-type text-content-type
:outgoing true}) :outgoing true})
(defn- set-signed-up [db signed-up]
(s/put kv/kv-store :signed-up signed-up)
(assoc db :signed-up signed-up))
;; -- Send confirmation code and synchronize contacts--------------------------- ;; -- Send confirmation code and synchronize contacts---------------------------
(defn on-sync-contacts [] (defn on-sync-contacts []
@ -27,7 +34,8 @@
:content-type text-content-type :content-type text-content-type
:outgoing false :outgoing false
:from "console" :from "console"
:to "me"}])) :to "me"}])
(dispatch [:set-signed-up true]))
(defn sync-contacts [] (defn sync-contacts []
(dispatch [:sync-contacts on-sync-contacts])) (dispatch [:sync-contacts on-sync-contacts]))
@ -129,7 +137,7 @@
:phone :phone
(str "Your phone number is also required to use the app. Type the " (str "Your phone number is also required to use the app. Type the "
"exclamation mark or hit the icon to open the command list " "exclamation mark or hit the icon to open the command list "
"and choose the !phone command") ) "and choose the !phone command"))
:content-type content-type-command-request :content-type content-type-command-request
:outgoing false :outgoing false
:from "console" :from "console"
@ -142,14 +150,14 @@
(defn intro [db] (defn intro [db]
(dispatch [:received-msg (dispatch [:received-msg
{:msg-id "1" {:msg-id (random/id)
: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 (dispatch [:received-msg
{:msg-id "2" {:msg-id (random/id)
:content (str "Syng uses a highly secure key-pair authentication type " :content (str "Syng uses a highly secure key-pair authentication type "
"to provide you a reliable way to access your account") "to provide you a reliable way to access your account")
:content-type text-content-type :content-type text-content-type
@ -157,7 +165,7 @@
:from "console" :from "console"
:to "me"}]) :to "me"}])
(dispatch [:received-msg (dispatch [:received-msg
{:msg-id "3" {:msg-id (random/id)
:content (commands/format-command-request-msg-content :content (commands/format-command-request-msg-content
:keypair-password :keypair-password
(str "A key pair has been generated and saved to your device. " (str "A key pair has been generated and saved to your device. "
@ -180,3 +188,12 @@
:content (commands/format-command-msg-content command-key content) :content (commands/format-command-msg-content command-key content)
:content-type content-type-command :content-type content-type-command
:outgoing true}) :outgoing true})
(defn init [db]
(let [signed-up (s/get kv/kv-store :signed-up)
db (if signed-up
db
(-> db
(set-current-chat-id "console")
intro))]
(assoc db :signed-up signed-up)))

View File

@ -94,10 +94,10 @@
(get @db :loading)))) (get @db :loading))))
(register-sub (register-sub
:get-confirmation-code :signed-up
(fn [db _] (fn [db _]
(reaction (reaction
(get @db :confirmation-code)))) (get @db :signed-up))))
(register-sub (register-sub
:get-contacts :get-contacts