fix loaded identity string instead of map

This commit is contained in:
michaelr 2016-03-20 13:56:41 +02:00
parent 6d2ac3a99b
commit ca2fa03e3d
8 changed files with 18 additions and 21 deletions

View File

@ -14,8 +14,7 @@
[messenger.android.contacts-list :refer [contacts-list]]
[messenger.android.chat :refer [chat]]
[messenger.comm.pubsub :as pubsub]
[messenger.comm.intercom :as intercom :refer [load-user-phone-number
load-user-identity]]
[messenger.comm.intercom :as intercom :refer [load-user-phone-number]]
[messenger.protocol.protocol-handler :refer [make-handler]]
[syng-im.protocol.api :refer [init-protocol]]
[messenger.init :refer [init-simple-store]]))
@ -67,6 +66,5 @@
(pubsub/setup-pub-sub)
(init-protocol (make-handler))
(load-user-phone-number)
(load-user-identity)
(om/add-root! state/reconciler AppRoot 1)
(.registerComponent app-registry "Messenger" (fn [] app-root)))

View File

@ -22,9 +22,6 @@
;; :service [service_name action_id args_map]
(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]
(publish! :service [:user-data :user-data/set-confirmation-code confirmation-code]))

View File

@ -1,15 +1,17 @@
(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.utils.encryption :refer [password-encrypt
password-decrypt]]))
password-decrypt]]
[messenger.utils.types :refer [to-edn-string]]))
(defn set-initialized [initialized?]
(swap! state/app-state assoc-in state/protocol-initialized-path initialized?))
(defn update-identity [identity]
(let [password (get-in @state/app-state state/identity-password-path)
encrypted (->> (str identity)
encrypted (->> (to-edn-string identity)
(password-encrypt password))]
(s/put (state/kv-store) :identity encrypted)))
@ -17,4 +19,5 @@
(let [encrypted (s/get (state/kv-store) :identity)
password (get-in @state/app-state state/identity-password-path)]
(when encrypted
(password-decrypt password encrypted))))
(-> (password-decrypt password encrypted)
(read-string)))))

View File

@ -1,7 +1,8 @@
(ns messenger.persistence.realm
(:require [cljs.reader :refer [read-string]]
[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"))

View File

@ -1,6 +1,7 @@
(ns messenger.persistence.simple-kv-store
(: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 []
st/Storage
@ -8,7 +9,7 @@
(r/write
(fn []
(r/create :kv-store {:key key
:value (with-out-str (pr value))} true))))
:value (to-edn-string value)} true))))
(get [_ key]
(some-> (r/get-by-field :kv-store :key key)
(r/single-cljs)

View File

@ -2,7 +2,7 @@
(:require [messenger.models.protocol :refer [set-initialized
update-identity]]
[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]))
(defmulti protocol (fn [state id args]
@ -12,7 +12,7 @@
[state id {:keys [identity] :as args}]
(log/debug "handling " id "args = " args)
(update-identity identity)
(load-user-identity)
(set-identity identity)
(set-initialized true))
(defmethod protocol :protocol/save-new-msg

View File

@ -28,12 +28,6 @@
(log/debug "handling " id "args = " args)
(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
[state id confirmation-code]
(log/info "handling " id " args = " confirmation-code)

View File

@ -4,3 +4,6 @@
(if (keyword? s)
(name s)
s))
(defn to-edn-string [value]
(with-out-str (pr value)))