From 34c78fbe870195a35cfbb0adfd3ed565ad9a498a Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 18:17:03 -0500 Subject: [PATCH] Handle both atom and string keys for packet received_at field When packets go through Phoenix LiveView serialization, map keys can be converted from atoms to strings. Add get_received_at/1 helper that handles both formats to prevent KeyError when accessing received_at field. This fixes the crash when the iOS app searches for callsigns and the LiveView tries to render the tracked callsign's last seen time. --- lib/aprsme_web/live/map_live/components.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/aprsme_web/live/map_live/components.ex b/lib/aprsme_web/live/map_live/components.ex index 72ad543..8b39fd5 100644 --- a/lib/aprsme_web/live/map_live/components.ex +++ b/lib/aprsme_web/live/map_live/components.ex @@ -196,7 +196,7 @@ defmodule AprsmeWeb.MapLive.Components do <%= if @tracked_callsign_latest_packet do %>
- Last seen: {time_ago_in_words(@tracked_callsign_latest_packet.received_at)} + Last seen: {time_ago_in_words(get_received_at(@tracked_callsign_latest_packet))}
<% end %> @@ -354,4 +354,11 @@ defmodule AprsmeWeb.MapLive.Components do """ end + + # Helper function to get received_at from packet with either atom or string keys + defp get_received_at(packet) when is_map(packet) do + packet[:received_at] || packet["received_at"] + end + + defp get_received_at(_), do: nil end