Merge pull request #321 from status-im/bug/#318

Discoveries bugs (#318)

Former-commit-id: 162952fcd2
This commit is contained in:
Roman Volosovskyi 2016-10-05 13:09:01 +03:00 committed by GitHub
commit c083ec4792
3 changed files with 42 additions and 21 deletions

View File

@ -218,6 +218,7 @@
:photo-path profile-image
:status status
:last-updated timestamp}]
(dispatch [:check-status! contact payload])
(dispatch [:update-contact! contact])
(when (chats from)
(dispatch [:update-chat! {:chat-id from

View File

@ -1,7 +1,7 @@
(ns status-im.discovery.handlers
(:require [re-frame.core :refer [after dispatch enrich]]
[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.navigation.handlers :as nav]
[status-im.data-store.discovery :as discoveries]
@ -36,19 +36,37 @@
(register-handler :discovery-response-received
(u/side-effect!
(fn [{:keys [current-public-key] :as db} [_ {:keys [from payload]}]]
(when-not (= current-public-key from)
(let [{:keys [discovery-id profile hashtags]} payload
{:keys [name profile-image status]} profile
discovery {:message-id discovery-id
:name name
:photo-path profile-image
:status status
:whisper-id from
:tags (map #(hash-map :name %) hashtags)
:last-updated (js/Date.)
:priority (calculate-priority db from payload)}]
(dispatch [:add-discovery discovery]))))))
(fn [db [_ {:keys [from payload]}]]
(let [{:keys [discovery-id profile hashtags]} payload
{:keys [name profile-image status]} profile
discovery {:message-id discovery-id
:name name
:photo-path profile-image
:status status
:whisper-id from
:tags (map #(hash-map :name %) hashtags)
:last-updated (js/Date.)
:priority (calculate-priority db from payload)}]
(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
(u/side-effect!

View File

@ -34,15 +34,17 @@
(when-not error
(debug :message-received)
(let [{:keys [from payload to] :as message}
(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)
(js->clj js-message :keywordize-keys true)
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)
message' (assoc message :payload payload'')]
message' (assoc message :payload payload'')]
(callback (if ack? :ack type) message')
(ack/check-ack! web3 from payload'' identity)))))))