diff --git a/lib/aprsme/streaming_packets_pubsub.ex b/lib/aprsme/streaming_packets_pubsub.ex index 02db43f..c58aa3c 100644 --- a/lib/aprsme/streaming_packets_pubsub.ex +++ b/lib/aprsme/streaming_packets_pubsub.ex @@ -119,17 +119,7 @@ defmodule Aprsme.StreamingPacketsPubSub do server_pid = self() Aprsme.BroadcastTaskSupervisor.async_execute(fn -> - dead_pids = - subscribers - |> Stream.filter(fn {_pid, bounds} -> packet_in_bounds?(lat, lon, bounds) end) - |> Enum.reduce([], fn {pid, _bounds}, acc -> - send_to_subscriber_if_alive(pid, packet, acc) - end) - - # Send dead pids back to GenServer for cleanup - if dead_pids != [] do - send(server_pid, {:cleanup_dead_subscribers, dead_pids}) - end + send_to_matching_subscribers(subscribers, lat, lon, packet, server_pid) end) end @@ -182,6 +172,18 @@ defmodule Aprsme.StreamingPacketsPubSub do lat_in_bounds and lon_in_bounds end + defp send_to_matching_subscribers(subscribers, lat, lon, packet, server_pid) do + dead_pids = + subscribers + |> Stream.filter(fn {_pid, bounds} -> packet_in_bounds?(lat, lon, bounds) end) + |> Enum.reduce([], fn {pid, _bounds}, acc -> + send_to_subscriber_if_alive(pid, packet, acc) + end) + + # Send dead pids back to GenServer for cleanup + send(server_pid, {:cleanup_dead_subscribers, dead_pids}) + end + defp send_to_subscriber_if_alive(pid, packet, acc) do if Process.alive?(pid) do send(pid, {:streaming_packet, packet}) diff --git a/lib/aprsme_web/live/map_live/data_builder.ex b/lib/aprsme_web/live/map_live/data_builder.ex index 0f1beae..9e813b2 100644 --- a/lib/aprsme_web/live/map_live/data_builder.ex +++ b/lib/aprsme_web/live/map_live/data_builder.ex @@ -184,10 +184,7 @@ defmodule AprsmeWeb.MapLive.DataBuilder do filter_historical_by_distance(historical, most_recent_lat, most_recent_lon) # Build data for remaining historical packets - historical_data = - filtered_historical - |> Enum.map(fn packet -> build_minimal_packet_data(packet, false, has_weather) end) - |> Enum.filter(& &1) + historical_data = build_historical_packet_data(filtered_historical, has_weather) # Combine most recent and filtered historical Enum.filter([most_recent_data | historical_data], & &1) @@ -628,4 +625,10 @@ defmodule AprsmeWeb.MapLive.DataBuilder do false end end + + defp build_historical_packet_data(filtered_historical, has_weather) do + filtered_historical + |> Enum.map(fn packet -> build_minimal_packet_data(packet, false, has_weather) end) + |> Enum.filter(& &1) + end end diff --git a/lib/aprsme_web/live/map_live/historical_loader.ex b/lib/aprsme_web/live/map_live/historical_loader.ex index c65abce..13837ae 100644 --- a/lib/aprsme_web/live/map_live/historical_loader.ex +++ b/lib/aprsme_web/live/map_live/historical_loader.ex @@ -197,12 +197,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do end # If tracking a callsign and this is the first batch, also load RF path stations - socket = - if socket.assigns.tracked_callsign != "" and batch_offset == 0 do - load_rf_path_stations(socket, historical_packets) - else - socket - end + socket = maybe_load_rf_path_stations(socket, batch_offset, historical_packets) process_loaded_packets(socket, historical_packets, packet_data_list, batch_offset) else @@ -424,6 +419,14 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do socket end + defp maybe_load_rf_path_stations(socket, batch_offset, historical_packets) do + if socket.assigns.tracked_callsign != "" and batch_offset == 0 do + load_rf_path_stations(socket, historical_packets) + else + socket + end + end + defp load_rf_path_stations(socket, packets) do # Extract unique RF path stations from all packets rf_path_stations = diff --git a/lib/aprsme_web/live/map_live/packet_processor.ex b/lib/aprsme_web/live/map_live/packet_processor.ex index 02dcb48..79a41d9 100644 --- a/lib/aprsme_web/live/map_live/packet_processor.ex +++ b/lib/aprsme_web/live/map_live/packet_processor.ex @@ -109,13 +109,7 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do marker_data = PacketUtils.build_packet_data(packet, true, get_locale(socket)) if marker_data do - # Only show new packet popup if no station popup is currently open - if socket.assigns.station_popup_open do - # Send without opening popup to avoid interrupting user - LiveView.push_event(socket, "new_packet", Map.put(marker_data, :openPopup, false)) - else - LiveView.push_event(socket, "new_packet", marker_data) - end + send_marker_with_popup_check(socket, marker_data) else socket end @@ -167,4 +161,13 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do # This function should be moved to DisplayManager module socket end + + defp send_marker_with_popup_check(socket, marker_data) do + if socket.assigns.station_popup_open do + # Send without opening popup to avoid interrupting user + LiveView.push_event(socket, "new_packet", Map.put(marker_data, :openPopup, false)) + else + LiveView.push_event(socket, "new_packet", marker_data) + end + end end