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);
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 {

View file

@ -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<Config> | 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];
}
};