Skip to content

Commit

Permalink
New version 1.0.5 - add send-message and send-multicast-message funct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
WojtAcht committed Mar 21, 2022
1 parent 55c37cf commit c6500cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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.4"]
[clj-push-notifications "1.0.5"]
```
### 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 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.4"
(defproject clj-push-notifications "1.0.5"
: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
18 changes: 16 additions & 2 deletions src/clj_push_notifications/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@
(.setApnsConfig apns-config))]
message))

(defn- get-message [builder data]
(reduce (fn [builder [k v]] (.putData builder k v)) builder data))

(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 badges custom-field custom-data type)
message-with-token (.setToken message token)
builded (.build message-with-token)]
(future (.send (FirebaseMessaging/getInstance) builded))))
built (.build message-with-token)]
(future (.send (FirebaseMessaging/getInstance) built))))

(defn send-multicast-notifications [{:keys [tokens title message badges custom-field custom-data type]}]
(let [custom-field (or custom-field "")
Expand All @@ -85,3 +87,15 @@
message-with-token (.addAllTokens message tokens)
built (.build message-with-token)]
(future (.sendMulticast (FirebaseMessaging/getInstance) built))))

(defn send-message [{:keys [token data]}]
(let [message (get-message (Message/builder) data)
message-with-token (.setToken message token)
built (.build message-with-token)]
(future (.send (FirebaseMessaging/getInstance) built))))

(defn send-multicast-messages [{:keys [tokens data]}]
(let [message (get-message (MulticastMessage/builder) data)
message-with-tokens (.addAllTokens message tokens)
built (.build message-with-tokens)]
(future (.send (FirebaseMessaging/getInstance) built))))

0 comments on commit c6500cc

Please sign in to comment.