Chatclient fixes 2 (#16587)

* Fixes the chat client and services.

* oh how we love you

* lemme talk to 'em...

* a

* m

* lilas

* bro

---------

Co-authored-by: Matt Atlas <liermattia@gmail.com>
This commit is contained in:
Matt Atlas
2023-06-29 12:31:42 +00:00
committed by GitHub
co-authored by Matt Atlas
parent dd0730580f
commit 1645af37cc
6 changed files with 112 additions and 49 deletions
+1 -1
View File
@@ -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()
@@ -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)
@@ -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,
@@ -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"
@@ -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
@@ -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()
@@ -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")
@@ -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
@@ -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."
+30 -45
View File
@@ -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';
@@ -12,6 +12,7 @@ export type ChatData = {
can_netadmin_mode: BooleanLike;
message_mute: BooleanLike;
active: Channel;
msg: string[];
channels: Channel[];
users: User[];
@@ -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',
@@ -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>
@@ -106,11 +102,6 @@ export const Users = (props, context) => {
`searchTerm`,
``
);
let [active, setActive] = useSharedState<Channel | null>(
context,
'active',
null
);
return (
<Section>
@@ -118,8 +109,8 @@ export const Users = (props, context) => {
<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
@@ -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>
);
};
@@ -147,11 +138,6 @@ export const AllUsers = (props, context) => {
`searchTerm`,
``
);
let [active, setActive] = useSharedState<Channel | null>(
context,
'active',
null
);
return (
<Stack vertical>
@@ -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')}
/>
@@ -219,7 +204,7 @@ export const Chat = (props, context) => {
onChange={(e, v) =>
act('set_password', {
password: password,
target: active ? active.ref : '',
target: data.active ? data.active.ref : '',
})
}
/>
@@ -227,7 +212,7 @@ export const Chat = (props, context) => {
''
)}
<Button
key={active.ref}
key={data.active.ref}
content={title ? 'Close Menu' : 'Set Title'}
onClick={() => setTitle(title ? '' : 'New Title')}
/>
@@ -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 : '',
})
}
/>
@@ -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 : '' })
}
/>
</>
@@ -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
@@ -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,
})
}
@@ -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',