Discoveries (fixes #318):

populate discoveries with statuses received from contacts
allow user to receive his own status


Former-commit-id: 1444465e89
This commit is contained in:
Roman Volosovskyi 2016-10-04 16:37:33 +03:00
parent 06332ab8fb
commit 04aa0e8848
3 changed files with 42 additions and 21 deletions

View File

@ -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

View File

@ -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,8 +36,7 @@
(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
@ -48,7 +47,26 @@
: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!

View File

@ -34,13 +34,15 @@
(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'')]