Eric Dvorsak 203f399aca
use from parameter for mailserver requests
Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
2018-05-29 10:19:08 +02:00

43 lines
1.5 KiB
Clojure

(ns status-im.network.events
(:require [re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.network.net-info :as net-info]
[status-im.native-module.core :as status]
[status-im.transport.inbox :as inbox]))
(re-frame/reg-fx
::listen-to-network-status
(fn [[connection-listener net-info-listener]]
(net-info/is-connected? connection-listener)
(net-info/net-info net-info-listener)
(net-info/add-connection-listener connection-listener)
(net-info/add-net-info-listener net-info-listener)))
(re-frame/reg-fx
::notify-status-go
(fn [data]
(status/connection-change data)))
(handlers/register-handler-fx
:listen-to-network-status
(fn []
{::listen-to-network-status [#(re-frame/dispatch [::update-connection-status %])
#(re-frame/dispatch [::update-network-status %])]}))
(handlers/register-handler-fx
::update-connection-status
[re-frame/trim-v]
(fn [{{:keys [network-status mailserver-status] :as db} :db :as cofx} [is-connected?]]
(cond-> (handlers-macro/merge-fx cofx
{:db (assoc db :network-status (if is-connected? :online :offline))}
(inbox/request-messages))
is-connected?
(assoc :drain-mixpanel-events nil))))
(handlers/register-handler-fx
::update-network-status
[re-frame/trim-v]
(fn [_ [data]]
{::notify-status-go data}))