diff --git a/lib/teiserver/account.ex b/lib/teiserver/account.ex index 9bffb16df..9aabc5bdf 100644 --- a/lib/teiserver/account.ex +++ b/lib/teiserver/account.ex @@ -2152,4 +2152,17 @@ defmodule Teiserver.Account do @spec call_party(T.party_id(), any) :: any | nil defdelegate call_party(party_id, msg), to: PartyLib + + @spec hide_contributor_rank?(T.userid()) :: boolean() + def hide_contributor_rank?(userid) do + stats_data = get_user_stat_data(userid) + Map.get(stats_data, "hide_contributor_rank", false) + end + + @spec set_hide_contributor_rank(T.userid(), boolean()) :: any() + def set_hide_contributor_rank(userid, boolean_value) do + update_user_stat(userid, %{ + "hide_contributor_rank" => boolean_value + }) + end end diff --git a/lib/teiserver/account/libs/role_lib.ex b/lib/teiserver/account/libs/role_lib.ex index 84f2a64ea..72d48b79f 100644 --- a/lib/teiserver/account/libs/role_lib.ex +++ b/lib/teiserver/account/libs/role_lib.ex @@ -81,6 +81,13 @@ defmodule Teiserver.Account.RoleLib do contains: ["Community team"], badge: true }, + %{ + name: "Blog helper", + colour: "#66AA66", + icon: "fa-solid fa-blog", + contains: [], + badge: true + }, # Privileged %{name: "VIP", colour: "#AA8833", icon: "fa-solid fa-sparkles", contains: ["BAR+"]}, @@ -96,11 +103,18 @@ defmodule Teiserver.Account.RoleLib do %{name: "Donor", colour: "#0066AA", icon: "fa-solid fa-euro", contains: ~w(), badge: true}, # Contributor/Staff + %{ + name: "Tester", + colour: "#00AAAA", + icon: "fa-solid fa-vial", + contains: ~w(), + badge: true + }, %{ name: "Contributor", colour: "#66AA66", icon: "fa-solid fa-code-commit", - contains: ["Trusted", "BAR+"], + contains: ["Trusted", "BAR+", "Tester", "Blog helper"], badge: true }, %{name: "Engine", colour: "#007700", icon: "fa-solid fa-engine", contains: ~w(Contributor)}, @@ -124,13 +138,6 @@ defmodule Teiserver.Account.RoleLib do icon: "fa-solid fa-download", contains: ~w(Contributor) }, - %{ - name: "Tester", - colour: "#00AAAA", - icon: "fa-solid fa-vial", - contains: ~w(Contributor), - badge: true - }, %{ name: "Core", colour: "#007700", @@ -246,7 +253,7 @@ defmodule Teiserver.Account.RoleLib do @spec community_roles :: [String.t()] def community_roles() do - ["Mentor", "Academy manager", "Promo team", "Community team"] + ["Mentor", "Academy manager", "Promo team", "Community team", "Blog helper"] end @spec privileged_roles :: [String.t()] diff --git a/lib/teiserver/data/cache_user.ex b/lib/teiserver/data/cache_user.ex index 47f9cef4f..aeb4fa4a4 100644 --- a/lib/teiserver/data/cache_user.ex +++ b/lib/teiserver/data/cache_user.ex @@ -1316,7 +1316,7 @@ defmodule Teiserver.CacheUser do # https://www.beyondallreason.info/guide/rating-and-lobby-balance#rank-icons cond do has_any_role?(userid, ["Tournament winner"]) -> 7 - has_any_role?(userid, ~w(Core Contributor)) -> 6 + has_any_role?(userid, ~w(Core Contributor)) and !Account.hide_contributor_rank?(userid) -> 6 ingame_hours >= 1000 -> 5 ingame_hours >= 250 -> 4 ingame_hours >= 100 -> 3 diff --git a/lib/teiserver_web/live/account/profile/contributor.ex b/lib/teiserver_web/live/account/profile/contributor.ex index f44c8f3b8..186fd7bbb 100644 --- a/lib/teiserver_web/live/account/profile/contributor.ex +++ b/lib/teiserver_web/live/account/profile/contributor.ex @@ -7,6 +7,7 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do def mount(%{"userid" => userid_str}, _session, socket) do userid = String.to_integer(userid_str) user = Account.get_user_by_id(userid) + hide_contributor_rank = Account.hide_contributor_rank?(userid) socket = cond do @@ -27,6 +28,7 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do |> assign(:view_colour, Teiserver.Account.UserLib.colours()) |> assign(:user, user) |> assign(:error_message, nil) + |> assign(:hide_contributor_rank, hide_contributor_rank) |> TeiserverWeb.Account.ProfileLive.Overview.get_relationships_and_permissions() |> user_assigns end @@ -94,6 +96,30 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do end end + @doc """ + Handles checkbox to disable contributor rank icon + """ + @impl true + def handle_event("toggle-hide-contributor-rank", event, %{assigns: assigns} = socket) do + [key] = event["_target"] + value = event[key] + + # value will be a string or nil; we will convert to boolean + boolean_value = + if value do + true + else + false + end + + Account.set_hide_contributor_rank(assigns.user.id, boolean_value) + Account.recache_user(assigns.user.id) + + {:noreply, + socket + |> assign(:hide_contributor_rank, boolean_value)} + end + def handle_event(_string, _event, socket) do {:noreply, socket} end diff --git a/lib/teiserver_web/live/account/profile/contributor.html.heex b/lib/teiserver_web/live/account/profile/contributor.html.heex index c2f2cfe05..09c9b8dbc 100644 --- a/lib/teiserver_web/live/account/profile/contributor.html.heex +++ b/lib/teiserver_web/live/account/profile/contributor.html.heex @@ -61,4 +61,25 @@ <% end %> +