From 081aca4915e9bde533fbb3178c762f4504e991aa Mon Sep 17 00:00:00 2001
From: Llywelwyn <82828093+Llywelwyn@users.noreply.github.com>
Date: Sun, 2 Jun 2024 19:44:04 +0100
Subject: [PATCH] Chatlog tweaks: fix-chat/reconnects no longer wipe log; and a
higher max message limit (#19285)
tg chatlog stored a very low number of `persisted messages` (stuff from
the last time chat got saved) and the significantly higher settings
value of how much stuff the player wants to save. when rebuilding chat
for any reason, the current msgs get saved to persisted, and everything
else is deleted.
e.g. any unexpected chat rebuilds means losing pretty much your entire
chatlog irrecoverably
- rscadd: "Increased the upper limit for max messages saved in the
chatlog."
- rscadd: "Chat log pruning and rebuilding now uses the max messages
value, so reconnects and the fix-chat verb will no longer wipe most of
the chatlog."
this means the player has the option to persist more messages which
might cause issues on PCs from 1970 but otherwise i see no issues
---
html/changelogs/lly-log_stuff.yml | 59 +++++++++++++++++++
tgui/packages/tgui-panel/chat/constants.js | 1 -
tgui/packages/tgui-panel/chat/middleware.js | 10 ++--
tgui/packages/tgui-panel/chat/renderer.js | 15 ++---
.../tgui-panel/settings/SettingsPanel.js | 7 ++-
5 files changed, 76 insertions(+), 16 deletions(-)
create mode 100644 html/changelogs/lly-log_stuff.yml
diff --git a/html/changelogs/lly-log_stuff.yml b/html/changelogs/lly-log_stuff.yml
new file mode 100644
index 00000000000..81e30c52ee1
--- /dev/null
+++ b/html/changelogs/lly-log_stuff.yml
@@ -0,0 +1,59 @@
+################################
+# 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
+# - (fixes bugs)
+# wip
+# - (work in progress)
+# qol
+# - (quality of life)
+# soundadd
+# - (adds a sound)
+# sounddel
+# - (removes a sound)
+# rscadd
+# - (adds a feature)
+# rscdel
+# - (removes a feature)
+# imageadd
+# - (adds an image or sprite)
+# imagedel
+# - (removes an image or sprite)
+# spellcheck
+# - (fixes spelling or grammar)
+# experiment
+# - (experimental change)
+# balance
+# - (balance changes)
+# code_imp
+# - (misc internal code change)
+# refactor
+# - (refactors code)
+# config
+# - (makes a change to the config files)
+# admin
+# - (makes changes to administrator tools)
+# server
+# - (miscellaneous changes to server)
+#################################
+
+# Your name.
+author: Llywelwyn
+
+# 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, this gets changed to [] after reading. Just remove the brackets when you add new shit.
+# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog.
+changes:
+ - rscadd: "Increased the upper limit for max messages saved in the chatlog."
+ - rscadd: "Chat log pruning and rebuilding now uses the max messages value, so reconnects and the fix-chat verb will no longer wipe most of the chatlog."
diff --git a/tgui/packages/tgui-panel/chat/constants.js b/tgui/packages/tgui-panel/chat/constants.js
index 5d174e8e87a..25d80a2dc80 100644
--- a/tgui/packages/tgui-panel/chat/constants.js
+++ b/tgui/packages/tgui-panel/chat/constants.js
@@ -4,7 +4,6 @@
* @license MIT
*/
-export const MAX_PERSISTED_MESSAGES = 1000;
export const MESSAGE_SAVE_INTERVAL = 10000;
export const MESSAGE_PRUNE_INTERVAL = 60000;
export const COMBINE_MAX_MESSAGES = 5;
diff --git a/tgui/packages/tgui-panel/chat/middleware.js b/tgui/packages/tgui-panel/chat/middleware.js
index 738bd1c169c..ae5900620a7 100644
--- a/tgui/packages/tgui-panel/chat/middleware.js
+++ b/tgui/packages/tgui-panel/chat/middleware.js
@@ -9,7 +9,7 @@ import { storage } from 'common/storage';
import { loadSettings, updateSettings, addHighlightSetting, removeHighlightSetting, updateHighlightSetting } from '../settings/actions';
import { selectSettings } from '../settings/selectors';
import { addChatPage, changeChatPage, changeScrollTracking, loadChat, rebuildChat, removeChatPage, saveChatToDisk, clearChatMessages, toggleAcceptedType, updateMessageCount } from './actions';
-import { MAX_PERSISTED_MESSAGES, MESSAGE_SAVE_INTERVAL, MESSAGE_PRUNE_INTERVAL } from './constants';
+import { MESSAGE_SAVE_INTERVAL, MESSAGE_PRUNE_INTERVAL } from './constants';
import { createMessage, serializeMessage } from './model';
import { chatRenderer } from './renderer';
import { selectChat, selectCurrentChatPage } from './selectors';
@@ -18,10 +18,11 @@ import { selectChat, selectCurrentChatPage } from './selectors';
const FORBID_TAGS = ['a', 'iframe', 'link', 'video'];
const saveChatToStorage = async (store) => {
+ const settings = selectSettings(store.getState());
const state = selectChat(store.getState());
const fromIndex = Math.max(
0,
- chatRenderer.messages.length - MAX_PERSISTED_MESSAGES
+ chatRenderer.messages.length - settings.maxMessages
);
const messages = chatRenderer.messages
.slice(fromIndex)
@@ -80,7 +81,7 @@ export const chatMiddleware = (store) => {
}, MESSAGE_SAVE_INTERVAL);
setInterval(() => {
const settings = selectSettings(store.getState());
- chatRenderer.pruneMessagesTo(settings.maxMessages, MAX_PERSISTED_MESSAGES);
+ chatRenderer.pruneMessagesTo(settings.maxMessages);
}, MESSAGE_PRUNE_INTERVAL);
return (next) => (action) => {
const { type, payload } = action;
@@ -114,7 +115,8 @@ export const chatMiddleware = (store) => {
return;
}
if (type === rebuildChat.type) {
- chatRenderer.rebuildChat();
+ const settings = selectSettings(store.getState());
+ chatRenderer.rebuildChat(settings.maxMessages);
return next(action);
}
diff --git a/tgui/packages/tgui-panel/chat/renderer.js b/tgui/packages/tgui-panel/chat/renderer.js
index 64858bce33d..70e39f7305e 100644
--- a/tgui/packages/tgui-panel/chat/renderer.js
+++ b/tgui/packages/tgui-panel/chat/renderer.js
@@ -7,7 +7,7 @@
import { EventEmitter } from 'common/events';
import { classes } from 'common/react';
import { createLogger } from 'tgui/logging';
-import { COMBINE_MAX_MESSAGES, COMBINE_MAX_TIME_WINDOW, IMAGE_RETRY_DELAY, IMAGE_RETRY_LIMIT, IMAGE_RETRY_MESSAGE_AGE, MAX_PERSISTED_MESSAGES, MESSAGE_TYPES, MESSAGE_TYPE_INTERNAL, MESSAGE_TYPE_UNKNOWN } from './constants';
+import { COMBINE_MAX_MESSAGES, COMBINE_MAX_TIME_WINDOW, IMAGE_RETRY_DELAY, IMAGE_RETRY_LIMIT, IMAGE_RETRY_MESSAGE_AGE, MESSAGE_TYPES, MESSAGE_TYPE_INTERNAL, MESSAGE_TYPE_UNKNOWN } from './constants';
import { render } from 'inferno';
import { canPageAcceptType, createMessage, isSameMessage } from './model';
import { highlightNode, linkifyNode } from './replaceInTextNode';
@@ -468,7 +468,7 @@ class ChatRenderer {
}
}
- pruneMessagesTo(max_visible_messages, max_persisted_messages) {
+ pruneMessagesTo(max_visible_messages) {
if (!this.isReady()) {
return;
}
@@ -502,7 +502,7 @@ class ChatRenderer {
{
const fromIndex = Math.max(
0,
- this.messages.length - max_persisted_messages
+ this.messages.length - max_visible_messages
);
if (fromIndex > 0) {
this.messages = this.messages.slice(fromIndex);
@@ -511,15 +511,12 @@ class ChatRenderer {
}
}
- rebuildChat() {
+ rebuildChat(max_visible_messages) {
if (!this.isReady()) {
return;
}
// Make a copy of messages
- const fromIndex = Math.max(
- 0,
- this.messages.length - MAX_PERSISTED_MESSAGES
- );
+ const fromIndex = Math.max(0, this.messages.length - max_visible_messages);
const messages = this.messages.slice(fromIndex);
// Remove existing nodes
for (let message of messages) {
@@ -585,7 +582,7 @@ class ChatRenderer {
}
clear() {
- this.pruneMessagesTo(0, 0);
+ this.pruneMessagesTo(0);
}
}
diff --git a/tgui/packages/tgui-panel/settings/SettingsPanel.js b/tgui/packages/tgui-panel/settings/SettingsPanel.js
index e2878d49d50..2d2de41f121 100644
--- a/tgui/packages/tgui-panel/settings/SettingsPanel.js
+++ b/tgui/packages/tgui-panel/settings/SettingsPanel.js
@@ -156,7 +156,7 @@ export const SettingsGeneral = (props, context) => {
step={50}
stepPixelSize={2}
minValue={2000}
- maxValue={16000}
+ maxValue={32000}
value={maxMessages}
format={(value) => toFixed(value)}
onChange={(e, value) =>
@@ -182,6 +182,7 @@ export const SettingsGeneral = (props, context) => {
const TextHighlightSettings = (props, context) => {
const highlightSettings = useSelector(context, selectHighlightSettings);
+ const settings = useSelector(context, selectSettings);
const dispatch = useDispatch(context);
return (
@@ -210,7 +211,9 @@ const TextHighlightSettings = (props, context) => {
-