2023-09-07 06:03:12 +00:00
|
|
|
// All the distinct localStorage keys used.
|
|
|
|
const keys = {
|
|
|
|
'fontSizeClass': String, // Text magnification
|
|
|
|
'videoScale': String, // Video magnification (CSS classnames)
|
2023-09-30 21:53:43 +00:00
|
|
|
'messageStyle': String, // Message display style (cards, compact, etc.)
|
2023-09-07 06:03:12 +00:00
|
|
|
'imageDisplaySetting': String, // Show/hide/expand image preference
|
|
|
|
'scrollback': Number, // Scrollback buffer (int)
|
|
|
|
'preferredDeviceNames': Object, // Webcam/mic device names (object, keys video,audio)
|
2023-09-08 03:05:52 +00:00
|
|
|
'whoSort': String, // user's preferred sort order for the Who List
|
2024-04-06 21:35:52 +00:00
|
|
|
'theme': String, // light, dark, or auto theme
|
2023-09-07 06:03:12 +00:00
|
|
|
|
|
|
|
// Webcam settings (booleans)
|
|
|
|
'videoMutual': Boolean,
|
|
|
|
'videoMutualOpen': Boolean,
|
|
|
|
'videoAutoMute': Boolean,
|
|
|
|
'videoVipOnly': Boolean,
|
2023-09-08 03:05:52 +00:00
|
|
|
'videoExplicit': Boolean, // whether the user turns explicit on by default
|
2023-10-14 19:24:30 +00:00
|
|
|
'videoNonExplicit': Boolean, // user prefers not to see explicit
|
|
|
|
'rememberExpresslyClosed': Boolean,
|
2024-01-12 03:45:32 +00:00
|
|
|
'autoMuteWebcams': Boolean, // automatically mute other peoples' webcam audio feeds
|
2024-09-21 22:48:47 +00:00
|
|
|
'videoAutoShare': Boolean, // automatically share your webcam on page load
|
2023-09-07 06:03:12 +00:00
|
|
|
|
|
|
|
// Booleans
|
2023-12-11 02:43:18 +00:00
|
|
|
'usePolling': Boolean, // use the polling API instead of WebSocket
|
2023-09-07 06:03:12 +00:00
|
|
|
'joinMessages': Boolean,
|
|
|
|
'exitMessages': Boolean,
|
|
|
|
'watchNotif': Boolean,
|
|
|
|
'muteSounds': Boolean,
|
|
|
|
'closeDMs': Boolean, // close unsolicited DMs
|
2024-05-08 03:54:13 +00:00
|
|
|
'debug': Boolean, // Debug views enabled (admin only)
|
2023-09-07 06:03:12 +00:00
|
|
|
|
|
|
|
// Don't Show Again on NSFW modals.
|
|
|
|
'skip-nsfw-modal': Boolean,
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserSettings centralizes browser settings for the chat room.
|
|
|
|
class UserSettings {
|
|
|
|
constructor() {
|
|
|
|
// Recall stored settings. Only set the keys that were
|
|
|
|
// found in localStorage on page load.
|
|
|
|
for (let key of Object.keys(keys)) {
|
|
|
|
if (localStorage[key] != undefined) {
|
2023-09-30 21:53:43 +00:00
|
|
|
try {
|
|
|
|
this[key] = JSON.parse(localStorage[key]);
|
|
|
|
} catch(e) {
|
|
|
|
console.error(`LocalStorage: parsing key ${key}: ${e}`);
|
|
|
|
delete(this[key]);
|
2023-09-07 06:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("LocalStorage: Loaded settings", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return all of the current settings where the user had actually
|
|
|
|
// left a preference on them (was in localStorage).
|
|
|
|
getSettings() {
|
|
|
|
let result = {};
|
|
|
|
for (let key of Object.keys(keys)) {
|
|
|
|
if (this[key] != undefined) {
|
|
|
|
result[key] = this[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a value from localStorage, if set.
|
|
|
|
get(key) {
|
|
|
|
return this[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generic setter.
|
|
|
|
set(key, value) {
|
|
|
|
if (keys[key] == undefined) {
|
|
|
|
throw `${key}: not a supported localStorage setting`;
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage[key] = JSON.stringify(value);
|
|
|
|
this[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocalStorage is a global singleton to access and update user settings.
|
|
|
|
const LocalStorage = new UserSettings();
|
|
|
|
export default LocalStorage;
|