Skip to content

Commit

Permalink
Merge pull request #3 from spinneyio/feature/andoid-aps-different-badge
Browse files Browse the repository at this point in the history
Handle different badges for android and aps notifications
  • Loading branch information
WojtAcht committed Nov 3, 2021
2 parents 36440b2 + 590b446 commit 55c37cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Clojure wrap for Firebase Cloud Messaging that allows You to send push notificat
### Installation
Leiningen coordinates:
```clj
[clj-push-notifications "1.0.3"]
[clj-push-notifications "1.0.4"]
```
### Example of usage:
First get Your credentials (google-services.json file) from Firebase console, and add them to Your project path (or some config file):
Expand All @@ -22,7 +22,7 @@ First get Your credentials (google-services.json file) from Firebase console, an
(assoc :token "some-firebase-token")
(assoc :title "Hi,")
(assoc :message "Hello world!")
(assoc :badge 1)
(assoc :badges {:android 1 :aps 2})
(assoc :custom-field "my-field")
(assoc :custom-data "Some data")))

Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject clj-push-notifications "1.0.3"
(defproject clj-push-notifications "1.0.4"
:description "Firebase cloud messaging client."
:url "https://github.com/spinneyio/clj-push-notifications"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
17 changes: 9 additions & 8 deletions src/clj_push_notifications/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
(defn delete-firebase []
(.delete (FirebaseApp/getInstance)))

(defn- get-notification [builder title message badge custom-field custom-data type]
(defn- get-notification [builder title message badges custom-field custom-data type]
(assert (string? custom-field))
(assert (int? badge))
(assert (int? (:android badges)))
(assert (int? (:aps badges)))
(assert (string? type))
(let [notification (Notification. title message)

Expand All @@ -39,7 +40,7 @@
(.setColor "#f45342")
(.setTitle title)
(.setClickAction type)
(.setNotificationCount badge))
(.setNotificationCount (:android badges)))

android-notification (.build android-notification)

Expand All @@ -51,7 +52,7 @@
android-config (.build android-config)

aps (doto (Aps/builder)
(.setBadge badge)
(.setBadge (:aps badges))
(.putCustomData custom-field custom-data)
(.setCategory type))

Expand All @@ -69,18 +70,18 @@
message))


(defn send-notification [{:keys [token title message badge custom-field custom-data type]}]
(defn send-notification [{:keys [token title message badges custom-field custom-data type]}]
(let [custom-field (or custom-field "")
custom-data (or custom-data "")
message (get-notification (Message/builder) title message badge custom-field custom-data type)
message (get-notification (Message/builder) title message badges custom-field custom-data type)
message-with-token (.setToken message token)
builded (.build message-with-token)]
(future (.send (FirebaseMessaging/getInstance) builded))))

(defn send-multicast-notifications [{:keys [tokens title message badge custom-field custom-data type]}]
(defn send-multicast-notifications [{:keys [tokens title message badges custom-field custom-data type]}]
(let [custom-field (or custom-field "")
custom-data (or custom-data "")
message (get-notification (MulticastMessage/builder) title message badge custom-field custom-data type)
message (get-notification (MulticastMessage/builder) title message badges custom-field custom-data type)
message-with-token (.addAllTokens message tokens)
built (.build message-with-token)]
(future (.sendMulticast (FirebaseMessaging/getInstance) built))))

0 comments on commit 55c37cf

Please sign in to comment.