Skip to content

Commit

Permalink
Chatclient fixes 2 (#16587)
Browse files Browse the repository at this point in the history
* Fixes the chat client and services.

* oh how we love you

* lemme talk to 'em...

* a

* m

* lilas

* bro

---------

Co-authored-by: Matt Atlas <[email protected]>
  • Loading branch information
NonQueueingMatt and Matt Atlas committed Jun 29, 2023
1 parent dd07305 commit 1645af3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 49 deletions.
2 changes: 1 addition & 1 deletion code/controllers/subsystems/ping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
init_order = SS_INIT_MISC_FIRST
wait = 4 SECONDS
flags = SS_NO_INIT
runlevels = RUNLEVEL_LOBBY | RUNLEVEL_SETUP | RUNLEVEL_GAME | RUNLEVEL_POSTGAME
runlevels = RUNLEVEL_INIT | RUNLEVEL_LOBBY | RUNLEVEL_SETUP | RUNLEVEL_GAME | RUNLEVEL_POSTGAME

var/list/currentrun = list()

Expand Down
2 changes: 2 additions & 0 deletions code/modules/modular_computers/NTNet/NTNRC/conversation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ var/global/ntnrc_uid = 0
/datum/ntnet_conversation/proc/cl_join(var/datum/computer_file/program/chat_client/Cl)
if(!istype(Cl) || !can_see(Cl) || direct)
return
if(Cl.my_user in users)
return
var/datum/ntnet_message/join/msg = new(Cl)
Cl.my_user.channels.Add(src)
users.Add(Cl.my_user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"autorun" = istype(autorun) && (autorun.stored_data == P.filename),
"running" = (P in idle_threads)
))
else
if(P.program_type & PROGRAM_SERVICE)
data["services"] += list(list(
"filename" = P.filename,
"desc" = P.filedesc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var/datum/ntnet_user/my_user
var/datum/ntnet_conversation/focused_conv
var/datum/ntnet_conversation/active

var/netadmin_mode = FALSE // Administrator mode (invisible to other users + bypasses passwords)
var/set_offline = FALSE // appear "invisible"
Expand Down Expand Up @@ -120,6 +121,29 @@
data["netadmin_mode"] = netadmin_mode
data["can_netadmin_mode"] = can_run(user, FALSE, access_network)
data["message_mute"] = message_mute
if(active && active.can_interact(src))
var/ref = text_ref(active)
var/can_interact = active.can_interact(src)
var/can_manage = active.can_manage(src)
var/list/our_channel = list(
"ref" = ref,
"title" = active.get_title(src),
"direct" = active.direct,
"password" = !!active.password,
"can_interact" = can_interact,
"can_manage" = can_manage,
"focused" = (focused_conv == active)
)
if(can_interact)
our_channel["users"] = list()
for(var/datum/ntnet_user/U in active.users)
var/uref = text_ref(U)
our_channel["users"] += list(list("ref" = uref, "username" = U.username))
data["active"] = our_channel
data["msg"] = active.messages
else
data["active"] = null
data["msg"] = null

return data

Expand Down Expand Up @@ -147,7 +171,6 @@
for(var/datum/ntnet_user/U in channel.users)
var/uref = text_ref(U)
our_channel["users"] += list(list("ref" = uref, "username" = U.username))
data["msg"] = channel.messages
data["channels"] += list(our_channel)

data["users"] = list()
Expand Down Expand Up @@ -194,7 +217,6 @@
if(ishuman(user))
user.visible_message("[SPAN_BOLD("\The [user]")] taps on [user.get_pronoun("his")] [computer.lexical_name]'s screen.")
conv.cl_send(src, message, user)
computer.update_static_data_for_all_viewers()
. = TRUE

if(action == "focus")
Expand Down Expand Up @@ -224,10 +246,22 @@
computer.update_static_data_for_all_viewers()
. = TRUE

if(action == "set_active")
if(isnull(params["set_active"]))
active = null
. = TRUE
else
var/datum/ntnet_conversation/conv = locate(params["set_active"])
if(istype(conv))
active = conv
. = TRUE

if(action == "leave")
var/datum/ntnet_conversation/conv = locate(params["leave"])
if(istype(conv))
conv.cl_leave(src)
if(active)
active = null
computer.update_static_data_for_all_viewers()
. = TRUE

Expand Down
42 changes: 42 additions & 0 deletions html/changelogs/mattatlas-illprotectyou.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
# admin
# backend
# security
# refactor
#################################

# Your name.
author: MattAtlas

# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True

# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- bugfix: "The chat client should now work properly, with self-clearing input and messages displaying correctly. Hopefully."
- bugfix: "Fixed services not showing up in the NTOS main menu."
75 changes: 30 additions & 45 deletions tgui/packages/tgui/interfaces/ChatClient.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BooleanLike } from '../../common/react';
import { useBackend, useLocalState, useSharedState } from '../backend';
import { useBackend, useLocalState } from '../backend';
import { Box, Button, Input, Section, Stack, Table, Tabs } from '../components';
import { NtosWindow } from '../layouts';

Expand All @@ -12,6 +12,7 @@ export type ChatData = {
can_netadmin_mode: BooleanLike;
message_mute: BooleanLike;

active: Channel;
msg: string[];
channels: Channel[];
users: User[];
Expand All @@ -35,11 +36,6 @@ type User = {

export const ChatClient = (props, context) => {
const { act, data } = useBackend<ChatData>(context);
let [active, setActive] = useSharedState<Channel | null>(
context,
'active',
null
);
const [editingRingtone, setEditingRingtone] = useLocalState(
context,
'editingRingtone',
Expand Down Expand Up @@ -92,7 +88,7 @@ export const ChatClient = (props, context) => {
</>
}>
{data.users && data.users.length ? <Users /> : 'There are no users.'}
{!active ? <ChannelsWindow /> : ''}
{!data.active ? <ChannelsWindow /> : ''}
</Section>
</NtosWindow.Content>
</NtosWindow>
Expand All @@ -106,20 +102,15 @@ export const Users = (props, context) => {
`searchTerm`,
``
);
let [active, setActive] = useSharedState<Channel | null>(
context,
'active',
null
);

return (
<Section>
<Section fitted>
<Tabs>
<Tabs.Tab
height="20%"
selected={!active}
onClick={() => setActive(null)}>
selected={!data.active}
onClick={() => act('set_active', { set_active: null })}>
All
</Tabs.Tab>
{data.channels
Expand All @@ -128,14 +119,14 @@ export const Users = (props, context) => {
<Tabs.Tab
height="10%"
key={channel.ref}
selected={active && active.ref === channel.ref}
onClick={() => setActive(channel)}>
selected={data.active && data.active.ref === channel.ref}
onClick={() => act('set_active', { set_active: channel.ref })}>
{channel.title}
</Tabs.Tab>
))}
</Tabs>
</Section>
{active ? <Chat /> : <AllUsers />}
{data.active && data.active.can_interact ? <Chat /> : <AllUsers />}
</Section>
);
};
Expand All @@ -147,11 +138,6 @@ export const AllUsers = (props, context) => {
`searchTerm`,
``
);
let [active, setActive] = useSharedState<Channel | null>(
context,
'active',
null
);

return (
<Stack vertical>
Expand Down Expand Up @@ -197,17 +183,16 @@ export const Chat = (props, context) => {
``
);
const [title, setTitle] = useLocalState<string>(context, `title`, ``);
let [active] = useLocalState<Channel | null>(context, 'active', null);

return (
<Section
title="Conversation"
buttons={
<>
{active && active.can_manage && !active.direct ? (
{data.active && data.active.can_manage && !data.active.direct ? (
<>
<Button
key={active.ref}
key={data.active.ref}
content={password ? 'Close Menu' : 'Set Password'}
onClick={() => setPassword(password ? '' : 'New Password')}
/>
Expand All @@ -219,15 +204,15 @@ export const Chat = (props, context) => {
onChange={(e, v) =>
act('set_password', {
password: password,
target: active ? active.ref : '',
target: data.active ? data.active.ref : '',
})
}
/>
) : (
''
)}
<Button
key={active.ref}
key={data.active.ref}
content={title ? 'Close Menu' : 'Set Title'}
onClick={() => setTitle(title ? '' : 'New Title')}
/>
Expand All @@ -239,7 +224,7 @@ export const Chat = (props, context) => {
onChange={(e, v) =>
act('change_title', {
title: title,
target: active ? active.ref : '',
target: data.active ? data.active.ref : '',
})
}
/>
Expand All @@ -250,7 +235,7 @@ export const Chat = (props, context) => {
content="Delete"
color="red"
onClick={() =>
act('delete', { delete: active ? active.ref : '' })
act('delete', { delete: data.active ? data.active.ref : '' })
}
/>
</>
Expand All @@ -259,17 +244,21 @@ export const Chat = (props, context) => {
)}
<Button
content="Leave"
disabled={active && active.direct}
onClick={() => act('leave', { leave: active ? active.ref : '' })}
disabled={data.active && data.active.direct}
onClick={() =>
act('leave', { leave: data.active ? data.active.ref : '' })
}
/>
<Button
content="Enable STT"
selected={active && active.focused}
onClick={() => act('focus', { focus: active ? active.ref : '' })}
selected={data.active && data.active.focused}
onClick={() =>
act('focus', { focus: data.active ? data.active.ref : '' })
}
/>
</>
}>
{active &&
{data.active &&
data.msg &&
data.msg.map((message) => (
<Box
Expand All @@ -286,30 +275,31 @@ export const Chat = (props, context) => {
value={newMessage}
placeholder="Type your message. Press enter to send."
width="100%"
selfClear
onInput={(e, v) => setNewMessage(v)}
onChange={(e, v) =>
act('send', {
message: newMessage,
target: active ? active.ref : '',
target: data.active ? data.active.ref : '',
})
}
/>
</Box>
<Box py={2}>
<Table>
{active &&
!active.direct &&
active.users.map((user) => (
{data.active &&
!data.active.direct &&
data.active.users.map((user) => (
<Table.Row key={user.ref}>
<Table.Cell>{user.username}</Table.Cell>
<Table.Cell>
<Button
content="Kick"
icon="user"
disabled={active && !active.can_manage}
disabled={data.active && !data.active.can_manage}
onClick={() =>
act('kick', {
target: active ? active.ref : '',
target: data.active ? data.active.ref : '',
user: user.ref,
})
}
Expand All @@ -330,11 +320,6 @@ export const ChannelsWindow = (props, context) => {
`channelSearchTerm`,
``
);
let [active, setActive] = useSharedState<Channel | null>(
context,
'active',
null
);
const [channelName, setChannelName] = useLocalState(
context,
'channelName',
Expand Down

0 comments on commit 1645af3

Please sign in to comment.