chore: send hubs limit as part of init event

This commit is contained in:
Dmitry Popov
2025-05-04 11:25:38 +02:00
parent fede6451e2
commit 9f656ca3cb
2 changed files with 17 additions and 17 deletions

View File

@@ -72,6 +72,9 @@ defmodule WandererApp.Map do
def get_characters_limit(map_id),
do: {:ok, map_id |> get_map!() |> Map.get(:characters_limit, 50)}
def get_hubs_limit(map_id),
do: {:ok, map_id |> get_map!() |> Map.get(:hubs_limit, 20)}
def is_subscription_active?(map_id),
do: is_subscription_active?(map_id, WandererApp.Env.map_subscriptions_enabled?())
@@ -105,17 +108,14 @@ defmodule WandererApp.Map do
def list_hubs(map_id) do
{:ok, map} = map_id |> get_map()
hubs = map |> Map.get(:hubs, [])
hubs_limit = map |> Map.get(:hubs_limit, 20)
{:ok, hubs |> maybe_limit_list(hubs_limit)}
{:ok, map |> Map.get(:hubs, [])}
end
def list_hubs(map_id, hubs) do
{:ok, map} = map_id |> get_map()
hubs_limit = map |> Map.get(:hubs_limit, 20)
{:ok, hubs |> maybe_limit_list(hubs_limit)}
{:ok, hubs}
end
def list_connections(map_id),
@@ -155,15 +155,16 @@ defmodule WandererApp.Map do
case not (characters |> Enum.member?(character_id)) do
true ->
{:ok, %{
alliance_id: alliance_id,
corporation_id: corporation_id,
solar_system_id: solar_system_id,
structure_id: structure_id,
station_id: station_id,
ship: ship_type_id,
ship_name: ship_name
}} = WandererApp.Character.get_character(character_id)
{:ok,
%{
alliance_id: alliance_id,
corporation_id: corporation_id,
solar_system_id: solar_system_id,
structure_id: structure_id,
station_id: station_id,
ship: ship_type_id,
ship_name: ship_name
}} = WandererApp.Character.get_character(character_id)
map_id
|> update_map(%{characters: [character_id | characters]})
@@ -543,9 +544,6 @@ defmodule WandererApp.Map do
end
end
defp maybe_limit_list(list, nil), do: list
defp maybe_limit_list(list, limit), do: Enum.take(list, limit)
@doc """
Returns the raw activity data that can be processed by WandererApp.Character.Activity.
Only includes characters that are on the map's ACL.

View File

@@ -594,6 +594,7 @@ defmodule WandererAppWeb.MapCoreEventHandler do
defp get_map_data(map_id, current_user_id, is_subscription_active) do
{:ok, hubs} = map_id |> WandererApp.Map.list_hubs()
{:ok, hubs_limit} = map_id |> WandererApp.Map.get_hubs_limit()
{:ok, connections} = map_id |> WandererApp.Map.list_connections()
{:ok, systems} = map_id |> WandererApp.Map.list_systems()
@@ -615,6 +616,7 @@ defmodule WandererAppWeb.MapCoreEventHandler do
system_static_infos:
system_static_infos |> Enum.map(&MapEventHandler.map_ui_system_static_info/1),
hubs: hubs,
hubs_limit: hubs_limit,
user_hubs: user_hubs,
connections: connections |> Enum.map(&MapEventHandler.map_ui_connection/1)
}