forked from status-im/status-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.cljs
More file actions
47 lines (41 loc) · 1.88 KB
/
notifications.cljs
File metadata and controls
47 lines (41 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns status-im.utils.notifications
(:require [goog.object :as object]
[re-frame.core :as re-frame :refer [dispatch reg-fx]]
[status-im.utils.handlers :as handlers]
[status-im.react-native.js-dependencies :as rn]
[status-im.utils.config :as config]
[status-im.utils.utils :as utils]
[status-im.ui.components.react :refer [copy-to-clipboard]]
[taoensso.timbre :as log]))
;; Work in progress namespace responsible for push notifications and interacting
;; with Firebase Cloud Messaging.
(handlers/register-handler-db
:update-fcm-token
(fn [db [_ fcm-token]]
(assoc-in db [:notifications :fcm-token] fcm-token)))
;; NOTE: Only need to explicitly request permissions on iOS.
(defn request-permissions []
(.requestPermissions (.-default rn/react-native-fcm)))
(defn get-fcm-token []
(-> (.getFCMToken (object/get rn/react-native-fcm "default"))
(.then (fn [x]
(log/debug "get-fcm-token: " x)
(dispatch [:update-fcm-token x])))))
(defn on-refresh-fcm-token []
(.on (.-default rn/react-native-fcm)
(.-RefreshToken (.-FCMEvent rn/react-native-fcm))
(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))))))