From 6744455ac4cff392202a720baf051796b3be9779 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 18:43:14 -0500 Subject: [PATCH] Fix get_received_at to properly handle Packet structs Structs don't implement the Access behaviour, so packet[:received_at] doesn't work. Use pattern matching to handle Aprsme.Packet structs separately with dot notation, and use Map.get for regular maps. This fixes the UndefinedFunctionError when rendering tracked callsign information with Packet structs from the database. --- lib/aprsme_web/live/map_live/components.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/aprsme_web/live/map_live/components.ex b/lib/aprsme_web/live/map_live/components.ex index 8b39fd5..55b27aa 100644 --- a/lib/aprsme_web/live/map_live/components.ex +++ b/lib/aprsme_web/live/map_live/components.ex @@ -355,9 +355,14 @@ defmodule AprsmeWeb.MapLive.Components do """ end - # Helper function to get received_at from packet with either atom or string keys + # Helper function to get received_at from packet (handles both structs and maps) + defp get_received_at(%Aprsme.Packet{} = packet) do + packet.received_at + end + defp get_received_at(packet) when is_map(packet) do - packet[:received_at] || packet["received_at"] + # For regular maps, try both atom and string keys + Map.get(packet, :received_at) || Map.get(packet, "received_at") end defp get_received_at(_), do: nil