Fix mobile channel update_bounds nil handling

Replace 'with' clause that was failing when socket.assigns[:subscribed]
returned nil. Now properly checks subscription status using Map.get with
a default value of false to prevent WithClauseError.

Fixes error: no with clause matching: nil

Generated with Claude Code https://claude.com/claude-code
This commit is contained in:
Graham McIntire 2025-10-25 12:48:34 -05:00
parent d6c3ada6c4
commit 9509c49429
No known key found for this signature in database

View file

@ -102,28 +102,30 @@ defmodule AprsmeWeb.MobileChannel do
west: ensure_float(west) west: ensure_float(west)
} }
# Validate bounds # Check if subscribed
with :ok <- validate_bounds(bounds), if Map.get(socket.assigns, :subscribed, false) do
true <- socket.assigns[:subscribed] do # Validate bounds
# Unsubscribe from old bounds case validate_bounds(bounds) do
if socket.assigns[:bounds] do :ok ->
Aprsme.StreamingPacketsPubSub.unsubscribe_from_bounds(self(), socket.assigns.bounds) # Unsubscribe from old bounds
if socket.assigns[:bounds] do
Aprsme.StreamingPacketsPubSub.unsubscribe_from_bounds(self(), socket.assigns.bounds)
end
# Subscribe to new bounds
Aprsme.StreamingPacketsPubSub.subscribe_to_bounds(self(), bounds)
socket = assign(socket, :bounds, bounds)
Logger.debug("Mobile client #{socket.assigns.client_id} updated bounds: #{inspect(bounds)}")
{:reply, {:ok, %{bounds: bounds, message: "Bounds updated"}}, socket}
{:error, reason} ->
{:reply, {:error, %{message: reason}}, socket}
end end
# Subscribe to new bounds
Aprsme.StreamingPacketsPubSub.subscribe_to_bounds(self(), bounds)
socket = assign(socket, :bounds, bounds)
Logger.debug("Mobile client #{socket.assigns.client_id} updated bounds: #{inspect(bounds)}")
{:reply, {:ok, %{bounds: bounds, message: "Bounds updated"}}, socket}
else else
{:error, reason} -> {:reply, {:error, %{message: "Not subscribed. Call subscribe_bounds first."}}, socket}
{:reply, {:error, %{message: reason}}, socket}
false ->
{:reply, {:error, %{message: "Not subscribed. Call subscribe_bounds first."}}, socket}
end end
end end