Skip to content

Commit

Permalink
username sorting (87616)
Browse files Browse the repository at this point in the history
  • Loading branch information
00-Steven committed Nov 1, 2024
1 parent 7d472f6 commit 86c7a0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#define PING_COOLDOWN_TIME (3 SECONDS)

#define STATUS_ONLINE 3
#define STATUS_AWAY 2
#define STATUS_OFFLINE 1

/datum/computer_file/program/chatclient
filename = "ntnrc_client"
filedesc = "Chat Client"
Expand Down Expand Up @@ -206,6 +210,14 @@
active_channel = null
return ..()

/// Converts active/idle/closed to a numerical status for sorting clients by.
/datum/computer_file/program/chatclient/proc/get_numerical_status()
if(src == computer.active_program)
return STATUS_ONLINE
if(src in computer.idle_threads)
return STATUS_AWAY
return STATUS_OFFLINE

/datum/computer_file/program/chatclient/ui_static_data(mob/user)
var/list/data = list()
data["selfref"] = REF(src) //used to verify who is you, as usernames can be copied.
Expand Down Expand Up @@ -242,6 +254,7 @@
"away" = (channel_client in channel_client.computer.idle_threads),
"muted" = (channel_client in channel.muted_clients),
"operator" = (channel.channel_operator == channel_client),
"status" = channel_client.get_numerical_status(),
"ref" = REF(channel_client),
)))
//no fishing for ui data allowed
Expand All @@ -267,3 +280,7 @@
#undef MESSAGE_SIZE

#undef PING_COOLDOWN_TIME

#undef STATUS_ONLINE
#undef STATUS_AWAY
#undef STATUS_OFFLINE
14 changes: 6 additions & 8 deletions tgui/packages/tgui/interfaces/NtosNetChat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ export const NtosNetChat = (props) => {
} = data;
const in_channel = active_channel !== null;
const authorized = authed || adminmode;
// this list has cliented ordered from their status. online > away > offline
// This list has clients ordered by operator>status>alphabetical
const displayed_clients = clients.sort((clientA, clientB) => {
if (clientA.operator) {
return -1;
}
if (clientB.operator) {
return 1;
}
return clientB.status - clientA.status;
return (
clientB.operator - clientA.operator ||
clientB.status - clientA.status ||
clientB.name < clientA.name
);
});
const client_color = (client) => {
if (client.operator) {
Expand Down

0 comments on commit 86c7a0a

Please sign in to comment.