From 50d35f7d4c762302fed38df6737d49ce34cb8e38 Mon Sep 17 00:00:00 2001 From: _0Steven Date: Fri, 1 Nov 2024 18:44:44 +0100 Subject: [PATCH] fix duplicate message jank, fix headers (87610) --- .../computers/item/computer.dm | 4 +- .../programs/chatroom/conversation.dm | 13 +++-- .../programs/chatroom/ntnrc_client.dm | 49 +++++++++++++------ tgui/packages/tgui/interfaces/NtosNetChat.jsx | 2 +- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/code/modules/modular_computers/computers/item/computer.dm b/code/modules/modular_computers/computers/item/computer.dm index 79ed186472ac1..8eeaa7bfbd3d9 100644 --- a/code/modules/modular_computers/computers/item/computer.dm +++ b/code/modules/modular_computers/computers/item/computer.dm @@ -607,14 +607,14 @@ if(NTNET_ETHERNET_SIGNAL) data["PC_ntneticon"] = "sig_lan.gif" + var/list/program_headers = list() if(length(idle_threads)) - var/list/program_headers = list() for(var/datum/computer_file/program/idle_programs as anything in idle_threads) if(!idle_programs.ui_header) continue program_headers.Add(list(list("icon" = idle_programs.ui_header))) - data["PC_programheaders"] = program_headers + data["PC_programheaders"] = program_headers data["PC_stationtime"] = station_time_timestamp() data["PC_stationdate"] = "[time2text(world.realtime, "DDD, Month DD")], [CURRENT_STATION_YEAR]" diff --git a/code/modules/modular_computers/file_system/programs/chatroom/conversation.dm b/code/modules/modular_computers/file_system/programs/chatroom/conversation.dm index fcfa41e3c90ac..1c3c7e95f10e7 100644 --- a/code/modules/modular_computers/file_system/programs/chatroom/conversation.dm +++ b/code/modules/modular_computers/file_system/programs/chatroom/conversation.dm @@ -13,8 +13,10 @@ ///ID using the UID. var/id - ///List of all messages sent in the conversation. + ///Associative list of all messages sent in the conversation. id > message var/list/messages = list() + ///ID used for next message, increments each use. Convert to string before use. + var/next_message_id = 0 ///The "Administrator" of the channel, the creator starts as channel's operator by default. var/datum/computer_file/program/chatclient/channel_operator @@ -45,11 +47,16 @@ /datum/ntnet_conversation/proc/add_message(message, username) message = "[station_time_timestamp(format = "hh:mm")] [username]: [message]" - messages.Add(message) + var/message_id = "[next_message_id]" + next_message_id++ + messages[message_id] = message trim_message_list() /datum/ntnet_conversation/proc/add_status_message(message) - messages.Add("[station_time_timestamp(format = "hh:mm")] -!- [message]") + message = "[station_time_timestamp(format = "hh:mm")] -!- [message]" + var/message_id = "[next_message_id]" + next_message_id++ + messages[message_id] = message trim_message_list() /datum/ntnet_conversation/proc/trim_message_list() diff --git a/code/modules/modular_computers/file_system/programs/chatroom/ntnrc_client.dm b/code/modules/modular_computers/file_system/programs/chatroom/ntnrc_client.dm index 87a04e6a212fb..532f6128c1e29 100644 --- a/code/modules/modular_computers/file_system/programs/chatroom/ntnrc_client.dm +++ b/code/modules/modular_computers/file_system/programs/chatroom/ntnrc_client.dm @@ -23,8 +23,8 @@ ///The user's screen name. var/username - ///The last message you sent in a channel, used to tell if someone has sent a new message yet. - var/last_message + ///The id of the last message sent in a channel, used to tell if someone has sent a new message yet. + var/last_message_id ///The channel currently active in. var/active_channel ///If the tablet is in Admin mode, you bypass Passwords and aren't announced when entering a channel. @@ -131,8 +131,8 @@ // Now we will generate HTML-compliant file that can actually be viewed/printed. logfile.filename = logname logfile.stored_text = "\[b\]Logfile dump from NTNRC channel [channel.title]\[/b\]\[BR\]" - for(var/logstring in channel.messages) - logfile.stored_text = "[logfile.stored_text][logstring]\[BR\]" + for(var/message_id in channel.messages) + logfile.stored_text = "[logfile.stored_text][channel.messages[message_id]]\[BR\]" logfile.stored_text = "[logfile.stored_text]\[b\]Logfile dump completed.\[/b\]" logfile.calculate_size() if(!computer || !computer.store_file(logfile)) @@ -181,19 +181,23 @@ /datum/computer_file/program/chatclient/process_tick(seconds_per_tick) . = ..() - var/datum/ntnet_conversation/channel = SSmodular_computers.get_chat_channel_by_id(active_channel) - if(src in computer.idle_threads) + + if(!(src in computer.idle_threads)) + return + + var/datum/ntnet_conversation/watched_channel = SSmodular_computers.get_chat_channel_by_id(active_channel) + if(isnull(watched_channel)) // If we're not in a channel, no need for a message notification header. + ui_header = null + return + if(!length(watched_channel.messages)) // But if there's no messages, we do still wait for a message. ui_header = "ntnrc_idle.gif" - if(channel) - // Remember the last message. If there is no message in the channel remember null. - last_message = length(channel.messages) ? channel.messages[length(channel.messages)] : null - else - last_message = null - return TRUE - if(channel?.messages?.len) - ui_header = (last_message == channel.messages[length(channel.messages)] ? "ntnrc_idle.gif" : "ntnrc_new.gif") - else + return + + var/last_message_id_found = watched_channel.messages[length(watched_channel.messages)] + if(last_message_id_found == last_message_id) ui_header = "ntnrc_idle.gif" + return + ui_header = "ntnrc_new.gif" /datum/computer_file/program/chatclient/on_start(mob/living/user) . = ..() @@ -218,6 +222,17 @@ return STATUS_AWAY return STATUS_OFFLINE +/datum/computer_file/program/chatclient/background_program(mob/user) + . = ..() + var/datum/ntnet_conversation/open_channel = SSmodular_computers.get_chat_channel_by_id(active_channel) + if(isnull(open_channel) || !length(open_channel.messages)) + last_message_id = null + ui_header = null + return + + last_message_id = open_channel.messages[length(open_channel.messages)] + ui_header = "ntnrc_idle.gif" + /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. @@ -263,8 +278,10 @@ data["clients"] = clients var/list/messages = list() for(var/i=channel.messages.len to 1 step -1) + var/message_id = channel.messages[i] messages.Add(list(list( - "msg" = channel.messages[i], + "key" = message_id, + "msg" = channel.messages[message_id], ))) data["messages"] = messages data["is_operator"] = (channel.channel_operator == src) || netadmin_mode diff --git a/tgui/packages/tgui/interfaces/NtosNetChat.jsx b/tgui/packages/tgui/interfaces/NtosNetChat.jsx index 2a1617cf12b4d..a9f0bbccb8f87 100644 --- a/tgui/packages/tgui/interfaces/NtosNetChat.jsx +++ b/tgui/packages/tgui/interfaces/NtosNetChat.jsx @@ -151,7 +151,7 @@ export const NtosNetChat = (props) => { {(in_channel && (authorized ? ( messages.map((message) => ( - {message.msg} + {message.msg} )) ) : (