Through a Controller, I am trying to fetch a simple list of userids subscribed to a topic. My channels are properly tracking users and I can view the Presence list on the browser, just like in the Presence tutorial. But I can’t get the list from inside this Controller. This is part of a backend API call to get a quick list of users who are currently in a room:
defmodule AppWeb.GetPresenceController do
use Phoenix.Controller
alias AppWeb.Presence
def getpresence(conn, %{"roomid" => roomid}) do
IO.inspect(roomid) # example: "room:15"
IO.inspect(Presence.list(roomid))
ulist =
Presence.list(roomid)
|> Enum.map(fn {k,_v} -> {k} end)
IO.inspect(ulist)
json(conn, %{})
end
end
When I inspect the Presence.list("room:15")
, I get this result:
%{
"{socket.assigns.user_id}" => %{
metas: [
%{phx_ref: "F8uCIBCYz4awowNB", online_at: "1714607157"},
%{phx_ref: "F8uCQnaXxtGwowJC", online_at: "1714607305"}
]
}
}
In my tests, I have two users in that room. But Presence.list is not showing the actual userids for those users. How can I get a simple list of userids in the room?
Thanks