Push notifications: iOS request permissions, listen for token, flags

- Asks for permissions on iOS at startup
- Introduce NOTIFICATIONS_WIP_ENABLED flag
- Surface FCM Token and put it in clipboard for QA manual end to end testing
- Listen for FCM RefreshToken event at root
This commit is contained in:
Oskar Thorén 2017-09-04 19:34:05 +02:00 committed by Roman Volosovskyi
parent c1cac1eb7c
commit aaa13b922b
9 changed files with 59 additions and 10 deletions

3
.env
View File

@ -1,2 +1,3 @@
TESTFAIRY_ENABLED=0
WALLET_WIP_ENABLED=1
WALLET_WIP_ENABLED=1
NOTIFICATIONS_WIP_ENABLED=1

View File

@ -1,2 +1,3 @@
TESTFAIRY_ENABLED=1
WALLET_WIP_ENABLED=1
WALLET_WIP_ENABLED=1
NOTIFICATIONS_WIP_ENABLED=1

View File

@ -1,2 +1,3 @@
TESTFAIRY_ENABLED=0
WALLET_WIP_ENABLED=0
WALLET_WIP_ENABLED=0
NOTIFICATIONS_WIP_ENABLED=0

View File

@ -9,7 +9,10 @@
[status-im.ui.screens.views :as views]
[status-im.components.react :as react]
[status-im.components.status :as status]
[status-im.utils.error-handler :as error-handler]))
[status-im.utils.error-handler :as error-handler]
[status-im.utils.utils :as utils]
[status-im.utils.config :as config]
[status-im.utils.notifications :as notifications]))
(defn init-back-button-handler! []
(let [new-listener (fn []
@ -62,6 +65,10 @@
(dispatch [:set :keyboard-height 0])))
(.hide react/splash-screen)
(.addEventListener react/app-state "change" app-state-change-handler))
:component-did-mount
(fn []
(when config/notifications-wip-enabled?
(notifications/on-refresh-fcm-token)))
:component-will-unmount
(fn []
(.stop react/http-bridge)

View File

@ -9,7 +9,10 @@
[status-im.ui.screens.views :as views]
[status-im.components.react :as react]
[status-im.components.status :as status]
[status-im.utils.error-handler :as error-handler]))
[status-im.utils.error-handler :as error-handler]
[status-im.utils.utils :as utils]
[status-im.utils.config :as config]
[status-im.utils.notifications :as notifications]))
(defn orientation->keyword [o]
(keyword (.toLowerCase o)))
@ -37,6 +40,11 @@
#(when-not (= 0 @keyboard-height)
(dispatch [:set :keyboard-height 0])))
(.hide react/splash-screen))
:component-did-mount
(fn []
(when config/notifications-wip-enabled?
(notifications/request-permissions)
(notifications/on-refresh-fcm-token)))
:component-will-unmount
(fn []
(.stop react/http-bridge))

View File

@ -103,6 +103,11 @@
(i18n/label :testfairy-title)
(i18n/label :testfairy-message)))))
(reg-fx
::get-fcm-token-fx
(fn []
(notifications/get-fcm-token)))
;;;; Handlers
(register-handler-db
@ -200,6 +205,11 @@
(fn [{{:keys [webview-bridge]} :db} _]
(.geoPermissionsGranted webview-bridge)))
(register-handler-fx
:get-fcm-token
(fn [_ _]
{::get-fcm-token-fx nil}))
(register-handler-fx
:signal-event
(fn [_ [_ event-str]]

View File

@ -3,6 +3,7 @@
[status-im.utils.handlers :as handlers]
[status-im.utils.prices :as prices]
[status-im.utils.transactions :as transactions]
[status-im.utils.utils :as utils]
[status-im.ui.screens.wallet.db :as wallet.db]
[status-im.components.status :as status]
[status-im.ui.screens.wallet.navigation]

View File

@ -10,4 +10,5 @@
(defn enabled? [v] (= "1" v))
(def testfairy-enabled? (enabled? (get-config :TESTFAIRY_ENABLED)))
(def wallet-wip-enabled? (enabled? (get-config :WALLET_WIP_ENABLED 0)))
(def wallet-wip-enabled? (enabled? (get-config :WALLET_WIP_ENABLED 0)))
(def notifications-wip-enabled? (enabled? (get-config :NOTIFICATIONS_WIP_ENABLED 0)))

View File

@ -1,10 +1,29 @@
(ns status-im.utils.notifications
(:require [status-im.react-native.js-dependencies :as rn]))
(:require [status-im.react-native.js-dependencies :as rn]
[status-im.utils.config :as config]
[status-im.utils.utils :as utils]
[status-im.components.react :refer [copy-to-clipboard]]
[taoensso.timbre :as log]))
;; Work in progress namespace responsible for push notifications and interacting
;; with Firebase Cloud Messaging.
;; NOTE: Only need to explicitly request permissions on iOS.
(defn request-permissions []
(.requestPermissions (.-default rn/react-native-fcm)))
(defn get-fcm-token []
(let [fcm (aget rn/react-native-fcm "default")]
(.then ((.-getFCMToken fcm))
(fn [x] (println "*** FCM TOKEN" x)))))
(-> (.getFCMToken (aget rn/react-native-fcm "default"))
(.then (fn [x]
(when config/notifications-wip-enabled?
(log/info "FCM token" x)
(copy-to-clipboard x)
(utils/show-popup "INFO" (str "FCM Token in clipboard: " x)))))))
(defn on-refresh-fcm-token []
(.on (.-default rn/react-native-fcm)
(.-RefreshToken (.-FCMEvent rn/react-native-fcm))
(fn [x]
(log/info "FCM token refreshed" x)
(copy-to-clipboard x)
(utils/show-popup "INFO" (str "FCM token (refreshed) in clipboard: " x)))))