peppy

peppy

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

Marked As Solved

peppy

peppy

This is fixed now.

Where Next?

Popular in Questions Top

New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement