diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 79bdfef65a..4f4d0825eb 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -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 diff --git a/src/status_im/discovery/handlers.cljs b/src/status_im/discovery/handlers.cljs index 533505dcfa..751f91e633 100644 --- a/src/status_im/discovery/handlers.cljs +++ b/src/status_im/discovery/handlers.cljs @@ -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! diff --git a/src/status_im/protocol/listeners.cljs b/src/status_im/protocol/listeners.cljs index e08781e0c0..aa3c3f347b 100644 --- a/src/status_im/protocol/listeners.cljs +++ b/src/status_im/protocol/listeners.cljs @@ -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)))))))