From 5ca07bcbe04aaedf3721cb2d9c09d8ab6ae7a926 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 3 Oct 2025 12:37:45 -0500 Subject: [PATCH] Fix info page to show last known position when latest packet has no location data For stations that send both position and status packets, the info page would show empty location data if the most recent packet was a status packet. This fix ensures the page displays the last known position from the most recent position packet while still showing the latest activity timestamp. --- lib/aprsme_web/live/info_live/show.ex | 32 +++++++++++++++++++- lib/aprsme_web/live/info_live/show.html.heex | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/aprsme_web/live/info_live/show.ex b/lib/aprsme_web/live/info_live/show.ex index ff08797..56d6ba5 100644 --- a/lib/aprsme_web/live/info_live/show.ex +++ b/lib/aprsme_web/live/info_live/show.ex @@ -137,7 +137,37 @@ defmodule AprsmeWeb.InfoLive.Show do defp get_latest_packet(callsign) do # Get the most recent packet for this callsign, regardless of type # This ensures we show the most recent activity, not just position packets - Packets.get_latest_packet_for_callsign(callsign) + packet = Packets.get_latest_packet_for_callsign(callsign) + + # If this packet doesn't have position data, try to get the latest position packet + if packet && (is_nil(packet.lat) || is_nil(packet.lon)) do + position_packet = get_latest_position_packet(callsign) + + if position_packet do + # Merge position data from position packet into the latest packet + %{packet | lat: position_packet.lat, lon: position_packet.lon, location: position_packet.location} + else + packet + end + else + packet + end + end + + defp get_latest_position_packet(callsign) do + import Ecto.Query + # Get the most recent packet with valid position data + alias Aprsme.Repo + + Repo.one( + from(p in Aprsme.Packet, + where: fragment("upper(?)", p.sender) == ^String.upcase(String.trim(callsign)), + where: not is_nil(p.lat) and not is_nil(p.lon), + order_by: [desc: p.received_at], + limit: 1, + select: %{p | lat: fragment("ST_Y(?)", p.location), lon: fragment("ST_X(?)", p.location)} + ) + ) end defp get_neighbors(nil, _callsign, _locale), do: [] diff --git a/lib/aprsme_web/live/info_live/show.html.heex b/lib/aprsme_web/live/info_live/show.html.heex index eba6dbb..9c534e8 100644 --- a/lib/aprsme_web/live/info_live/show.html.heex +++ b/lib/aprsme_web/live/info_live/show.html.heex @@ -99,7 +99,7 @@ <% end %>
-
{gettext("Last Position")}
+
{gettext("Last Activity")}
<%= if @packet.received_at do %>