From 4e755ace368d8f1161459bd4ab938a4882bbedb0 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Mon, 7 Jul 2025 11:23:11 +0200 Subject: [PATCH] Finish config conversion --- src/router/index.js | 8 ++++---- src/services/config.service.ts | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 6e990ba..863587f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -157,7 +157,7 @@ router.beforeEach((to, from, next) => { let roomId = util.sanitizeUserId(to.params.userId); if (roomId && !roomId.startsWith("@")) { // Not a full username. Assume local name on this server. - return router.app.$config.promise.then((config) => { + return router.app.$config.load().then((config) => { const domain = config.defaultMatrixDomainPart; if (!domain) throw new Error("No domain part for user invite!"); roomId = "@" + roomId + ":" + domain; @@ -174,7 +174,7 @@ router.beforeEach((to, from, next) => { router.app.$matrix.setCurrentRoomId(roomId); } } else if (to.name == 'CreateRoom') { - return router.app.$config.promise.then((config) => { + return router.app.$config.load().then((config) => { if (config.hide_add_room_on_home || !config.roomTypes.includes("group_chat")) { next('/'); } else { @@ -182,7 +182,7 @@ router.beforeEach((to, from, next) => { } }).catch(err => { console.error(err); next('/'); }); } else if (to.name == 'CreateChannel') { - return router.app.$config.promise.then((config) => { + return router.app.$config.load().then((config) => { if (!config.roomTypes.includes("channel")) { next('/'); } else { @@ -190,7 +190,7 @@ router.beforeEach((to, from, next) => { } }).catch(err => { console.error(err); next('/'); }); } else if (to.name == 'CreateFileDrop') { - return router.app.$config.promise.then((config) => { + return router.app.$config.load().then((config) => { if (!config.roomTypes.includes("file_drop")) { next('/'); } else { diff --git a/src/services/config.service.ts b/src/services/config.service.ts index a6515ff..92d5da4 100644 --- a/src/services/config.service.ts +++ b/src/services/config.service.ts @@ -1,6 +1,8 @@ import * as defaultConfig from "@/assets/config.json"; export class Config { + // Configuration file entries + // appName: string = ""; appNames: { [key: string]: string } = {}; languageSupportEmail: string = ""; @@ -11,6 +13,7 @@ export class Config { defaultMatrixDomainPart: string = ""; identityServer?: string; registrationToken?: string; + userIdPrefix?: string; accentColor?: string; logo?: string; analytics: { type?: string; enabled: boolean; config?: any }[] = []; @@ -27,6 +30,9 @@ export class Config { shortCodeStickers?: { packs: { name: string; stickers: string[] }[] }; roomTypes: ("group_chat" | "channel" | "file_drop")[] = ["group_chat", "channel", "file_drop"]; + + // Class implementation + // _loaded: boolean; _loadPromise: Promise | undefined; @@ -57,9 +63,10 @@ export class Config { fromJson = (json: { [key: string]: any }) => { for (const key of Object.keys(json)) { if (!Object.hasOwn(this, key)) { - console.error("NO SUCH CONFIG VALUE", key); + console.warn("Invalid config value", key); + } else { + (this as any)[key] = json[key]; } - (this as any)[key] = json[key]; } };