Skip to content

Commit

Permalink
handle signal
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos committed Feb 10, 2022
1 parent 67813a5 commit c0d01ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[status-im.node.core :as node]
[status-im.utils.mobile-sync :as mobile-network-utils]
[status-im.navigation :as navigation]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]))

Expand All @@ -28,14 +27,6 @@
(defn connected? [db id]
(= (:mailserver/current-id db) id))

(def whisper-opts
{;; time drift that is tolerated by whisper, in seconds
:whisper-drift-tolerance 10
;; ttl of 10 sec
:ttl 10
:powTarget config/pow-target
:powTime config/pow-time})

(defn fetch [db id]
(get-in db [:mailserver/mailservers (node/current-fleet-key db) id]))

Expand Down Expand Up @@ -102,6 +93,14 @@
(log/error "failed retrieve historical messages" %)
(re-frame/dispatch [::disconnect-from-mailserver]))}]}))

(fx/defn handle-mailserver-changed
[{:keys [db] :as cofx} ms]
(if (seq ms)
(fx/merge cofx
{:db (assoc db :mailserver/state :connected)}
(process-next-messages-request))
{:db (assoc db :mailserver/state nil)}))

(fx/defn connected-to-mailserver
[{:keys [db] :as cofx}]
(let [{:keys [address]} (fetch-current db)]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/signals/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"envelope.expired" (transport.message/update-envelopes-status cofx (:ids (js->clj event-js :keywordize-keys true)) :not-sent)
"message.delivered" (let [{:keys [chatID messageID]} (js->clj event-js :keywordize-keys true)]
(models.message/update-db-message-status cofx chatID messageID :delivered))
"mailserver.changed" (mailserver/process-next-messages-request cofx)
"mailserver.changed" (mailserver/handle-mailserver-changed cofx (.-address event-js))
"discovery.summary" (summary cofx (js->clj event-js :keywordize-keys true))
"wakuv2.peerstats" (wakuv2-peer-stats cofx (js->clj event-js :keywordize-keys true))
"subscriptions.data" (ethereum.subscriptions/handle-signal cofx (js->clj event-js :keywordize-keys true))
Expand Down

0 comments on commit c0d01ea

Please sign in to comment.