From ca2fa03e3d099ddd3e32005a04ea8b1c471da682 Mon Sep 17 00:00:00 2001 From: michaelr Date: Sun, 20 Mar 2016 13:56:41 +0200 Subject: [PATCH] fix loaded identity string instead of map --- src/messenger/android/core.cljs | 4 +--- src/messenger/comm/intercom.cljs | 3 --- src/messenger/models/protocol.cljs | 11 +++++++---- src/messenger/persistence/realm.cljs | 3 ++- src/messenger/persistence/simple_kv_store.cljs | 5 +++-- src/messenger/services/protocol.cljs | 4 ++-- src/messenger/services/user_data.cljs | 6 ------ src/messenger/utils/types.cljs | 3 +++ 8 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/messenger/android/core.cljs b/src/messenger/android/core.cljs index cc410e34c1..700758c5bf 100644 --- a/src/messenger/android/core.cljs +++ b/src/messenger/android/core.cljs @@ -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))) diff --git a/src/messenger/comm/intercom.cljs b/src/messenger/comm/intercom.cljs index aa033c28a8..2997e24f78 100644 --- a/src/messenger/comm/intercom.cljs +++ b/src/messenger/comm/intercom.cljs @@ -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])) diff --git a/src/messenger/models/protocol.cljs b/src/messenger/models/protocol.cljs index 17f4432d30..ea89f2aa5b 100644 --- a/src/messenger/models/protocol.cljs +++ b/src/messenger/models/protocol.cljs @@ -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))))) diff --git a/src/messenger/persistence/realm.cljs b/src/messenger/persistence/realm.cljs index 76dcac277a..f2dd4088cd 100644 --- a/src/messenger/persistence/realm.cljs +++ b/src/messenger/persistence/realm.cljs @@ -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")) diff --git a/src/messenger/persistence/simple_kv_store.cljs b/src/messenger/persistence/simple_kv_store.cljs index 073b915599..75f243e846 100644 --- a/src/messenger/persistence/simple_kv_store.cljs +++ b/src/messenger/persistence/simple_kv_store.cljs @@ -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) diff --git a/src/messenger/services/protocol.cljs b/src/messenger/services/protocol.cljs index 148b034e62..036ca1fe9b 100644 --- a/src/messenger/services/protocol.cljs +++ b/src/messenger/services/protocol.cljs @@ -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 diff --git a/src/messenger/services/user_data.cljs b/src/messenger/services/user_data.cljs index 9a5bf143c1..53eee29349 100644 --- a/src/messenger/services/user_data.cljs +++ b/src/messenger/services/user_data.cljs @@ -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) diff --git a/src/messenger/utils/types.cljs b/src/messenger/utils/types.cljs index fed789f0c1..883daf94b0 100644 --- a/src/messenger/utils/types.cljs +++ b/src/messenger/utils/types.cljs @@ -4,3 +4,6 @@ (if (keyword? s) (name s) s)) + +(defn to-edn-string [value] + (with-out-str (pr value))) \ No newline at end of file