I’m tracking online users with :after_join callback and after pushing new state I expect to see list of online users in this callback but map object is empty in this process, on the other hand, while creating new connection i see the previous connection in the list of online users.
How does your after join looks like? I have one like this…
def handle_info(:after_join, socket) do
user = socket.assigns.user
{:ok, _} = Presence.track(socket, user.id, %{
username: user.name,
online_at: System.system_time(:second)
})
push(socket, "presence_state", Presence.list(socket))
{:noreply, socket}
end
In the Phoenix example the push state is before the presence track. Thus there is a presence state push (without user), then a presence diff (with user)…
I put the presence_state after presence track because the first presence state will include user and there will be no presence diff push.
I would advise to put some code to help us understand your question, and thus have better answers
I have this same problem. This comes from the book written by Chris McCord. I tried your suggestion of putting push after Presence.track yet to no avail.