Skip to content

Reduces stuttering issues for 516 users #6636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tgui/packages/tgui-panel/chat/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

export const MAX_VISIBLE_MESSAGES = 2500;
export const MAX_PERSISTED_MESSAGES = 1000;
export const MESSAGE_SAVE_INTERVAL = 10000;
export const MAX_PERSISTED_MESSAGES = 500;
export const MESSAGE_SAVE_INTERVAL = 60000;
export const MESSAGE_PRUNE_INTERVAL = 60000;
export const COMBINE_MAX_MESSAGES = 5;
export const COMBINE_MAX_TIME_WINDOW = 5000;
Expand Down
13 changes: 13 additions & 0 deletions tgui/packages/tgui-panel/chat/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ import { selectChat, selectCurrentChatPage } from './selectors';
const FORBID_TAGS = ['a', 'iframe', 'link', 'video'];

const saveChatToStorage = async (store) => {
// Early return if chat saving is disabled
const chatSavingEnabled = await storage.get('chat-saving-enabled');
if (chatSavingEnabled === false) {
return;
}

const state = selectChat(store.getState());
const fromIndex = Math.max(
0,
Expand All @@ -51,6 +57,13 @@ const saveChatToStorage = async (store) => {
};

const loadChatFromStorage = async (store) => {
// Early return if chat saving is disabled
const chatSavingEnabled = await storage.get('chat-saving-enabled');
if (chatSavingEnabled === false) {
store.dispatch(loadChat());
return;
}

const [state, messages] = await Promise.all([
storage.get('chat-state'),
storage.get('chat-messages'),
Expand Down
21 changes: 20 additions & 1 deletion tgui/packages/tgui-panel/settings/SettingsPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import { importChatSettings } from './settingsImExport';
import { reconnectWebsocket, disconnectWebsocket } from '../websocket';
import { chatRenderer } from '../chat/renderer';
import { storage } from 'common/storage';

export const SettingsPanel = (props, context) => {
const activeTab = useSelector(context, selectActiveTab);
Expand Down Expand Up @@ -85,14 +86,24 @@ export const SettingsPanel = (props, context) => {
};

export const SettingsGeneral = (props, context) => {
const { theme, fontFamily, fontSize, lineHeight } = useSelector(
const { theme, fontFamily, fontSize, lineHeight, chatSaving } = useSelector(
context,
selectSettings,
);
const dispatch = useDispatch(context);
const [freeFont, setFreeFont] = useLocalState('freeFont', false);
const [editingPanes, setEditingPanes] = useLocalState('freeFont', false);

const updateChatSaving = (value) => {
const boolValue = value === true;
dispatch(
updateSettings({
chatSaving: boolValue,
}),
);
storage.set('chat-saving-enabled', boolValue);
};

return (
<Section>
<LabeledList>
Expand Down Expand Up @@ -246,6 +257,14 @@ export const SettingsGeneral = (props, context) => {
Import settings
</Button.File>
</Stack.Item>
<Stack.Item mt={0.15}>
<Button.Checkbox
checked={chatSaving === true}
content="Persistent Chat"
tooltip="Enable chat persistence"
onClick={() => updateChatSaving(!chatSaving)}
/>
</Stack.Item>
<Stack.Item grow mt={0.15}>
<Button
content="Save chat log"
Expand Down
3 changes: 3 additions & 0 deletions tgui/packages/tgui-panel/settings/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from './actions';
import { createDefaultHighlightSetting } from './model';
import { SETTINGS_TABS, FONTS } from './constants';
import { storage } from 'common/storage';

const defaultHighlightSetting = createDefaultHighlightSetting();

Expand Down Expand Up @@ -45,6 +46,8 @@ const initialState = {
initialized: false,
websocketEnabled: false,
websocketServer: '',
// Chat persistence setting - default is false, but use stored value if available
chatSaving: storage.get('chat-saving-enabled') === true,
};

export const settingsReducer = (state = initialState, action) => {
Expand Down
Loading