2019-11-16 17:24:03 +00:00
|
|
|
import socket from "./socket";
|
2019-11-05 20:51:55 +00:00
|
|
|
|
|
|
|
const defaultSettingConfig = {
|
|
|
|
apply() {},
|
|
|
|
default: null,
|
|
|
|
sync: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const config = normalizeConfig({
|
|
|
|
syncSettings: {
|
|
|
|
default: true,
|
|
|
|
sync: "never",
|
2019-12-15 16:03:13 +00:00
|
|
|
apply(store, value, auto = false) {
|
|
|
|
// If applied by settings/applyAll, do not emit to server
|
|
|
|
if (value && !auto) {
|
2019-11-20 17:43:27 +00:00
|
|
|
socket.emit("setting:get");
|
|
|
|
}
|
2019-11-05 20:51:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
advanced: {
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
autocomplete: {
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
nickPostfix: {
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
coloredNicks: {
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
desktopNotifications: {
|
|
|
|
default: false,
|
2020-08-12 15:36:07 +00:00
|
|
|
sync: "never",
|
2019-11-05 20:51:55 +00:00
|
|
|
apply(store, value) {
|
|
|
|
store.commit("refreshDesktopNotificationState", null, {root: true});
|
|
|
|
|
|
|
|
if ("Notification" in window && value && Notification.permission !== "granted") {
|
|
|
|
Notification.requestPermission(() =>
|
|
|
|
store.commit("refreshDesktopNotificationState", null, {root: true})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
highlights: {
|
|
|
|
default: "",
|
|
|
|
sync: "always",
|
|
|
|
},
|
2020-07-22 15:28:12 +00:00
|
|
|
highlightExceptions: {
|
|
|
|
default: "",
|
|
|
|
sync: "always",
|
|
|
|
},
|
2019-03-11 17:25:02 +00:00
|
|
|
awayMessage: {
|
|
|
|
default: "",
|
|
|
|
sync: "always",
|
|
|
|
},
|
2019-11-05 20:51:55 +00:00
|
|
|
links: {
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
motd: {
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
notification: {
|
|
|
|
default: true,
|
2020-08-12 15:36:07 +00:00
|
|
|
sync: "never",
|
2019-11-05 20:51:55 +00:00
|
|
|
},
|
|
|
|
notifyAllMessages: {
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
showSeconds: {
|
|
|
|
default: false,
|
|
|
|
},
|
2020-02-29 09:37:45 +00:00
|
|
|
use12hClock: {
|
|
|
|
default: false,
|
|
|
|
},
|
2019-11-05 20:51:55 +00:00
|
|
|
statusMessages: {
|
|
|
|
default: "condensed",
|
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
default: document.getElementById("theme").dataset.serverTheme,
|
|
|
|
apply(store, value) {
|
|
|
|
const themeEl = document.getElementById("theme");
|
|
|
|
const themeUrl = `themes/${value}.css`;
|
|
|
|
|
|
|
|
if (themeEl.attributes.href.value === themeUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
themeEl.attributes.href.value = themeUrl;
|
|
|
|
const newTheme = store.state.serverConfiguration.themes.filter(
|
|
|
|
(theme) => theme.name === value
|
|
|
|
)[0];
|
|
|
|
const themeColor =
|
|
|
|
newTheme.themeColor || document.querySelector('meta[name="theme-color"]').content;
|
|
|
|
document.querySelector('meta[name="theme-color"]').content = themeColor;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
media: {
|
|
|
|
default: true,
|
|
|
|
},
|
2020-01-03 15:37:28 +00:00
|
|
|
uploadCanvas: {
|
|
|
|
default: true,
|
|
|
|
},
|
2019-11-05 20:51:55 +00:00
|
|
|
userStyles: {
|
|
|
|
default: "",
|
|
|
|
apply(store, value) {
|
|
|
|
if (!/[?&]nocss/.test(window.location.search)) {
|
|
|
|
document.getElementById("user-specified-css").innerHTML = value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-04-12 21:09:55 +00:00
|
|
|
searchEnabled: {
|
|
|
|
default: false,
|
|
|
|
},
|
2019-11-05 20:51:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export function createState() {
|
|
|
|
const state = {};
|
|
|
|
|
|
|
|
for (const settingName in config) {
|
|
|
|
state[settingName] = config[settingName].default;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
function normalizeConfig(obj) {
|
|
|
|
const newConfig = {};
|
|
|
|
|
|
|
|
for (const settingName in obj) {
|
|
|
|
newConfig[settingName] = {...defaultSettingConfig, ...obj[settingName]};
|
|
|
|
}
|
|
|
|
|
|
|
|
return newConfig;
|
|
|
|
}
|