I am creating a whatsapp clone and have difficulty figuring out some things with the Presence.
I have two channels:
channel "chats:*", Typi.ChatChannel
channel "users:*", Typi.UserChannel
The user always connects to the channel users:...if it is in the application, and when I connect, I begin to track its 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 the user joins the chat, I add chat_idto the 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 the meta-information, but I keep it. How can i do this?
thank