Show console chat on first run

This commit is contained in:
virvar 2016-04-08 12:17:10 +03:00
parent c08acdf24a
commit e04a6eec4f
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.new-group :refer [new-group]]
[syng-im.utils.logging :as log]
[syng-im.utils.utils :refer [toast]]
[syng-im.navigation :as nav]
[syng-im.utils.encryption]))
@ -32,10 +33,14 @@
(add-event-listener "hardwareBackPress" new-listener)))))
(defn app-root []
(let [signed-up-atom (subscribe [:signed-up])]
(fn []
(let [signed-up @signed-up-atom]
[navigator {:initial-route (clj->js {:view-id :chat-list})
:render-scene (fn [route nav]
(log/debug "route" route)
(when true ;; nav/*nav-render*
(if signed-up
(let [{:keys [view-id]} (js->clj route :keywordize-keys true)
view-id (keyword view-id)]
(init-back-button-handler! nav)
@ -43,7 +48,8 @@
: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}])))))}])
:chat (r/as-element [chat {:navigator nav}])))
(r/as-element [chat {:navigator nav}]))))}]))))
(defn init []
(dispatch-sync [:initialize-db])
@ -51,6 +57,5 @@
(dispatch [:initialize-protocol])
(dispatch [:load-user-phone-number])
(dispatch [:load-syng-contacts])
;; TODO execute on first run only
(dispatch [:set-sign-up-chat])
(dispatch-sync [:init-console-chat])
(.registerComponent app-registry "SyngIm" #(r/reactify-component app-root)))

View File

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

View File

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

View File

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

View File

@ -1,6 +1,9 @@
(ns syng-im.handlers.sign-up
(: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.models.chat :refer [set-current-chat-id]]
[syng-im.models.commands :as commands]
[syng-im.utils.utils :refer [log on-error http-post toast]]
[syng-im.utils.logging :as log]
@ -18,6 +21,10 @@
:content-type text-content-type
: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---------------------------
(defn on-sync-contacts []
@ -27,7 +34,8 @@
:content-type text-content-type
:outgoing false
:from "console"
:to "me"}]))
:to "me"}])
(dispatch [:set-signed-up true]))
(defn sync-contacts []
(dispatch [:sync-contacts on-sync-contacts]))
@ -142,14 +150,14 @@
(defn intro [db]
(dispatch [:received-msg
{:msg-id "1"
{:msg-id (random/id)
: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"
{:msg-id (random/id)
: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
@ -157,7 +165,7 @@
:from "console"
:to "me"}])
(dispatch [:received-msg
{:msg-id "3"
{:msg-id (random/id)
:content (commands/format-command-request-msg-content
:keypair-password
(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-type content-type-command
: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))))
(register-sub
:get-confirmation-code
:signed-up
(fn [db _]
(reaction
(get @db :confirmation-code))))
(get @db :signed-up))))
(register-sub
:get-contacts