diff --git a/lib/screens/alerts/informed_entity.ex b/lib/screens/alerts/informed_entity.ex index d5916e2fe..848e75fa5 100644 --- a/lib/screens/alerts/informed_entity.ex +++ b/lib/screens/alerts/informed_entity.ex @@ -76,4 +76,16 @@ defmodule Screens.Alerts.InformedEntity do end) |> Enum.filter(fn ie -> not is_nil(ie.stop) end) end + + @spec boarding_platforms_from_entities([t()]) :: [Stop.t()] + def boarding_platforms_from_entities(informed_parent_stations) do + informed_parent_stations + |> Enum.flat_map( + &case &1.stop.child_stops do + nil -> [] + child_stops -> child_stops + end + ) + |> Stop.filter_subway_platforms() + end end diff --git a/lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex b/lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex index b845a7ac2..3cd5b9aae 100644 --- a/lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex +++ b/lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex @@ -163,10 +163,11 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlert do # Given informed entities representing an alert at a single station, # finds the corresponding platform names for those child stops included. with [informed_parent_station] <- Alert.informed_parent_stations(alert), - [_ | _] = child_platforms <- informed_parent_station.stop.child_stops, + [_ | _] = child_platforms <- + InformedEntity.boarding_platforms_from_entities([informed_parent_station]), :partial_closure <- Alert.station_closure_type(alert, child_platforms) do platform_ids = - child_platforms |> Stop.filter_subway_platforms() |> Enum.map(& &1.id) |> MapSet.new() + child_platforms |> Enum.map(& &1.id) |> MapSet.new() informed_entities |> Enum.filter(&(&1.stop.id in platform_ids)) diff --git a/lib/screens/v2/widget_instance/subway_status/serialize.ex b/lib/screens/v2/widget_instance/subway_status/serialize.ex index e84a604f0..613db14d6 100644 --- a/lib/screens/v2/widget_instance/subway_status/serialize.ex +++ b/lib/screens/v2/widget_instance/subway_status/serialize.ex @@ -4,8 +4,8 @@ defmodule Screens.V2.WidgetInstance.SubwayStatus.Serialize do """ alias Screens.Alerts.Alert + alias Screens.Alerts.InformedEntity alias Screens.Routes.Route - alias Screens.Stops.Stop alias Screens.V2.WidgetInstance.SubwayStatus alias Screens.V2.WidgetInstance.SubwayStatus.Serialize.GreenLine alias Screens.V2.WidgetInstance.SubwayStatus.Serialize.RedLine @@ -251,13 +251,7 @@ defmodule Screens.V2.WidgetInstance.SubwayStatus.Serialize do child_platforms_at_informed_stations = alert |> Alert.informed_parent_stations() - |> Enum.flat_map( - &case &1.stop.child_stops do - nil -> [] - child_stops -> child_stops - end - ) - |> Stop.filter_subway_platforms() + |> InformedEntity.boarding_platforms_from_entities() case Alert.station_closure_type(alert, child_platforms_at_informed_stations) do # Logic for partial_station_closure will remove any alerts that apply to more than