1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

userpage: cope with disabled contact methods

This commit is contained in:
Harvey Tindall 2023-09-07 14:40:24 +01:00
parent 0b830e9b5e
commit 00e6da520d
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -363,7 +363,8 @@ const discordConf: ServiceConfiguration = {
} }
}; };
let discord = new Discord(discordConf); let discord: Discord;
if (window.discordEnabled) discord = new Discord(discordConf);
const telegramConf: ServiceConfiguration = { const telegramConf: ServiceConfiguration = {
modal: window.modals.telegram as Modal, modal: window.modals.telegram as Modal,
@ -378,7 +379,8 @@ const telegramConf: ServiceConfiguration = {
} }
}; };
let telegram = new Telegram(telegramConf); let telegram: Telegram;
if (window.telegramEnabled) telegram = new Telegram(telegramConf);
const matrixConf: MatrixConfiguration = { const matrixConf: MatrixConfiguration = {
modal: window.modals.matrix as Modal, modal: window.modals.matrix as Modal,
@ -393,7 +395,8 @@ const matrixConf: MatrixConfiguration = {
} }
}; };
let matrix = new Matrix(matrixConf); let matrix: Matrix;
if (window.matrixEnabled) matrix = new Matrix(matrixConf);
const oldPasswordField = document.getElementById("user-old-password") as HTMLInputElement; const oldPasswordField = document.getElementById("user-old-password") as HTMLInputElement;
@ -468,14 +471,15 @@ document.addEventListener("details-reload", () => {
// Note the weird format of the functions for discord/telegram: // Note the weird format of the functions for discord/telegram:
// "this" was being redefined within the onclick() method, so // "this" was being redefined within the onclick() method, so
// they had to be wrapped in an anonymous function. // they had to be wrapped in an anonymous function.
const contactMethods: { name: string, icon: string, f: (add: boolean) => void, required: boolean }[] = [ const contactMethods: { name: string, icon: string, f: (add: boolean) => void, required: boolean, enabled: boolean }[] = [
{name: "email", icon: `<i class="ri-mail-fill ri-lg"></i>`, f: addEditEmail, required: true}, {name: "email", icon: `<i class="ri-mail-fill ri-lg"></i>`, f: addEditEmail, required: true, enabled: true},
{name: "discord", icon: `<i class="ri-discord-fill ri-lg"></i>`, f: (add: boolean) => { discord.onclick(); }, required: window.discordRequired}, {name: "discord", icon: `<i class="ri-discord-fill ri-lg"></i>`, f: (add: boolean) => { discord.onclick(); }, required: window.discordRequired, enabled: window.discordEnabled},
{name: "telegram", icon: `<i class="ri-telegram-fill ri-lg"></i>`, f: (add: boolean) => { telegram.onclick() }, required: window.telegramRequired}, {name: "telegram", icon: `<i class="ri-telegram-fill ri-lg"></i>`, f: (add: boolean) => { telegram.onclick() }, required: window.telegramRequired, enabled: window.telegramEnabled},
{name: "matrix", icon: `<span class="font-bold">[m]</span>`, f: (add: boolean) => { matrix.show(); }, required: window.matrixRequired} {name: "matrix", icon: `<span class="font-bold">[m]</span>`, f: (add: boolean) => { matrix.show(); }, required: window.matrixRequired, enabled: window.matrixEnabled}
]; ];
for (let method of contactMethods) { for (let method of contactMethods) {
if (!(method.enabled)) continue;
if (method.name in details) { if (method.name in details) {
contactMethodList.append(method.name, details[method.name], method.icon, method.f, method.required); contactMethodList.append(method.name, details[method.name], method.icon, method.f, method.required);
} }