Changeset View
Changeset View
Standalone View
Standalone View
web/channels/system_channel.ex
- This file was added.
defmodule KolabChat.SystemChannel do | |||||
use KolabChat.Web, :channel | |||||
alias KolabChat.Presence | |||||
def join("system", _, socket) do | |||||
Process.flag(:trap_exit, true) | |||||
:timer.send_interval(10000, :ping) | |||||
send self(), :after_join | |||||
{:ok, socket} | |||||
end | |||||
def handle_info(:after_join, socket) do | |||||
Presence.track(socket, socket.assigns.user.username, %{ | |||||
status: "online" | |||||
}) | |||||
push socket, "info", %{user: socket.assigns.user.username} | |||||
push socket, "presence_state", Presence.list(socket) | |||||
{:noreply, socket} | |||||
end | |||||
def handle_info(:ping, socket) do | |||||
push socket, "new:msg", %{user: "SYSTEM", body: "ping"} | |||||
{:noreply, socket} | |||||
end | |||||
def handle_in("set-status", %{"status" => status}, socket) do | |||||
{:ok, _} = Presence.update(socket, socket.assigns.user.username, %{ | |||||
status: status | |||||
}) | |||||
{:noreply, socket} | |||||
end | |||||
end |