Skip to content

Commit c98f1ad

Browse files
author
Pedro Pombeiro
committed
fixup! Address PR review comments
1 parent 6a91968 commit c98f1ad

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/status_im/notifications/core.cljs

+15-8
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
(log/debug "notifications-denied")
3030
(re-frame/dispatch [:notifications.callback/request-notifications-permissions-denied {}]))))))
3131

32+
(defn valid-notification-payload?
33+
[{:keys [from to] :as payload}]
34+
(and from to))
35+
3236
(defn create-notification-payload
3337
[{:keys [from to] :as payload}]
34-
(if (and from to)
38+
(if (valid-notification-payload? payload)
3539
{:msg (js/JSON.stringify #js {:from from
3640
:to to})}
3741
(throw (str "Invalid push notification payload" payload))))
@@ -48,13 +52,16 @@
4852
(def icon "ic_stat_status_notification")
4953

5054
(defn get-notification-payload [message-js]
51-
(let [data (.. message-js -data) ;; https://github.com/invertase/react-native-firebase/blob/adcbeac3d11585dd63922ef178ff6fd886d5aa9b/src/modules/notifications/Notification.js#L79
52-
msg (js/JSON.parse (object/get data "msg"))
53-
from (object/get msg "from")
54-
to (object/get msg "to")]
55-
(if (and from to)
56-
{:from from
57-
:to to}
55+
;; message-js.-data is Notification.data():
56+
;; https://github.com/invertase/react-native-firebase/blob/adcbeac3d11585dd63922ef178ff6fd886d5aa9b/src/modules/notifications/Notification.js#L79
57+
(let [data (.. message-js -data)
58+
msg (js/JSON.parse (object/get data "msg"))
59+
from (object/get msg "from")
60+
to (object/get msg "to")
61+
payload {:from from
62+
:to to}]
63+
(if (valid-notification-payload? payload)
64+
payload
5865
(log/warn "failed to retrieve notification payload from" (js/JSON.stringify data)))))
5966

6067
(defn display-notification [{:keys [title body from to]}]

0 commit comments

Comments
 (0)