[MIRROR] allows to hide important messages for admins in TG chat tabs (#7922)

Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
Co-authored-by: CHOMPStation2 <chompsation2@gmail.com>
This commit is contained in:
CHOMPStation2
2024-03-10 14:47:56 +01:00
committed by GitHub
co-authored by Kashargul CHOMPStation2
parent 05552c5c7a
commit b20ddf29c0
6 changed files with 105 additions and 24 deletions
@@ -166,6 +166,7 @@ export const chatMiddleware = (store) => {
settings.storedTypes,
game.roundId,
settings.prependTimestamps,
settings.hideImportantInAdminTab,
);
// Load the chat once settings are loaded
if (!initialized && settings.initialized) {
+29
View File
@@ -11,6 +11,35 @@ import { MESSAGE_TYPE_INTERNAL, MESSAGE_TYPES } from './constants';
export const canPageAcceptType = (page, type) =>
type.startsWith(MESSAGE_TYPE_INTERNAL) || page.acceptedTypes[type];
export const typeIsImportant = (type) => {
let isImportant = false;
for (let typeDef of MESSAGE_TYPES) {
if (typeDef.type === type && !!typeDef.important) {
isImportant = true;
break;
}
}
return isImportant;
};
export const adminPageOnly = (page) => {
let adminTab = true;
let checked = 0;
for (let typeDef of MESSAGE_TYPES) {
if (
page.acceptedTypes[typeDef.type] &&
!(!!typeDef.important || !!typeDef.admin)
) {
adminTab = false;
break;
}
if (page.acceptedTypes[typeDef.type] && !typeDef.important) {
checked++;
}
}
return checked > 0 && adminTab;
};
export const canStoreType = (storedTypes, type) => storedTypes[type];
export const createPage = (obj) => {
+43 -24
View File
@@ -20,11 +20,13 @@ import {
MESSAGE_TYPES,
} from './constants';
import {
adminPageOnly,
canPageAcceptType,
canStoreType,
createMessage,
isSameMessage,
serializeMessage,
typeIsImportant,
} from './model';
import { highlightNode, linkifyNode } from './replaceInTextNode';
@@ -155,6 +157,7 @@ class ChatRenderer {
this.logEnable = true;
this.roundId = null;
this.storedTypes = {};
this.hideImportantInAdminTab = false;
// Scroll handler
/** @type {HTMLElement} */
this.scrollNode = null;
@@ -366,6 +369,30 @@ class ChatRenderer {
this.scrollNode.scrollTop = this.scrollNode.scrollHeight;
}
setVisualChatLimits(
visibleMessageLimit,
combineMessageLimit,
combineIntervalLimit,
exportLimit,
logEnable,
logLimit,
storedTypes,
roundId,
prependTimestamps,
hideImportantInAdminTab,
) {
this.visibleMessageLimit = visibleMessageLimit;
this.combineMessageLimit = combineMessageLimit;
this.combineIntervalLimit = combineIntervalLimit;
this.exportLimit = exportLimit;
this.logEnable = logEnable;
this.logLimit = logLimit;
this.storedTypes = storedTypes;
this.roundId = roundId;
this.prependTimestamps = prependTimestamps;
this.hideImportantInAdminTab = hideImportantInAdminTab;
}
changePage(page) {
if (!this.isReady()) {
this.page = page;
@@ -380,7 +407,14 @@ class ChatRenderer {
const fragment = document.createDocumentFragment();
let node;
for (let message of this.messages) {
if (canPageAcceptType(page, message.type)) {
if (
canPageAcceptType(page, message.type) &&
!(
adminPageOnly(page) &&
typeIsImportant(message.type) &&
this.hideImportantInAdminTab
)
) {
node = message.node;
fragment.appendChild(node);
this.visibleMessages.push(message);
@@ -392,28 +426,6 @@ class ChatRenderer {
}
}
setVisualChatLimits(
visibleMessageLimit,
combineMessageLimit,
combineIntervalLimit,
exportLimit,
logEnable,
logLimit,
storedTypes,
roundId,
prependTimestamps,
) {
this.visibleMessageLimit = visibleMessageLimit;
this.combineMessageLimit = combineMessageLimit;
this.combineIntervalLimit = combineIntervalLimit;
this.exportLimit = exportLimit;
this.logEnable = logEnable;
this.logLimit = logLimit;
this.storedTypes = storedTypes;
this.roundId = roundId;
this.prependTimestamps = prependTimestamps;
}
getCombinableMessage(predicate) {
const now = Date.now();
const len = this.visibleMessages.length;
@@ -619,7 +631,14 @@ class ChatRenderer {
}
this.archivedMessages.push(serializeMessage(message, true)); // TODO: Actually having a better message archiving maybe for exports?
}
if (canPageAcceptType(this.page, message.type)) {
if (
canPageAcceptType(this.page, message.type) &&
!(
adminPageOnly(this.page) &&
typeIsImportant(message.type) &&
this.hideImportantInAdminTab
)
) {
fragment.appendChild(node);
this.visibleMessages.push(message);
}
@@ -81,6 +81,7 @@ export const SettingsPanel = (props) => {
{activeTab === 'export' && <ExportTab />}
{activeTab === 'chatPage' && <ChatPageSettings />}
{activeTab === 'textHighlight' && <TextHighlightSettings />}
{activeTab === 'adminSettings' && <AdminSettings />}
</Stack.Item>
</Stack>
);
@@ -804,3 +805,29 @@ const TextHighlightSetting = (props) => {
</Flex.Item>
);
};
export const AdminSettings = (props) => {
const dispatch = useDispatch();
const { hideImportantInAdminTab } = useSelector(selectSettings);
return (
<Section>
<LabeledList>
<LabeledList.Item label="Hide Important messages in admin only tabs">
<Button.Checkbox
checked={hideImportantInAdminTab}
content=""
tooltip="Enabling this will hide all important messages in admin filter exclusive tabs."
mr="5px"
onClick={() =>
dispatch(
updateSettings({
hideImportantInAdminTab: !hideImportantInAdminTab,
}),
)
}
/>
</LabeledList.Item>
</LabeledList>
</Section>
);
};
@@ -9,6 +9,10 @@ export const SETTINGS_TABS = [
id: 'general',
name: 'General',
},
{
id: 'adminSettings',
name: 'Admin',
},
{
id: 'limits',
name: 'Visual Limits',
@@ -58,6 +58,7 @@ const initialState = {
lastId: null,
initialized: false,
storedTypes: {},
hideImportantInAdminTab: false,
};
export const settingsReducer = (state = initialState, action) => {