Use 'current-identity'
This commit is contained in:
parent
785ddcc245
commit
797fe3336b
|
@ -15,7 +15,7 @@
|
||||||
[messenger.android.chat :refer [chat]]
|
[messenger.android.chat :refer [chat]]
|
||||||
[messenger.comm.pubsub :as pubsub]
|
[messenger.comm.pubsub :as pubsub]
|
||||||
[messenger.comm.intercom :as intercom :refer [load-user-phone-number
|
[messenger.comm.intercom :as intercom :refer [load-user-phone-number
|
||||||
load-user-whisper-identity]]
|
load-user-identity]]
|
||||||
[messenger.protocol.protocol-handler :refer [make-handler]]
|
[messenger.protocol.protocol-handler :refer [make-handler]]
|
||||||
[syng-im.protocol.api :refer [init-protocol]]
|
[syng-im.protocol.api :refer [init-protocol]]
|
||||||
[messenger.init :refer [init-simple-store]]))
|
[messenger.init :refer [init-simple-store]]))
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
(defui AppRoot
|
(defui AppRoot
|
||||||
static om/IQuery
|
static om/IQuery
|
||||||
(query [this]
|
(query [this]
|
||||||
'[:loading :contacts-ds :user-phone-number :confirmation-code])
|
'[:loading :contacts-ds :user-phone-number :user-identity :confirmation-code])
|
||||||
Object
|
Object
|
||||||
(render [this]
|
(render [this]
|
||||||
(navigator
|
(navigator
|
||||||
|
@ -67,6 +67,6 @@
|
||||||
(pubsub/setup-pub-sub)
|
(pubsub/setup-pub-sub)
|
||||||
(init-protocol (make-handler))
|
(init-protocol (make-handler))
|
||||||
(load-user-phone-number)
|
(load-user-phone-number)
|
||||||
(load-user-whisper-identity)
|
(load-user-identity)
|
||||||
(om/add-root! state/reconciler AppRoot 1)
|
(om/add-root! state/reconciler AppRoot 1)
|
||||||
(.registerComponent app-registry "Messenger" (fn [] app-root)))
|
(.registerComponent app-registry "Messenger" (fn [] app-root)))
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
(swap! state/app-state assoc :loading true)
|
(swap! state/app-state assoc :loading true)
|
||||||
(let [app-state (state/state)
|
(let [app-state (state/state)
|
||||||
phone-number (:user-phone-number app-state)
|
phone-number (:user-phone-number app-state)
|
||||||
whisper-identity (:user-whisper-identity app-state)]
|
whisper-identity (:public (:user-identity app-state))]
|
||||||
(intercom/sign-up phone-number whisper-identity show-confirm-view)))
|
(intercom/sign-up phone-number whisper-identity show-confirm-view)))
|
||||||
|
|
||||||
(defn update-phone-number [value]
|
(defn update-phone-number [value]
|
||||||
|
@ -38,10 +38,10 @@
|
||||||
(defui Login
|
(defui Login
|
||||||
static om/IQuery
|
static om/IQuery
|
||||||
(query [this]
|
(query [this]
|
||||||
'[:user-phone-number :user-whisper-identity :loading])
|
'[:user-phone-number :user-identity :loading])
|
||||||
Object
|
Object
|
||||||
(render [this]
|
(render [this]
|
||||||
(let [{:keys [user-phone-number user-whisper-identity loading]} (om/props this)
|
(let [{:keys [user-phone-number user-identity loading]} (om/props this)
|
||||||
{:keys [nav]} (om/get-computed this)]
|
{:keys [nav]} (om/get-computed this)]
|
||||||
(reset! nav-atom nav)
|
(reset! nav-atom nav)
|
||||||
(view
|
(view
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
[natal-shell.alert :refer [alert]])
|
[natal-shell.alert :refer [alert]])
|
||||||
(:require [om.next :as om :refer-macros [defui]]
|
(:require [om.next :as om :refer-macros [defui]]
|
||||||
[re-natal.support :as sup]
|
[re-natal.support :as sup]
|
||||||
[syng-im.protocol.web3 :as whisper]
|
|
||||||
[messenger.state :as state]
|
[messenger.state :as state]
|
||||||
[messenger.utils.utils :refer [log toast]]
|
[messenger.utils.utils :refer [log toast]]
|
||||||
[messenger.utils.resources :as res]
|
[messenger.utils.resources :as res]
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
;; :service [service_name action_id args_map]
|
;; :service [service_name action_id args_map]
|
||||||
(publish! :service [:user-data :user-data/load-phone-number nil]))
|
(publish! :service [:user-data :user-data/load-phone-number nil]))
|
||||||
|
|
||||||
(defn load-user-whisper-identity []
|
(defn load-user-identity []
|
||||||
(publish! :service [:user-data :user-data/load-whisper-identity nil]))
|
(publish! :service [:user-data :user-data/load-identity nil]))
|
||||||
|
|
||||||
(defn set-confirmation-code [confirmation-code]
|
(defn set-confirmation-code [confirmation-code]
|
||||||
(publish! :service [:user-data :user-data/set-confirmation-code confirmation-code]))
|
(publish! :service [:user-data :user-data/set-confirmation-code confirmation-code]))
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
[messenger.state :as state]
|
[messenger.state :as state]
|
||||||
[messenger.utils.utils :refer [log on-error toast]]))
|
[messenger.utils.utils :refer [log on-error toast]]))
|
||||||
|
|
||||||
(def ethereum-rpc-url "http://localhost:8545")
|
|
||||||
|
|
||||||
(defn set-phone-number [phone-number]
|
(defn set-phone-number [phone-number]
|
||||||
(swap! state/app-state assoc :user-phone-number phone-number))
|
(swap! state/app-state assoc :user-phone-number phone-number))
|
||||||
|
|
||||||
|
@ -23,33 +21,8 @@
|
||||||
(swap! state/app-state assoc :user-phone-number (when value
|
(swap! state/app-state assoc :user-phone-number (when value
|
||||||
(str value)))))))
|
(str value)))))))
|
||||||
|
|
||||||
(defn save-whisper-identity [identity]
|
(defn set-identity [identity]
|
||||||
(set-item "user-whisper-identity" identity)
|
(swap! state/app-state assoc :user-identity identity))
|
||||||
(swap! state/app-state assoc :user-whisper-identity identity))
|
|
||||||
|
|
||||||
(defn load-whisper-identity []
|
|
||||||
(let [ch (chan)]
|
|
||||||
(get-item "user-whisper-identity"
|
|
||||||
(fn [error value]
|
|
||||||
(log (str "load whisper identity: " value))
|
|
||||||
(put! ch
|
|
||||||
{:error error
|
|
||||||
:value (let [whisper-identity (when value (str value))]
|
|
||||||
(swap! state/app-state assoc :user-whisper-identity
|
|
||||||
whisper-identity)
|
|
||||||
whisper-identity)})))
|
|
||||||
ch))
|
|
||||||
|
|
||||||
(defn new-whisper-identity []
|
|
||||||
(let [ch (chan)]
|
|
||||||
(let [web3 (web3/make-web3 ethereum-rpc-url)]
|
|
||||||
(.newIdentity (web3/whisper web3)
|
|
||||||
(fn [error value]
|
|
||||||
(log (str "new whisper identity: " value))
|
|
||||||
(swap! state/app-state assoc :user-whisper-identity value)
|
|
||||||
(put! ch {:error error
|
|
||||||
:value value}))))
|
|
||||||
ch))
|
|
||||||
|
|
||||||
(defn set-confirmation-code [code]
|
(defn set-confirmation-code [code]
|
||||||
(swap! state/app-state assoc :confirmation-code code))
|
(swap! state/app-state assoc :confirmation-code code))
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
[messenger.models.user-data :refer [set-phone-number
|
[messenger.models.user-data :refer [set-phone-number
|
||||||
save-phone-number
|
save-phone-number
|
||||||
load-phone-number
|
load-phone-number
|
||||||
save-whisper-identity
|
set-identity
|
||||||
load-whisper-identity
|
|
||||||
new-whisper-identity
|
|
||||||
set-confirmation-code]]
|
set-confirmation-code]]
|
||||||
|
[messenger.models.protocol :refer [current-identity]]
|
||||||
[messenger.utils.utils :refer [log on-error]]
|
[messenger.utils.utils :refer [log on-error]]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
|
@ -29,18 +28,11 @@
|
||||||
(log/debug "handling " id "args = " args)
|
(log/debug "handling " id "args = " args)
|
||||||
(load-phone-number))
|
(load-phone-number))
|
||||||
|
|
||||||
(defmethod user-data :user-data/load-whisper-identity
|
(defmethod user-data :user-data/load-identity
|
||||||
[state id args]
|
[state id args]
|
||||||
(log/info "handling " id " args = " args)
|
(log/info "handling " id " args = " args)
|
||||||
(go
|
(let [identity (current-identity)]
|
||||||
(let [result (<! (load-whisper-identity))]
|
(set-identity identity)))
|
||||||
(if-let [error (:error result)]
|
|
||||||
(on-error error)
|
|
||||||
(when (not (:value result))
|
|
||||||
(let [result (<! (new-whisper-identity))]
|
|
||||||
(if-let [error (:error result)]
|
|
||||||
(on-error error)
|
|
||||||
(save-whisper-identity (:value result)))))))))
|
|
||||||
|
|
||||||
(defmethod user-data :user-data/set-confirmation-code
|
(defmethod user-data :user-data/set-confirmation-code
|
||||||
[state id confirmation-code]
|
[state id confirmation-code]
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
(defonce app-state (atom {:component nil
|
(defonce app-state (atom {:component nil
|
||||||
:loading false
|
:loading false
|
||||||
:user-phone-number nil
|
:user-phone-number nil
|
||||||
:user-whisper-identity nil
|
:user-identity nil
|
||||||
:confirmation-code nil
|
:confirmation-code nil
|
||||||
:channels {:pub-sub-publisher (chan)
|
:channels {:pub-sub-publisher (chan)
|
||||||
:pub-sub-publication nil}}))
|
:pub-sub-publication nil}}))
|
||||||
|
|
Loading…
Reference in New Issue