61 lines
3.1 KiB
JavaScript
61 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Chat preferences that follow the official TS6 Settings > Chats page (client_ui/main.js settings component
|
|
* near offset 4873300; defaults from workflowSettings class `Xe` and appearanceSettings class `qe`).
|
|
*
|
|
* Official key → TeamsPeach key default
|
|
* appearanceSettings.chat_input_toolbar_visibility → chatToolbarVisibility 'always-visible'
|
|
* appearanceSettings.chat_mermaid_autoload_mode → chatMermaidAutoload 'only-simple'
|
|
* workflowSettings.openIncomingChats → chatOpenIncoming true
|
|
* appearanceSettings.chat_show_system_messages → chatShowModerationEvents true
|
|
* workflowSettings.use24hrTime → chatUse24hTime true
|
|
* workflowSettings.autoDownloadImages → autoDownloadImages false
|
|
* chat-server ignore list (per myTeamSpeak chat connection) → chatIgnoredUsers [] (local, keyed by client UID)
|
|
*
|
|
* Not modelled because TeamsPeach has no backing feature: useRichTextEditor (the composer is a plain
|
|
* textarea), autoAcceptIncomingDirectChats (TS6-server decentral chat invitations), useChatsHistory and
|
|
* sort_contacts_alphabetically / show_offline_contacts / group_offline_contacts (myTeamSpeak contacts and
|
|
* group chats).
|
|
*/
|
|
|
|
const MAX_IGNORED_USERS = 1000;
|
|
const MAX_NAME_LENGTH = 128;
|
|
// TeamSpeak client UIDs are base64 SHA-1 digests; ServerQuery clients use short ASCII ids such as "serveradmin".
|
|
const UID = /^[A-Za-z0-9+/]{1,126}={0,2}$/;
|
|
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
|
|
const isBool = (v) => typeof v === 'boolean';
|
|
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) && Object.getPrototypeOf(v) === Object.prototype;
|
|
|
|
function validUid(uid) {
|
|
return typeof uid === 'string' && uid.length <= 128 && UID.test(uid);
|
|
}
|
|
|
|
/** [{ uid, name }]: unique UIDs; `name` is the nickname seen when the user was ignored (display only). */
|
|
function validIgnoredUsers(list) {
|
|
if (!Array.isArray(list) || list.length > MAX_IGNORED_USERS) return false;
|
|
const seen = new Set();
|
|
for (const entry of list) {
|
|
if (!isPlainObject(entry)) return false;
|
|
const keys = Object.keys(entry);
|
|
if (keys.length !== 2 || !keys.includes('uid') || !keys.includes('name')) return false;
|
|
if (!validUid(entry.uid) || seen.has(entry.uid)) return false;
|
|
if (typeof entry.name !== 'string' || entry.name.length > MAX_NAME_LENGTH || CONTROL.test(entry.name)) return false;
|
|
seen.add(entry.uid);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
const CHAT_SCHEMA = {
|
|
chatToolbarVisibility: { default: 'always-visible', check: (v) => v === 'inactive' || v === 'dynamic' || v === 'always-visible' },
|
|
chatMermaidAutoload: { default: 'only-simple', check: (v) => v === 'never' || v === 'only-simple' },
|
|
chatOpenIncoming: { default: true, check: isBool },
|
|
chatShowModerationEvents: { default: true, check: isBool },
|
|
chatUse24hTime: { default: true, check: isBool },
|
|
autoDownloadImages: { default: false, check: isBool },
|
|
chatIgnoredUsers: { default: [], check: validIgnoredUsers },
|
|
};
|
|
|
|
module.exports = { CHAT_SCHEMA, MAX_IGNORED_USERS, validUid };
|