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.
This commit is contained in:
Graham McIntire 2025-10-25 18:43:14 -05:00
parent 34c78fbe87
commit 6744455ac4
No known key found for this signature in database

View file

@ -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