How to get Presence list inside Controller? Is not returning full list of user ids

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

Please could we see your test code?

In the meantime, I found this blog post was a great tutorial and got me up and running using Phoenix Presence in what I think is a similar way to what you’re trying to do.

This is fixed now.