Finish config conversion

This commit is contained in:
N-Pex 2025-07-07 11:23:11 +02:00
parent eb58f77162
commit 4e755ace36
2 changed files with 13 additions and 6 deletions

View file

@ -157,7 +157,7 @@ router.beforeEach((to, from, next) => {
let roomId = util.sanitizeUserId(to.params.userId); let roomId = util.sanitizeUserId(to.params.userId);
if (roomId && !roomId.startsWith("@")) { if (roomId && !roomId.startsWith("@")) {
// Not a full username. Assume local name on this server. // 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; const domain = config.defaultMatrixDomainPart;
if (!domain) throw new Error("No domain part for user invite!"); if (!domain) throw new Error("No domain part for user invite!");
roomId = "@" + roomId + ":" + domain; roomId = "@" + roomId + ":" + domain;
@ -174,7 +174,7 @@ router.beforeEach((to, from, next) => {
router.app.$matrix.setCurrentRoomId(roomId); router.app.$matrix.setCurrentRoomId(roomId);
} }
} else if (to.name == 'CreateRoom') { } 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")) { if (config.hide_add_room_on_home || !config.roomTypes.includes("group_chat")) {
next('/'); next('/');
} else { } else {
@ -182,7 +182,7 @@ router.beforeEach((to, from, next) => {
} }
}).catch(err => { console.error(err); next('/'); }); }).catch(err => { console.error(err); next('/'); });
} else if (to.name == 'CreateChannel') { } else if (to.name == 'CreateChannel') {
return router.app.$config.promise.then((config) => { return router.app.$config.load().then((config) => {
if (!config.roomTypes.includes("channel")) { if (!config.roomTypes.includes("channel")) {
next('/'); next('/');
} else { } else {
@ -190,7 +190,7 @@ router.beforeEach((to, from, next) => {
} }
}).catch(err => { console.error(err); next('/'); }); }).catch(err => { console.error(err); next('/'); });
} else if (to.name == 'CreateFileDrop') { } 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")) { if (!config.roomTypes.includes("file_drop")) {
next('/'); next('/');
} else { } else {

View file

@ -1,6 +1,8 @@
import * as defaultConfig from "@/assets/config.json"; import * as defaultConfig from "@/assets/config.json";
export class Config { export class Config {
// Configuration file entries
//
appName: string = ""; appName: string = "";
appNames: { [key: string]: string } = {}; appNames: { [key: string]: string } = {};
languageSupportEmail: string = ""; languageSupportEmail: string = "";
@ -11,6 +13,7 @@ export class Config {
defaultMatrixDomainPart: string = ""; defaultMatrixDomainPart: string = "";
identityServer?: string; identityServer?: string;
registrationToken?: string; registrationToken?: string;
userIdPrefix?: string;
accentColor?: string; accentColor?: string;
logo?: string; logo?: string;
analytics: { type?: string; enabled: boolean; config?: any }[] = []; analytics: { type?: string; enabled: boolean; config?: any }[] = [];
@ -27,6 +30,9 @@ export class Config {
shortCodeStickers?: { packs: { name: string; stickers: string[] }[] }; shortCodeStickers?: { packs: { name: string; stickers: string[] }[] };
roomTypes: ("group_chat" | "channel" | "file_drop")[] = ["group_chat", "channel", "file_drop"]; roomTypes: ("group_chat" | "channel" | "file_drop")[] = ["group_chat", "channel", "file_drop"];
// Class implementation
//
_loaded: boolean; _loaded: boolean;
_loadPromise: Promise<Config> | undefined; _loadPromise: Promise<Config> | undefined;
@ -57,9 +63,10 @@ export class Config {
fromJson = (json: { [key: string]: any }) => { fromJson = (json: { [key: string]: any }) => {
for (const key of Object.keys(json)) { for (const key of Object.keys(json)) {
if (!Object.hasOwn(this, key)) { 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];
} }
}; };