towerops/lib/towerops_web/channels/mobile_socket.ex
Graham McIntire 91e3181bbc dialyzer: fix all unmatched_return warnings (154 → 0)
Prefix fire-and-forget calls (PubSub.broadcast, Oban enqueue, Logger,
update_*, etc.) with `_ =` so dialyzer knows the return value is
intentionally discarded. Wrap a few if/case expressions whose
branches produce mixed types the same way.

No behavior changes — only explicit acknowledgement of discarded
returns.

Warnings: 242 → 88.
2026-04-21 10:03:55 -05:00

48 lines
1.4 KiB
Elixir

defmodule ToweropsWeb.MobileSocket do
@moduledoc """
WebSocket endpoint for mobile app communication.
Mobile clients connect to: ws://server/mobile/socket/websocket
Authentication happens at connect time using a bearer token from
the mobile session system (QR code login flow).
The token is passed as a `"token"` parameter during the WebSocket
handshake. It is validated against the `mobile_sessions` table,
and expired sessions are rejected.
"""
use Phoenix.Socket
alias Towerops.MobileSessions
channel "mobile:org:*", ToweropsWeb.MobileChannel
channel "mobile:device:*", ToweropsWeb.MobileChannel
@impl true
@spec connect(map(), Phoenix.Socket.t(), map()) :: {:ok, Phoenix.Socket.t()} | :error
def connect(%{"token" => token}, socket, _connect_info) when is_binary(token) do
case MobileSessions.get_session_by_token(token) do
nil ->
:error
session ->
session = Towerops.Repo.preload(session, :user)
_ = Task.start(fn -> MobileSessions.touch_session(session) end)
socket =
socket
|> assign(:user_id, session.user_id)
|> assign(:mobile_session_id, session.id)
{:ok, socket}
end
end
def connect(_params, _socket, _connect_info), do: :error
@impl true
@spec id(Phoenix.Socket.t()) :: String.t()
def id(socket) do
"mobile_socket:#{socket.assigns.user_id}"
end
end