Merge pull request #321 from status-im/bug/#318
Discoveries bugs (#318)
Former-commit-id: 162952fcd2
This commit is contained in:
commit
c083ec4792
|
@ -218,6 +218,7 @@
|
||||||
:photo-path profile-image
|
:photo-path profile-image
|
||||||
:status status
|
:status status
|
||||||
:last-updated timestamp}]
|
:last-updated timestamp}]
|
||||||
|
(dispatch [:check-status! contact payload])
|
||||||
(dispatch [:update-contact! contact])
|
(dispatch [:update-contact! contact])
|
||||||
(when (chats from)
|
(when (chats from)
|
||||||
(dispatch [:update-chat! {:chat-id from
|
(dispatch [:update-chat! {:chat-id from
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns status-im.discovery.handlers
|
(ns status-im.discovery.handlers
|
||||||
(:require [re-frame.core :refer [after dispatch enrich]]
|
(:require [re-frame.core :refer [after dispatch enrich]]
|
||||||
[status-im.utils.utils :refer [first-index]]
|
[status-im.utils.utils :refer [first-index]]
|
||||||
[status-im.utils.handlers :refer [register-handler]]
|
[status-im.utils.handlers :refer [register-handler get-hashtags]]
|
||||||
[status-im.protocol.core :as protocol]
|
[status-im.protocol.core :as protocol]
|
||||||
[status-im.navigation.handlers :as nav]
|
[status-im.navigation.handlers :as nav]
|
||||||
[status-im.data-store.discovery :as discoveries]
|
[status-im.data-store.discovery :as discoveries]
|
||||||
|
@ -36,19 +36,37 @@
|
||||||
|
|
||||||
(register-handler :discovery-response-received
|
(register-handler :discovery-response-received
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [current-public-key] :as db} [_ {:keys [from payload]}]]
|
(fn [db [_ {:keys [from payload]}]]
|
||||||
(when-not (= current-public-key from)
|
(let [{:keys [discovery-id profile hashtags]} payload
|
||||||
(let [{:keys [discovery-id profile hashtags]} payload
|
{:keys [name profile-image status]} profile
|
||||||
{:keys [name profile-image status]} profile
|
discovery {:message-id discovery-id
|
||||||
discovery {:message-id discovery-id
|
:name name
|
||||||
:name name
|
:photo-path profile-image
|
||||||
:photo-path profile-image
|
:status status
|
||||||
:status status
|
:whisper-id from
|
||||||
:whisper-id from
|
:tags (map #(hash-map :name %) hashtags)
|
||||||
:tags (map #(hash-map :name %) hashtags)
|
:last-updated (js/Date.)
|
||||||
:last-updated (js/Date.)
|
:priority (calculate-priority db from payload)}]
|
||||||
:priority (calculate-priority db from payload)}]
|
(dispatch [:add-discovery discovery])))))
|
||||||
(dispatch [:add-discovery discovery]))))))
|
|
||||||
|
(register-handler :check-status!
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [db [_ {:keys [whisper-identity status]} payload]]
|
||||||
|
(let [{old-status :status} (contacts/get-contact whisper-identity)]
|
||||||
|
(when (not= old-status status)
|
||||||
|
(let [hashtags (get-hashtags status)]
|
||||||
|
(when-not (empty? hashtags)
|
||||||
|
(let [{:keys [message-id content]} payload
|
||||||
|
{:keys [name profile-image status]} (content :profile)
|
||||||
|
discovery {:message-id message-id
|
||||||
|
:name name
|
||||||
|
:photo-path profile-image
|
||||||
|
:status status
|
||||||
|
:whisper-id whisper-identity
|
||||||
|
:tags (map #(hash-map :name %) hashtags)
|
||||||
|
:last-updated (js/Date.)
|
||||||
|
:priority (calculate-priority db whisper-identity payload)}]
|
||||||
|
(dispatch [:add-discovery discovery])))))))))
|
||||||
|
|
||||||
(register-handler :broadcast-status
|
(register-handler :broadcast-status
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
|
|
|
@ -34,15 +34,17 @@
|
||||||
(when-not error
|
(when-not error
|
||||||
(debug :message-received)
|
(debug :message-received)
|
||||||
(let [{:keys [from payload to] :as message}
|
(let [{:keys [from payload to] :as message}
|
||||||
(js->clj js-message :keywordize-keys true)]
|
(js->clj js-message :keywordize-keys true)
|
||||||
(when-not (= (i/normalize-hex identity)
|
|
||||||
(i/normalize-hex from))
|
|
||||||
(let [{:keys [type ack?] :as payload'}
|
|
||||||
(parse-payload payload)
|
|
||||||
|
|
||||||
content (parse-content (:private keypair) payload' (not= "0x0" to))
|
{:keys [type ack?] :as payload'}
|
||||||
|
(parse-payload payload)]
|
||||||
|
(when (or (not= (i/normalize-hex identity)
|
||||||
|
(i/normalize-hex from))
|
||||||
|
;; allow user to receive his own discoveries
|
||||||
|
(= type :discovery))
|
||||||
|
(let [content (parse-content (:private keypair) payload' (not= "0x0" to))
|
||||||
payload'' (assoc payload' :content content)
|
payload'' (assoc payload' :content content)
|
||||||
|
|
||||||
message' (assoc message :payload payload'')]
|
message' (assoc message :payload payload'')]
|
||||||
(callback (if ack? :ack type) message')
|
(callback (if ack? :ack type) message')
|
||||||
(ack/check-ack! web3 from payload'' identity)))))))
|
(ack/check-ack! web3 from payload'' identity)))))))
|
||||||
|
|
Loading…
Reference in New Issue