parent
62642eadc1
commit
85f7a08380
|
@ -17,7 +17,8 @@
|
|||
[messenger.comm.intercom :as intercom :refer [load-user-phone-number
|
||||
load-user-whisper-identity]]
|
||||
[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]]))
|
||||
|
||||
|
||||
(def app-registry (.-AppRegistry js/React))
|
||||
|
@ -62,6 +63,7 @@
|
|||
(defonce app-root (om/factory RootNode))
|
||||
|
||||
(defn init []
|
||||
(init-simple-store)
|
||||
(pubsub/setup-pub-sub)
|
||||
(init-protocol (make-handler))
|
||||
(load-user-phone-number)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
(ns messenger.init
|
||||
(:require [messenger.persistence.simple-kv-store :as kv]
|
||||
[messenger.state :as state]))
|
||||
|
||||
(defn init-simple-store []
|
||||
(swap! state/app-state assoc-in state/simple-store-path (kv/->SimpleKvStore)))
|
|
@ -1,6 +1,6 @@
|
|||
(ns messenger.models.protocol
|
||||
(:require [messenger.state :as state]
|
||||
[messenger.persistence.realm :as r]))
|
||||
[syng-im.protocol.state.storage :as s]))
|
||||
|
||||
(defn set-initialized [initialized?]
|
||||
(swap! state/app-state assoc-in state/protocol-initialized-path initialized?))
|
||||
|
@ -8,12 +8,7 @@
|
|||
;; TODO at least the private key has to be encrypted with user's password
|
||||
|
||||
(defn update-identity [identity]
|
||||
(r/write
|
||||
(fn []
|
||||
(r/create :kv-store {:key :identity
|
||||
:value (str identity)} true))))
|
||||
(s/put (state/kv-store) :identity identity))
|
||||
|
||||
(defn current-identity []
|
||||
(-> (r/get-by-field :kv-store :key :identity)
|
||||
(r/single-cljs)
|
||||
(r/decode-value)))
|
||||
(s/get (state/kv-store) :identity))
|
||||
|
|
|
@ -61,23 +61,9 @@
|
|||
(defn decode-value [{:keys [key value]}]
|
||||
(read-string value))
|
||||
|
||||
(comment
|
||||
(use 'figwheel-sidecar.repl-api)
|
||||
(cljs-repl)
|
||||
|
||||
(def x (-> (get-by-field :kv-store :key :identity)
|
||||
(single)))
|
||||
|
||||
(aget x 1)
|
||||
|
||||
(defn delete [obj]
|
||||
(write (fn []
|
||||
(.delete realm (-> (get-by-field :kv-store :key :identity)
|
||||
(single)))))
|
||||
|
||||
|
||||
(log/info (.keys js/Object realm))
|
||||
(log/info (clj->js opts))
|
||||
|
||||
(clj->js (clj->js {:a [{:b 123}]}))
|
||||
(.delete realm obj))))
|
||||
|
||||
(comment
|
||||
)
|
|
@ -0,0 +1,26 @@
|
|||
(ns messenger.persistence.simple-kv-store
|
||||
(:require [syng-im.protocol.state.storage :as st]
|
||||
[messenger.persistence.realm :as r]))
|
||||
|
||||
(defrecord SimpleKvStore []
|
||||
st/Storage
|
||||
(put [_ key value]
|
||||
(r/write
|
||||
(fn []
|
||||
(r/create :kv-store {:key key
|
||||
:value (str value)} true))))
|
||||
(get [_ key]
|
||||
(-> (r/get-by-field :kv-store :key key)
|
||||
(r/single-cljs)
|
||||
(r/decode-value)))
|
||||
(contains-key? [_ key]
|
||||
(= 0
|
||||
(.-length (r/get-by-field :kv-store :key key))))
|
||||
(delete [_ key]
|
||||
(-> (r/get-by-field :kv-store :key key)
|
||||
(r/single)
|
||||
(r/delete))))
|
||||
|
||||
(comment
|
||||
|
||||
)
|
|
@ -2,12 +2,13 @@
|
|||
(:require [syng-im.utils.logging :as log]
|
||||
[messenger.constants :refer [ethereum-rpc-url]]
|
||||
[messenger.comm.intercom :refer [protocol-initialized]]
|
||||
[messenger.models.protocol :refer [current-identity]]))
|
||||
[messenger.models.protocol :refer [current-identity]]
|
||||
[messenger.state :refer [kv-store]]))
|
||||
|
||||
(defn make-handler []
|
||||
{:ethereum-rpc-url ethereum-rpc-url
|
||||
:identity (current-identity)
|
||||
:storage nil
|
||||
:storage (kv-store)
|
||||
:handler (fn [{:keys [event-type] :as event}]
|
||||
(log/info "Event:" (clj->js event))
|
||||
(case event-type
|
||||
|
|
|
@ -38,5 +38,8 @@
|
|||
(def pub-sub-path [:channels :pub-sub-publication])
|
||||
(def user-notification-path [:user-notification])
|
||||
(def protocol-initialized-path [:protocol-initialized])
|
||||
(def simple-store-path [:simple-store])
|
||||
|
||||
(defn pub-sub-publisher [app] (get-in app pub-sub-bus-path))
|
||||
(defn kv-store []
|
||||
(get-in @app-state simple-store-path))
|
Loading…
Reference in New Issue