planning-poker/lib/planningpoker_web/channels/presence.ex

33 lines
900 B
Elixir
Raw Normal View History

2020-05-06 05:30:43 +00:00
defmodule PlanningpokerWeb.Presence do
@moduledoc """
Provides presence tracking to channels and processes.
See the [`Phoenix.Presence`](http://hexdocs.pm/phoenix/Phoenix.Presence.html)
docs for more details.
"""
use Phoenix.Presence, otp_app: :planningpoker,
pubsub_server: Planningpoker.PubSub
2020-05-08 03:43:02 +00:00
require Logger
alias Planningpoker.Db
2020-05-08 04:34:42 +00:00
def fetch("room:" <> room, entries) do
2020-05-08 04:46:37 +00:00
players =
2020-05-08 03:43:02 +00:00
entries
|> Map.keys()
2020-05-08 04:46:37 +00:00
|> Db.get_players(room)
|> Enum.into(%{}, fn {{u, _r}, v} -> {u, v} end)
2020-05-08 04:34:42 +00:00
votes =
2020-05-08 04:46:37 +00:00
entries
2020-05-08 04:34:42 +00:00
|> Map.keys()
|> Db.get_votes(room)
|> Enum.into(%{}, fn {{u, _r}, v} -> {u, v} end)
2020-05-08 03:43:02 +00:00
for {key, %{metas: metas}} <- entries, into: %{} do
2020-05-08 04:34:42 +00:00
{key, %{metas: metas,
2020-05-08 04:46:37 +00:00
name: players[key],
2020-05-08 04:34:42 +00:00
vote: Map.get(votes, key)}}
2020-05-08 03:43:02 +00:00
end
end
2020-05-08 04:34:42 +00:00
def fetch(_topic, entries), do: entries
2020-05-06 05:30:43 +00:00
end