fix #812
This commit is contained in:
parent
c1abe16f89
commit
42c356f604
|
@ -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}]])))))))
|
|
||||||
|
|
|
@ -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
|
||||||
|
@ -222,9 +243,9 @@
|
||||||
(register-handler :add-pending-contact
|
(register-handler :add-pending-contact
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [chats contacts]} [_ chat-id]]
|
(fn [{:keys [chats contacts]} [_ chat-id]]
|
||||||
(let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])]
|
(let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])]
|
||||||
(read-string contact-info)
|
(read-string contact-info)
|
||||||
(assoc (get contacts chat-id) :pending false))
|
(assoc (get contacts chat-id) :pending false))
|
||||||
contact' (assoc contact :address (public-key->address chat-id))]
|
contact' (assoc contact :address (public-key->address chat-id))]
|
||||||
(dispatch [::prepare-contact contact'])
|
(dispatch [::prepare-contact contact'])
|
||||||
(dispatch [:watch-contact contact'])
|
(dispatch [:watch-contact contact'])
|
||||||
|
@ -258,21 +279,21 @@
|
||||||
(register-handler
|
(register-handler
|
||||||
:update-keys-received
|
:update-keys-received
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [db [_ {:keys [from payload]}]]
|
(fn [db [_ {:keys [from payload]}]]
|
||||||
(let [{{:keys [public private]} :keypair
|
(let [{{:keys [public private]} :keypair
|
||||||
timestamp :timestamp} payload
|
timestamp :timestamp} payload
|
||||||
prev-last-updated (get-in db [:contacts from :keys-last-updated])]
|
prev-last-updated (get-in db [:contacts from :keys-last-updated])]
|
||||||
(when (<= prev-last-updated timestamp)
|
(when (<= prev-last-updated timestamp)
|
||||||
(let [contact {:whisper-identity from
|
(let [contact {:whisper-identity from
|
||||||
:public-key public
|
:public-key public
|
||||||
:private-key private
|
:private-key private
|
||||||
:keys-last-updated timestamp}]
|
:keys-last-updated timestamp}]
|
||||||
(dispatch [:update-contact! contact])))))))
|
(dispatch [:update-contact! contact])))))))
|
||||||
|
|
||||||
(register-handler
|
(register-handler
|
||||||
:contact-online-received
|
:contact-online-received
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [db [_ {:keys [from]
|
(fn [db [_ {:keys [from]
|
||||||
{{:keys [timestamp]} :content} :payload}]]
|
{{:keys [timestamp]} :content} :payload}]]
|
||||||
(let [prev-last-online (get-in db [:contacts from :last-online])]
|
(let [prev-last-online (get-in db [:contacts from :last-online])]
|
||||||
(when (and timestamp (< prev-last-online timestamp))
|
(when (and timestamp (< prev-last-online timestamp))
|
||||||
|
@ -301,10 +322,10 @@
|
||||||
:open-contact-menu
|
:open-contact-menu
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ list-selection-fn {:keys [name] :as contact}]]
|
(fn [_ [_ list-selection-fn {:keys [name] :as contact}]]
|
||||||
(list-selection-fn {:title name
|
(list-selection-fn {:title name
|
||||||
:options [(label :t/remove-contact)]
|
:options [(label :t/remove-contact)]
|
||||||
:callback (fn [index]
|
:callback (fn [index]
|
||||||
(case index
|
(case index
|
||||||
0 (dispatch [:hide-contact contact])
|
0 (dispatch [:hide-contact contact])
|
||||||
:default))
|
:default))
|
||||||
:cancel-text (label :t/cancel)}))))
|
:cancel-text (label :t/cancel)}))))
|
||||||
|
|
Loading…
Reference in New Issue