Presence not working correctly in my project

I’m currently experimenting with the new Presence feature and have some problems with updating the state of the presence object. In my project the Presence.list function is returning an empty list while there are multiple users online.

The presence_state and presence_diff works fine, but i think there’s something wrong with updating the presence object with the syncState and syncDiff functions in my web/static/javascript/app.js file.

Can somebody take a look and tell me what i’m doing wrong?

Any help is really appreciated!

My project is located at

1 Like

Hmm, only oddity there is that I put the ‘list’ call before the track (which I’ve noticed makes a difference, like a race condition or so).

    push socket, "presence_state", MessengerPresence.list(socket)
    {:ok, _} = MessengerPresence.track(socket.channel_pid, socket.topic, socket.assigns.uid, %{
      loc: socket.assigns.loc,
      nick: socket.assigns.display_name,

That looks entirely correct to me, but based on your description I’m wondering if the issue you are seeing might be caused by the list being after track instead of before.

1 Like

Hi @OvermindDL1 thanks for looking into my question :slight_smile:
Moving the push line to the top doesn’t give any results.

When i inspect the Presence.list(socket) in the handle_info function it returns all the users. So the presences are lost between receiving the new state in the client and running the render method in my javascript, Thereby the state of my presences object is not updated.

Next issue, you are not saving the state and diffs, your lines are currently like:

Presence.syncState(presences, state)

When it should be like:

presences = Presence.syncState(presences, state)

Right now you are not storing the return value anywhere. And the same with diff. :slight_smile:


Thank you very much! This was indeed the problem, after looking at it again it’s quite logical :stuck_out_tongue:.