Receive whisper identities

This commit is contained in:
virvar 2016-03-10 22:31:43 +03:00
parent 56f249e9fb
commit 7cf1b5b0b9
2 changed files with 17 additions and 10 deletions

View File

@ -2,14 +2,14 @@
(:require [messenger.state :as state] (:require [messenger.state :as state]
[messenger.android.utils :refer [log toast http-post]])) [messenger.android.utils :refer [log toast http-post]]))
(def fake-contacts? false) (def fake-contacts? true)
(def react-native-contacts (js/require "react-native-contacts")) (def react-native-contacts (js/require "react-native-contacts"))
(defn generate-contact [n] (defn generate-contact [n]
{:name (str "Contact " n) {:name (str "Contact " n)
:photo "" :photo ""
:phone-numbers [{:label "mobile" :number "121212"}] :phone-numbers [{:label "mobile" :number (apply str (repeat 7 n))}]
:delivery-status (if (< (rand) 0.5) :delivered :seen) :delivery-status (if (< (rand) 0.5) :delivered :seen)
:datetime "15:30" :datetime "15:30"
:new-messages-count (rand-int 3) :new-messages-count (rand-int 3)
@ -20,7 +20,7 @@
(defn load-contacts [on-success on-error] (defn load-contacts [on-success on-error]
(if fake-contacts? (if fake-contacts?
(on-success (generate-contacts 100)) (on-success (generate-contacts 10))
(.getAll react-native-contacts (.getAll react-native-contacts
(fn [error raw-contacts] (fn [error raw-contacts]
(if (not error) (if (not error)

View File

@ -24,19 +24,26 @@
:name "contacts-list"})))) :name "contacts-list"}))))
(defn handle-load-contacts-identities-response [identities] (defn handle-load-contacts-identities-response [identities]
;; do not keywordize?
;; save contacts to DB
(show-home-view)) (show-home-view))
(defn get-contacts-by-hash [contacts] (defn get-contacts-by-hash [contacts]
(reduce (fn [m contact] (let [numbers (reduce (fn [numbers contact]
(let [number (get-in contact [:phone-numbers :number]) (into numbers
hash (encrypt number)] (map :number (:phone-numbers contact))))
'()
contacts)]
(reduce (fn [m number]
(let [hash (encrypt number)]
(assoc m hash number))) (assoc m hash number)))
contacts)) {}
numbers)))
(defn send-load-contacts-identities [contacts] (defn send-load-contacts-identities [contacts]
(let [contacts-by-hash (get-contacts-by-hash contacts) (let [contacts-by-hash (get-contacts-by-hash contacts)
data (keys contacts-by-hash)] data (keys contacts-by-hash)]
(http-post "get-contacts" data (http-post "get-contacts" {:phone-numbers data}
handle-load-contacts-identities-response handle-load-contacts-identities-response
(fn [error] (fn [error]
(toast (str error)))))) (toast (str error))))))
@ -53,7 +60,7 @@
"Confirmed" "Confirmed"
"Wrong code")) "Wrong code"))
(when (:confirmed body) (when (:confirmed body)
(show-home-view))) (load-contacts)))
(defn code-valid? [code] (defn code-valid? [code]
(= 4 (count code))) (= 4 (count code)))