saved firebase tokens now used to push messages
This commit is contained in:
parent
60888fd63c
commit
a1cccbf270
@ -63,4 +63,12 @@ defmodule Bump.Database do
|
|||||||
Repo.insert(%Sender{sender: sender, firebase_token: firebase})
|
Repo.insert(%Sender{sender: sender, firebase_token: firebase})
|
||||||
end
|
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
|
end
|
||||||
|
@ -4,9 +4,10 @@ defmodule Bump.Firebase do
|
|||||||
IO.puts "Hello, world!"
|
IO.puts "Hello, world!"
|
||||||
end
|
end
|
||||||
|
|
||||||
def push(sender, message) do
|
|
||||||
IO.puts "Pushing #{message} to #{sender}"
|
def push(%{firebase_token: token}, message) do
|
||||||
n = Pigeon.FCM.Notification.new({:token, "dTm8S2bfTdKYQTjrxnwFFg:APA91bHGgM7IdRS5uxD0ljmwmP6cAec2icX0VBs69iRB2ApsohyOWzTzontO7cBkjNYbWV87zvxrXIs5jHkJ-8mSWa_-RiU2Y8-XEy3g-Fep3z6dhDeM3KazP58jDRgbdB5cVpDcIEWL"}, %{"body" => message})
|
IO.puts "Pushing #{message} to #{token}"
|
||||||
|
n = Pigeon.FCM.Notification.new({:token, token}, %{"body" => message})
|
||||||
Bump.FCM.push(n)
|
Bump.FCM.push(n)
|
||||||
%{status: 'cheese'}
|
%{status: 'cheese'}
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,11 @@ defmodule Bump.Messages do
|
|||||||
|
|
||||||
def push(sender, message) do
|
def push(sender, message) do
|
||||||
Database.push(sender, message)
|
Database.push(sender, message)
|
||||||
Firebase.push(sender, message)
|
tokens = Database.tokens(sender)
|
||||||
|
|
||||||
|
for token <- tokens do
|
||||||
|
Firebase.push(token, message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user