diff --git a/src/legacy/status_im/ui/screens/notifications_settings/events.cljs b/src/legacy/status_im/ui/screens/notifications_settings/events.cljs index 2edeaea9e0..aec2be2629 100644 --- a/src/legacy/status_im/ui/screens/notifications_settings/events.cljs +++ b/src/legacy/status_im/ui/screens/notifications_settings/events.cljs @@ -49,14 +49,14 @@ (rf/defn notification-switch {:events [:push-notifications/switch]} - [{:keys [db] :as cofx} options] + [{:keys [db] :as cofx} desired-settings] (let [profile (:profile/profile db) prev-settings {:notifications-enabled? (:notifications-enabled? profile) :local-push-notifications-enabled? (:local-push-notifications-enabled? profile) :remote-push-notifications-enabled? (:remote-push-notifications-enabled? profile)} next-settings (cond - (and (:notifications-enabled? options) + (and (:notifications-enabled? desired-settings) (not (:notifications-enabled? prev-settings))) (if platform/android? {:notifications-enabled? true @@ -66,46 +66,44 @@ :local-push-notifications-enabled? true :remote-push-notifications-enabled? true}) - (and (not (:notifications-enabled? options)) - (not (nil? (:notifications-enabled? options))) + (and (= false (:notifications-enabled? desired-settings)) (:notifications-enabled? prev-settings)) {:notifications-enabled? false :local-push-notifications-enabled? false :remote-push-notifications-enabled? false} - (and (:notifications-enabled? prev-settings) - (not (:local-push-notifications-enabled? options)) - (not (:local-push-notifications-enabled? prev-settings)) - (not (:remote-push-notifications-enabled? options)) - (not (:remote-push-notifications-enabled? prev-settings))) - {:notifications-enabled? false - :local-push-notifications-enabled? false - :remote-push-notifications-enabled? false} - :else {:notifications-enabled? (:notifications-enabled? prev-settings) :local-push-notifications-enabled? - (if (nil? (:local-push-notifications-enabled? options)) + (if (nil? (:local-push-notifications-enabled? desired-settings)) (:local-push-notifications-enabled? prev-settings) - (:local-push-notifications-enabled? options)) + (:local-push-notifications-enabled? desired-settings)) :remote-push-notifications-enabled? - (if (nil? (:remote-push-notifications-enabled? options)) + (if (nil? (:remote-push-notifications-enabled? desired-settings)) (:remote-push-notifications-enabled? prev-settings) - (:remote-push-notifications-enabled? options))}) - any-disabled? - (or - (and (:local-push-notifications-enabled? prev-settings) - (not (:local-push-notifications-enabled? next-settings))) - (and (:remote-push-notifications-enabled? prev-settings) - (not (:remote-push-notifications-enabled? next-settings))))] + (:remote-push-notifications-enabled? desired-settings))}) + enable-remote? (and (not (:remote-push-notifications-enabled? prev-settings)) + (:remote-push-notifications-enabled? next-settings)) + enable-local? (and (not (:local-push-notifications-enabled? prev-settings)) + (:local-push-notifications-enabled? next-settings)) + disable-local? (and (:local-push-notifications-enabled? prev-settings) + (not (:local-push-notifications-enabled? next-settings))) + disable-remote? (and (:remote-push-notifications-enabled? prev-settings) + (not (:remote-push-notifications-enabled? next-settings))) + any-disabled? (or disable-local? disable-remote?)] (rf/merge cofx - (if (and (:notifications-enabled? next-settings) - (not any-disabled?)) - {:effects/push-notifications-enable {:prev-settings prev-settings - :settings next-settings}} - {:effects/push-notifications-disable {:prev-settings prev-settings - :settings next-settings}}) + (if (and (:notifications-enabled? next-settings) (not any-disabled?)) + {:effects/push-notifications-enable (cond-> {} + enable-remote? + (assoc :enable-remote? true) + enable-local? + (assoc :enable-local? true))} + {:effects/push-notifications-disable (cond-> {} + disable-remote? + (assoc :disable-remote? true) + disable-local? + (assoc :disable-local? true))}) (multiaccounts.update/multiaccount-update :notifications-enabled? (:notifications-enabled? next-settings) {}) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index bd26257652..0143265556 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -114,11 +114,11 @@ [:profile.settings/get-profile-picture key-uid] (when notifications-enabled? [:effects/push-notifications-enable - {:prev-settings {} - :settings {:notifications-enabled? notifications-enabled? - :local-push-notifications-enabled? local-push-notifications-enabled? - :remote-push-notifications-enabled? - remote-push-notifications-enabled?}}])]}))) + (cond-> {} + local-push-notifications-enabled? + (assoc :enable-local? true) + remote-push-notifications-enabled? + (assoc :enable-remote? true))])]}))) ;; Login phase 3: events at this phase can wait a bit longer to be processed in ;; order to leave room for higher-priority or heavy weight events. diff --git a/src/status_im/contexts/profile/logout/events.cljs b/src/status_im/contexts/profile/logout/events.cljs index f0c7eb9afa..ad8dc75747 100644 --- a/src/status_im/contexts/profile/logout/events.cljs +++ b/src/status_im/contexts/profile/logout/events.cljs @@ -5,18 +5,12 @@ (rf/reg-event-fx :profile.logout/disable-notifications - (fn [{:keys [db]}] - (let [profile (:profile/profile db) - prev-settings {:notifications-enabled? (:notifications-enabled? profile) - :local-push-notifications-enabled? (:local-push-notifications-enabled? profile) - :remote-push-notifications-enabled? (:remote-push-notifications-enabled? - profile)}] - {:fx [[:effects/push-notifications-disable - {:prev-settings prev-settings - :settings {:notifications-enabled? false - :local-push-notifications-enabled? false - :remote-push-notifications-enabled? false}}] - [:dispatch [:alert-banners/remove-all]]]}))) + (fn [_cofx] + {:fx [[:effects/push-notifications-disable + {:notifications-enabled? false + :local-push-notifications-enabled? false + :remote-push-notifications-enabled? false}] + [:dispatch [:alert-banners/remove-all]]]})) (defn- restart-app-db [{:keys [initials-avatar-font-file keycard biometrics diff --git a/src/status_im/contexts/profile/push_notifications/effects.cljs b/src/status_im/contexts/profile/push_notifications/effects.cljs index 9b3d490087..1355830b20 100644 --- a/src/status_im/contexts/profile/push_notifications/effects.cljs +++ b/src/status_im/contexts/profile/push_notifications/effects.cljs @@ -39,19 +39,14 @@ (disable-remote-notifications)) (defn enable-android-notifications - [{:keys [prev-settings settings]}] - (let [enable-remote? (and (not (:remote-push-notifications-enabled? prev-settings)) - (:remote-push-notifications-enabled? settings) - (not config/google-free)) - enable-local? (and (not (:local-push-notifications-enabled? prev-settings)) - (:local-push-notifications-enabled? settings))] - (when enable-remote? - (enable-remote-notifications {})) - (when enable-local? - (native-module.pn/create-channel - {:channel-id "status-im-notifications" - :channel-name "Status push notifications"}) - (native-module.pn/enable-notifications)))) + [{:keys [enable-remote? enable-local?]}] + (when (and enable-remote? (not config/google-free)) + (enable-remote-notifications {})) + (when enable-local? + (native-module.pn/create-channel + {:channel-id "status-im-notifications" + :channel-name "Status push notifications"}) + (native-module.pn/enable-notifications))) (defn enable-push-notifications [settings] @@ -60,16 +55,11 @@ (enable-ios-notifications settings))) (defn disable-android-notifications - [{:keys [prev-settings settings]}] - (let [disable-local? (and (:local-push-notifications-enabled? prev-settings) - (not (:local-push-notifications-enabled? settings))) - disable-remote? (and (:remote-push-notifications-enabled? prev-settings) - (not (:remote-push-notifications-enabled? settings)) - (not config/google-free))] - (when disable-remote? - (disable-remote-notifications)) - (when disable-local? - (native-module.pn/disable-notifications))) + [{:keys [disable-local? disable-remote?]}] + (when (and disable-remote? (not config/google-free)) + (disable-remote-notifications)) + (when disable-local? + (native-module.pn/disable-notifications)) ;; (native-module.pn/clear-all-message-notifications) )