diff --git a/lib/bump/database.ex b/lib/bump/database.ex index 3cd5134..8ee4ea9 100644 --- a/lib/bump/database.ex +++ b/lib/bump/database.ex @@ -63,4 +63,12 @@ defmodule Bump.Database do Repo.insert(%Sender{sender: sender, firebase_token: firebase}) end + def tokens(sender) do + query = from s in "senders", + where: s.sender == ^sender, + select: %{firebase_token: s.firebase_token} + + Repo.all(query) + end + end diff --git a/lib/bump/firebase.ex b/lib/bump/firebase.ex index 076f1ff..f0d86e0 100644 --- a/lib/bump/firebase.ex +++ b/lib/bump/firebase.ex @@ -4,9 +4,10 @@ defmodule Bump.Firebase do IO.puts "Hello, world!" end - def push(sender, message) do - IO.puts "Pushing #{message} to #{sender}" - n = Pigeon.FCM.Notification.new({:token, "dTm8S2bfTdKYQTjrxnwFFg:APA91bHGgM7IdRS5uxD0ljmwmP6cAec2icX0VBs69iRB2ApsohyOWzTzontO7cBkjNYbWV87zvxrXIs5jHkJ-8mSWa_-RiU2Y8-XEy3g-Fep3z6dhDeM3KazP58jDRgbdB5cVpDcIEWL"}, %{"body" => message}) + + def push(%{firebase_token: token}, message) do + IO.puts "Pushing #{message} to #{token}" + n = Pigeon.FCM.Notification.new({:token, token}, %{"body" => message}) Bump.FCM.push(n) %{status: 'cheese'} end diff --git a/lib/bump/messages.ex b/lib/bump/messages.ex index c764ed8..7aa11e3 100644 --- a/lib/bump/messages.ex +++ b/lib/bump/messages.ex @@ -20,7 +20,11 @@ defmodule Bump.Messages do def push(sender, message) do Database.push(sender, message) - Firebase.push(sender, message) + tokens = Database.tokens(sender) + + for token <- tokens do + Firebase.push(token, message) + end end