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]
[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"))
(defn generate-contact [n]
{:name (str "Contact " n)
: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)
:datetime "15:30"
:new-messages-count (rand-int 3)
@ -20,7 +20,7 @@
(defn load-contacts [on-success on-error]
(if fake-contacts?
(on-success (generate-contacts 100))
(on-success (generate-contacts 10))
(.getAll react-native-contacts
(fn [error raw-contacts]
(if (not error)

View File

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