This commit is contained in:
Roman Volosovskyi 2017-02-17 18:56:50 +02:00
parent c1abe16f89
commit 42c356f604
2 changed files with 49 additions and 45 deletions

View File

@ -163,20 +163,3 @@
(reg-handler ::clear-commands-callbacks (reg-handler ::clear-commands-callbacks
(fn [db [chat-id]] (fn [db [chat-id]]
(assoc-in db [::commands-callbacks chat-id] nil))) (assoc-in db [::commands-callbacks chat-id] nil)))
(reg-handler :load-default-contacts!
(u/side-effect!
(fn [{:keys [chats]}]
(doseq [[id {:keys [name photo-path public-key add-chat?
dapp? dapp-url dapp-hash]}] js-res/default-contacts]
(let [id' (clojure.core/name id)]
(when-not (chats id')
(when add-chat?
(dispatch [:add-chat id' {:name (:en name)}]))
(dispatch [:add-contacts [{:whisper-identity id'
:name (:en name)
:photo-path photo-path
:public-key public-key
:dapp? dapp?
:dapp-url (:en dapp-url)
:dapp-hash dapp-hash}]])))))))

View File

@ -13,7 +13,8 @@
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[cljs.reader :refer [read-string]])) [cljs.reader :refer [read-string]]
[status-im.utils.js-resources :as js-res]))
(defmethod nav/preload-data! :group-contacts (defmethod nav/preload-data! :group-contacts
[db [_ _ group]] [db [_ _ group]]
@ -185,17 +186,37 @@
(update :contacts merge new-contacts') (update :contacts merge new-contacts')
(assoc :new-contacts (vals new-contacts'))))) (assoc :new-contacts (vals new-contacts')))))
(register-handler :add-contacts
(after save-contacts!)
add-new-contacts)
(defn public-key->address [public-key] (defn public-key->address [public-key]
(let [length (count public-key) (let [length (count public-key)
normalized-key (case length normalized-key (case length
132 (subs public-key 4) 132 (subs public-key 4)
130 (subs public-key 2) 130 (subs public-key 2)
128 public-key)] 128 public-key
(subs (.sha3 js/Web3.prototype normalized-key #js {:encoding "hex"}) 26))) nil)]
(when normalized-key
(subs (.sha3 js/Web3.prototype normalized-key #js {:encoding "hex"}) 26))))
(register-handler :load-default-contacts!
(u/side-effect!
(fn [{:keys [chats]}]
(doseq [[id {:keys [name photo-path public-key add-chat?
dapp? dapp-url dapp-hash]}] js-res/default-contacts]
(let [id' (clojure.core/name id)]
(when-not (chats id')
(when add-chat?
(dispatch [:add-chat id' {:name (:en name)}]))
(dispatch [:add-contacts [{:whisper-identity id'
:address (public-key->address id')
:name (:en name)
:photo-path photo-path
:public-key public-key
:dapp? dapp?
:dapp-url (:en dapp-url)
:dapp-hash dapp-hash}]])))))))
(register-handler :add-contacts
(after save-contacts!)
add-new-contacts)
(defn add-new-contact [db [_ {:keys [whisper-identity] :as contact}]] (defn add-new-contact [db [_ {:keys [whisper-identity] :as contact}]]
(-> db (-> db