From 50d38e8b1cb8e96a0dbead98073f53fd64cb94ff Mon Sep 17 00:00:00 2001 From: DreamySkrell <107256943+DreamySkrell@users.noreply.github.com> Date: Wed, 29 Mar 2023 20:34:54 +0200 Subject: [PATCH] Chat message limit can now be changed (#16121) * a * Update code/modules/goonchat/browserassets/js/browserOutput.js Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com> * Update html/changelogs/DreamySkrell-chatmessagelimit11112.yml Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com> * Update code/modules/goonchat/browserassets/js/browserOutput.js Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com> * b * whitespace... * Update code/modules/goonchat/browserassets/js/browserOutput.js Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com> --------- Co-authored-by: DreamySkrell <> Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com> --- .../browserassets/html/browserOutput.html | 1 + .../browserassets/js/browserOutput.js | 60 +++++++++++++++++-- .../DreamySkrell-chatmessagelimit11112.yml | 41 +++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 html/changelogs/DreamySkrell-chatmessagelimit11112.yml diff --git a/code/modules/goonchat/browserassets/html/browserOutput.html b/code/modules/goonchat/browserassets/html/browserOutput.html index 11840cc9a78..b84a232f2f5 100644 --- a/code/modules/goonchat/browserassets/html/browserOutput.html +++ b/code/modules/goonchat/browserassets/html/browserOutput.html @@ -56,6 +56,7 @@ Increase line height Toggle ping display Highlight string + Change message limit Save chat log Toggle line combining Clear all messages diff --git a/code/modules/goonchat/browserassets/js/browserOutput.js b/code/modules/goonchat/browserassets/js/browserOutput.js index 979299c1d5d..121195ef318 100644 --- a/code/modules/goonchat/browserassets/js/browserOutput.js +++ b/code/modules/goonchat/browserassets/js/browserOutput.js @@ -24,8 +24,10 @@ window.status = 'Output'; var $messages, $subTheme, $subOptions, $subFont, $selectedSub, $contextMenu, $filterMessages, $last_message; var opts = { //General - 'messageCount': 0, //A count...of messages... - 'messageLimit': 2053, //A limit...for the messages... + 'messageCount': 0, //A count of messages + 'messageLimit': 2048, //A limit for the messages + 'messageLimitMin': 2048, + 'messageLimitMax': 16384, 'scrollSnapTolerance': 10, //If within x pixels of bottom 'clickTolerance': 10, //Keep focus if outside x pixels of mousedown position on mouseup 'imageRetryDelay': 50, //how long between attempts to reload images (in ms) @@ -348,9 +350,9 @@ function output(message, flag) { opts.messageCount++; //Pop the top message off if history limit reached - if (opts.messageCount >= opts.messageLimit) { + while (opts.messageCount >= opts.messageLimit) { $messages.children('div.entry:first-child').remove(); - opts.messageCount--; //I guess the count should only ever equal the limit + opts.messageCount--; } // Create the element - if combining is off, we use it, and if it's on, we @@ -670,6 +672,7 @@ $(function() { fontsize: getCookie('fontsize'), iconsize: getCookie('iconsize'), lineheight: getCookie('lineheight'), + 'smessageLimit': getCookie('messageLimit'), 'spingDisabled': getCookie('pingdisabled'), 'shighlightTerms': getCookie('highlightterms'), 'shighlightColor': getCookie('highlightcolor'), @@ -694,6 +697,17 @@ $(function() { if(savedConfig.stheme){ setTheme(savedConfig.stheme); } + if (savedConfig.smessageLimit) { + var limit = parseInt(savedConfig.smessageLimit); + if(isNaN(limit) || limit < opts.messageLimitMin) { + limit = opts.messageLimitMin + } + if(limit > opts.messageLimitMax) { + limit = opts.messageLimitMax + } + opts.messageLimit = limit; + internalOutput('Loaded message limit of '+opts.messageLimit+'', 'internal'); + } if (savedConfig.spingDisabled) { if (savedConfig.spingDisabled == 'true') { opts.pingDisabled = true; @@ -994,6 +1008,44 @@ $(function() { setCookie('highlightcolor', opts.highlightColor, 365); }); + $('#messageLimit').click(function(e) { + if ($('.popup .messageLimit').is(':visible')) {return;} + var popupContent = '
Chat Message Limit
' + + '
' + + '
Choose the limit of messages in the chat. Default value is '+opts.messageLimitMin+', min is '+opts.messageLimitMin+', max is '+opts.messageLimitMax+'. ' + + 'If limit is reached, oldest messages at the top will be deleted. Higher limits may cause lower performance during long rounds.
' + + '
' + + '
' + + '
' + + '
' + + '
'; + createPopup(popupContent, 250); + }); + + $('body').on('submit', '#messageLimitForm', function(e) { + e.preventDefault(); + + var limit = $('#messageLimitInput').val(); + limit = parseInt(limit); + + if(isNaN(limit) || limit < opts.messageLimitMin) { + limit = opts.messageLimitMin + internalOutput('Message limit invalid or below min value.', 'internal'); + } + if(limit > opts.messageLimitMax) { + limit = opts.messageLimitMax + internalOutput('Message limit above max value.', 'internal'); + } + + opts.messageLimit = limit + internalOutput('Message limit set to '+opts.messageLimit+'', 'internal'); + + var $popup = $('#messageLimitPopup').closest('.popup'); + $popup.remove(); + + setCookie('messageLimit', opts.messageLimit, 365); + }); + $('#clearMessages').click(function() { $messages.empty(); opts.messageCount = 0; diff --git a/html/changelogs/DreamySkrell-chatmessagelimit11112.yml b/html/changelogs/DreamySkrell-chatmessagelimit11112.yml new file mode 100644 index 00000000000..ad89a74b9d1 --- /dev/null +++ b/html/changelogs/DreamySkrell-chatmessagelimit11112.yml @@ -0,0 +1,41 @@ +################################ +# 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: DreamySkrell + +# 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: + - tweak: "Chat message limit can now be changed."