From 9ab7ebdcf2fb8e6a8d9669e18bf05be52b871a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Thor=C3=A9n?= Date: Thu, 21 Sep 2017 17:14:23 +0200 Subject: [PATCH] Push notifications: Print notif and data payload when resuming app - on-notification listener registered in root component - print data (hardcoded keys) and notif payload to debug --- src/status_im/android/core.cljs | 4 +++- src/status_im/ios/core.cljs | 3 ++- src/status_im/utils/notifications.cljs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index be62d25545..1518d1b4fe 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -68,7 +68,9 @@ :component-did-mount (fn [] (when config/notifications-wip-enabled? - (notifications/on-refresh-fcm-token))) + (notifications/on-refresh-fcm-token) + ;; TODO(oskarth): Background click_action handler + (notifications/on-notification))) :component-will-unmount (fn [] (.stop react/http-bridge) diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index c2fee30082..3d99905655 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -44,7 +44,8 @@ (fn [] (when config/notifications-wip-enabled? (notifications/request-permissions) - (notifications/on-refresh-fcm-token))) + (notifications/on-refresh-fcm-token) + (notifications/on-notification))) :component-will-unmount (fn [] (.stop react/http-bridge)) diff --git a/src/status_im/utils/notifications.cljs b/src/status_im/utils/notifications.cljs index 49b410b9e1..3fe16e94a5 100644 --- a/src/status_im/utils/notifications.cljs +++ b/src/status_im/utils/notifications.cljs @@ -32,3 +32,16 @@ (fn [x] (log/debug "on-refresh-fcm-token: " x) (dispatch [:update-fcm-token x])))) + +;; TODO(oskarth): Only called in background on iOS right now. +;; NOTE(oskarth): Hardcoded data keys :sum and :msg in status-go right now. +(defn on-notification [] + (.on (.-default rn/react-native-fcm) + (.-Notification (.-FCMEvent rn/react-native-fcm)) + (fn [event-js] + (let [event (js->clj event-js :keywordize-keys true) + data (select-keys event [:sum :msg]) + aps (:aps event)] + (log/debug "on-notification event: " (pr-str event)) + (log/debug "on-notification aps: " (pr-str aps)) + (log/debug "on-notification data: " (pr-str data))))))