parent
c471190c1f
commit
cf4d2e45f5
|
@ -14,8 +14,7 @@
|
||||||
[messenger.android.contacts-list :refer [contacts-list]]
|
[messenger.android.contacts-list :refer [contacts-list]]
|
||||||
[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-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]]))
|
||||||
|
@ -67,6 +66,5 @@
|
||||||
(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-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)))
|
||||||
|
|
|
@ -22,9 +22,6 @@
|
||||||
;; :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-identity []
|
|
||||||
(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]))
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
(ns messenger.models.protocol
|
(ns messenger.models.protocol
|
||||||
(:require [messenger.state :as state]
|
(:require [cljs.reader :refer [read-string]]
|
||||||
|
[messenger.state :as state]
|
||||||
[syng-im.protocol.state.storage :as s]
|
[syng-im.protocol.state.storage :as s]
|
||||||
[syng-im.utils.encryption :refer [password-encrypt
|
[syng-im.utils.encryption :refer [password-encrypt
|
||||||
password-decrypt]]))
|
password-decrypt]]
|
||||||
|
[messenger.utils.types :refer [to-edn-string]]))
|
||||||
|
|
||||||
(defn set-initialized [initialized?]
|
(defn set-initialized [initialized?]
|
||||||
(swap! state/app-state assoc-in state/protocol-initialized-path initialized?))
|
(swap! state/app-state assoc-in state/protocol-initialized-path initialized?))
|
||||||
|
|
||||||
(defn update-identity [identity]
|
(defn update-identity [identity]
|
||||||
(let [password (get-in @state/app-state state/identity-password-path)
|
(let [password (get-in @state/app-state state/identity-password-path)
|
||||||
encrypted (->> (str identity)
|
encrypted (->> (to-edn-string identity)
|
||||||
(password-encrypt password))]
|
(password-encrypt password))]
|
||||||
(s/put (state/kv-store) :identity encrypted)))
|
(s/put (state/kv-store) :identity encrypted)))
|
||||||
|
|
||||||
|
@ -17,4 +19,5 @@
|
||||||
(let [encrypted (s/get (state/kv-store) :identity)
|
(let [encrypted (s/get (state/kv-store) :identity)
|
||||||
password (get-in @state/app-state state/identity-password-path)]
|
password (get-in @state/app-state state/identity-password-path)]
|
||||||
(when encrypted
|
(when encrypted
|
||||||
(password-decrypt password encrypted))))
|
(-> (password-decrypt password encrypted)
|
||||||
|
(read-string)))))
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
(ns messenger.persistence.realm
|
(ns messenger.persistence.realm
|
||||||
(:require [cljs.reader :refer [read-string]]
|
(:require [cljs.reader :refer [read-string]]
|
||||||
[syng-im.utils.logging :as log]
|
[syng-im.utils.logging :as log]
|
||||||
[messenger.utils.types :refer [to-string]]))
|
[messenger.utils.types :refer [to-string]])
|
||||||
|
(:refer-clojure :exclude [exists?]))
|
||||||
|
|
||||||
(set! js/Realm (js/require "realm"))
|
(set! js/Realm (js/require "realm"))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns messenger.persistence.simple-kv-store
|
(ns messenger.persistence.simple-kv-store
|
||||||
(:require [syng-im.protocol.state.storage :as st]
|
(:require [syng-im.protocol.state.storage :as st]
|
||||||
[messenger.persistence.realm :as r]))
|
[messenger.persistence.realm :as r]
|
||||||
|
[messenger.utils.types :refer [to-edn-string]]))
|
||||||
|
|
||||||
(defrecord SimpleKvStore []
|
(defrecord SimpleKvStore []
|
||||||
st/Storage
|
st/Storage
|
||||||
|
@ -8,7 +9,7 @@
|
||||||
(r/write
|
(r/write
|
||||||
(fn []
|
(fn []
|
||||||
(r/create :kv-store {:key key
|
(r/create :kv-store {:key key
|
||||||
:value (with-out-str (pr value))} true))))
|
:value (to-edn-string value)} true))))
|
||||||
(get [_ key]
|
(get [_ key]
|
||||||
(some-> (r/get-by-field :kv-store :key key)
|
(some-> (r/get-by-field :kv-store :key key)
|
||||||
(r/single-cljs)
|
(r/single-cljs)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
(:require [messenger.models.protocol :refer [set-initialized
|
(:require [messenger.models.protocol :refer [set-initialized
|
||||||
update-identity]]
|
update-identity]]
|
||||||
[messenger.models.messages :refer [save-message]]
|
[messenger.models.messages :refer [save-message]]
|
||||||
[messenger.comm.intercom :refer [load-user-identity]]
|
[messenger.models.user-data :refer [set-identity]]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
(defmulti protocol (fn [state id args]
|
(defmulti protocol (fn [state id args]
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
[state id {:keys [identity] :as args}]
|
[state id {:keys [identity] :as args}]
|
||||||
(log/debug "handling " id "args = " args)
|
(log/debug "handling " id "args = " args)
|
||||||
(update-identity identity)
|
(update-identity identity)
|
||||||
(load-user-identity)
|
(set-identity identity)
|
||||||
(set-initialized true))
|
(set-initialized true))
|
||||||
|
|
||||||
(defmethod protocol :protocol/save-new-msg
|
(defmethod protocol :protocol/save-new-msg
|
||||||
|
|
|
@ -28,12 +28,6 @@
|
||||||
(log/debug "handling " id "args = " args)
|
(log/debug "handling " id "args = " args)
|
||||||
(load-phone-number))
|
(load-phone-number))
|
||||||
|
|
||||||
(defmethod user-data :user-data/load-identity
|
|
||||||
[state id args]
|
|
||||||
(log/info "handling " id " args = " args)
|
|
||||||
(let [identity (current-identity)]
|
|
||||||
(set-identity identity)))
|
|
||||||
|
|
||||||
(defmethod user-data :user-data/set-confirmation-code
|
(defmethod user-data :user-data/set-confirmation-code
|
||||||
[state id confirmation-code]
|
[state id confirmation-code]
|
||||||
(log/info "handling " id " args = " confirmation-code)
|
(log/info "handling " id " args = " confirmation-code)
|
||||||
|
|
|
@ -4,3 +4,6 @@
|
||||||
(if (keyword? s)
|
(if (keyword? s)
|
||||||
(name s)
|
(name s)
|
||||||
s))
|
s))
|
||||||
|
|
||||||
|
(defn to-edn-string [value]
|
||||||
|
(with-out-str (pr value)))
|
Loading…
Reference in New Issue