-
Notifications
You must be signed in to change notification settings - Fork 98
Add ability to show/hide moderator status #1307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,17 +19,24 @@ defmodule Teiserver.Protocols.Spring do | |
| } | ||
| end | ||
|
|
||
| @spec create_client_status(map()) :: Integer.t() | ||
| def create_client_status(client) do | ||
| @spec create_client_status(map(), boolean()) :: Integer.t() | ||
| def create_client_status(client, true_mod_status \\ false) do | ||
| [r1, r2, r3] = BitParse.parse_bits("#{client.rank || 1}", 3) | ||
|
|
||
| moderator = | ||
| if true_mod_status do | ||
| client.moderator | ||
| else | ||
| Map.get(client, :show_moderator, client.moderator) | ||
| end | ||
|
Comment on lines
+26
to
+31
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the part controlling what is shown to other clients., If |
||
|
|
||
| [ | ||
| if(client.in_game, do: 1, else: 0), | ||
| if(client.away, do: 1, else: 0), | ||
| r3, | ||
| r2, | ||
| r1, | ||
| if(client.moderator, do: 1, else: 0), | ||
| if(moderator, do: 1, else: 0), | ||
| if(client.bot, do: 1, else: 0) | ||
| ] | ||
| |> Enum.reverse() | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are testing at the socket level, shouldn't you check you receive the correct status message through a socket instead of reaching for the internals? None of these test really make sure other clients will see the correct status for the client you are modifying. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| defmodule Teiserver.Coordinator.CoordinatorCommandsSyncTest do | ||
| alias Teiserver.Account | ||
| alias Teiserver.Account.Auth | ||
| alias Teiserver.Account.UserLib | ||
| alias Teiserver.CacheUser | ||
|
|
||
|
|
@@ -8,6 +9,9 @@ defmodule Teiserver.Coordinator.CoordinatorCommandsSyncTest do | |
| import TeiserverTestLib, | ||
| only: [ | ||
| auth_setup: 1, | ||
| auth_setup: 2, | ||
| new_user: 1, | ||
| _recv_until: 1, | ||
| _send_raw: 2, | ||
| _recv_raw: 1, | ||
| start_spring_server: 1 | ||
|
|
@@ -50,5 +54,63 @@ defmodule Teiserver.Coordinator.CoordinatorCommandsSyncTest do | |
|
|
||
| Application.put_env(:teiserver, Teiserver, config) | ||
| end | ||
|
|
||
| test "modme - not moderator", %{socket: socket, user: user} do | ||
| client = Account.get_client_by_id(user.id) | ||
| refute client.moderator | ||
| refute client.show_moderator | ||
|
|
||
| _send_raw(socket, "SAYPRIVATE coordinator $modme\n") | ||
| :timer.sleep(100) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the sleeps aren't ideal, there are a few helper function under |
||
|
|
||
| client = Account.get_client_by_id(user.id) | ||
| refute client.moderator | ||
| refute client.show_moderator | ||
| end | ||
|
|
||
| test "modme/unmodme - as moderator", context do | ||
| user_watcher = new_user("user_watcher") | ||
| %{socket: user_watcher_socket} = auth_setup(context, user_watcher) | ||
| bot_watcher = new_user("bot_watcher") | ||
| %{socket: bot_watcher_socket} = auth_setup(context, bot_watcher) | ||
| {:ok, _} = Auth.add_roles(bot_watcher.id, ["Bot"]) | ||
|
|
||
| std_user = new_user("std_watcher") | ||
| %{socket: std_socket} = auth_setup(context, std_user) | ||
| mod_user = new_user("mod_user") | ||
| %{socket: mod_socket} = auth_setup(context, mod_user) | ||
| {:ok, _} = Auth.add_roles(mod_user.id, ["Moderator"]) | ||
|
|
||
| lines1 = _recv_until(user_watcher_socket) | ||
| lines2 = _recv_until(bot_watcher_socket) | ||
|
|
||
| _recv_until(mod_socket) | ||
|
|
||
| IO.puts "MODME" | ||
| _send_raw(std_socket, "SAYPRIVATE coordinator $modme\n") | ||
| _send_raw(mod_socket, "SAYPRIVATE coordinator $modme\n") | ||
|
|
||
| lines3 = _recv_until(user_watcher_socket) | ||
| lines4 = _recv_until(bot_watcher_socket) | ||
|
|
||
| lines5 = _recv_until(mod_socket) | ||
|
|
||
| IO.puts "lines1" | ||
| IO.puts lines1 | ||
| IO.puts "" | ||
| IO.puts "lines2" | ||
| IO.puts lines2 | ||
| IO.puts "" | ||
| IO.puts "lines3" | ||
| IO.puts lines3 | ||
| IO.puts "" | ||
| IO.puts "lines4" | ||
| IO.puts lines4 | ||
| IO.puts "" | ||
|
|
||
| IO.puts "" | ||
| IO.puts lines5 | ||
| IO.puts "" | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default to not showing it at login