I am building a whatsapp clone and having trouble figuring out some stuff with Presence.
I have two channel:
channel "chats:*", Typi.ChatChannel
channel "users:*", Typi.UserChannel
The user is always connected to users:...
channel, if he is in the app, and on join I start tracking his presence:
def join("users:" <> user_id, _payload, socket) do
send self(), :after_join
{:ok, socket}
end
def handle_info(:after_join, socket) do
Presence.track(socket, socket.assigns.current_user.id, %{})
{:noreply, socket}
end
When user joins some chat I add chat_id
to meta:
def join("chats:" <> chat_id, _payload, socket) do
send self(), :after_join
{:ok, assign(socket, :current_chat, chat)}
end
def handle_info(:after_join, socket) do
Presence.track(socket, socket.assigns.current_user.id, %{
chat_id: socket.assigns.current_chat.id
})
{:noreply, socket}
end
When the user leaves the chat I want to delete meta information but keep the presence. How can I do that?
Thanks