change own contact when name setting changes

This commit is contained in:
marlon-erler
2026-09-27 03:05:01 +02:00
parent a9fba4646d
commit fc5486a0f7
2 changed files with 49 additions and 51 deletions
+47 -49
View File
@@ -1,9 +1,8 @@
import StorageModel, { StorageModelSubPaths, filePaths } from "./storageModel"; import StorageModel, { StorageModelSubPaths, filePaths } from "./storageModel";
import { UUID } from "../../react"; import { UUID } from "../../react";
import ContactListModel from "./contactListModel";
export default class SettingsModel { export default class SettingsModel {
readonly storageModel: StorageModel;
// data // data
username: string = ""; username: string = "";
userid: string = ""; userid: string = "";
@@ -30,95 +29,94 @@ export default class SettingsModel {
readonly setName = (newValue: string): void => { readonly setName = (newValue: string): void => {
this.username = newValue; this.username = newValue;
this.storeSetting("username", newValue); this.storeSetting("username", newValue);
this.contactListModel.storeContact(this.userid,newValue);
}; };
readonly setFirstDayOfWeek = (newValue: string): void => { readonly setFirstDayOfWeek = (newValue: string): void => {
this.firstDayOfWeek = newValue; this.firstDayOfWeek = newValue;
this.storeSetting("firstDayOfWeek", newValue); this.storeSetting("firstDayOfWeek", newValue);
}; };
readonly setLanguage = (newValue: string): void => { readonly setLanguage = (newValue: string): void => {
this.language = newValue; this.language = newValue;
this.storeSetting("language", newValue); this.storeSetting("language", newValue);
}; };
readonly setTheme = (newValue: string): void => { readonly setTheme = (newValue: string): void => {
this.theme = newValue; this.theme = newValue;
this.storeSetting("theme", newValue); this.storeSetting("theme", newValue);
}; };
// load // load
private readonly readSetting = ( private readonly readSetting = (
pathName: keyof typeof filePaths.settingsModel, pathName: keyof typeof filePaths.settingsModel,
): string | null => { ): string | null => {
const path = StorageModel.getPath( const path = StorageModel.getPath(
StorageModelSubPaths.SettingsModel, StorageModelSubPaths.SettingsModel,
filePaths.settingsModel[pathName], filePaths.settingsModel[pathName],
); );
return this.storageModel.read(path); return this.storageModel.read(path);
}; };
readonly loadId = (): void => { readonly loadId = (): void => {
const content: string | null = this.readSetting("userid"); const content: string | null = this.readSetting("userid");
const id = content ?? UUID(); const id = content ?? UUID();
if (content) this.userid = content; if (content) this.userid = content;
else this.setId(id); else this.setId(id);
}; };
readonly loadUsername = (): void => { readonly loadUsername = (): void => {
const content: string | null = this.readSetting("username"); const content: string | null = this.readSetting("username");
this.username = content ?? ""; this.username = content ?? "";
}; };
readonly loadFirstDayofWeek = (): void => { readonly loadFirstDayofWeek = (): void => {
const content: string | null = this.readSetting("firstDayOfWeek"); const content: string | null = this.readSetting("firstDayOfWeek");
this.firstDayOfWeek = content ?? "0"; this.firstDayOfWeek = content ?? "0";
}; };
readonly loadLanguage = (): void => { readonly loadLanguage = (): void => {
const content: string | null = this.readSetting("language"); const content: string | null = this.readSetting("language");
this.language = content ?? SettingsModel.getSystemLanguage(); this.language = content ?? SettingsModel.getSystemLanguage();
}; };
readonly loadTheme = (): void => { readonly loadTheme = (): void => {
const content: string | null = this.readSetting("theme"); const content: string | null = this.readSetting("theme");
this.theme = content ?? ThemeSettings.System; this.theme = content ?? ThemeSettings.System;
}; };
// init // init
constructor(storageModel: StorageModel) { constructor(public storageModel: StorageModel, public contactListModel: ContactListModel) {
this.storageModel = storageModel; this.loadId();
this.loadUsername();
this.loadId(); this.loadFirstDayofWeek();
this.loadUsername(); this.loadLanguage();
this.loadFirstDayofWeek(); this.loadTheme();
this.loadLanguage();
this.loadTheme();
} }
static getSystemLanguage(): Languages { static getSystemLanguage(): Languages {
switch (navigator.language.substring(0, 2)) { switch (navigator.language.substring(0, 2)) {
case "de": case "de":
return Languages.German; return Languages.German;
case "es": case "es":
return Languages.Spanish; return Languages.Spanish;
default: default:
return Languages.English; return Languages.English;
} }
} }
} }
export enum Languages { export enum Languages {
English = "en", English = "en",
German = "de", German = "de",
Spanish = "es", Spanish = "es",
} }
export enum ThemeSettings { export enum ThemeSettings {
Dark = "dark", Dark = "dark",
Light = "light", Light = "light",
System = "system", System = "system",
Dynamic = "dynamic", Dynamic = "dynamic",
Black = "black", Black = "black",
} }
+2 -2
View File
@@ -25,8 +25,8 @@ import ContactListViewModel from "./ViewModel/Global/contactViewModel";
// models // models
const storageModel = new StorageModel(); const storageModel = new StorageModel();
const settingsModel = new SettingsModel(storageModel);
const contactListModel = new ContactListModel(storageModel); const contactListModel = new ContactListModel(storageModel);
const settingsModel = new SettingsModel(storageModel, contactListModel);
const connectionModel = new ConnectionModel(storageModel); const connectionModel = new ConnectionModel(storageModel);
const chatListModel = new ChatListModel( const chatListModel = new ChatListModel(
storageModel, storageModel,
@@ -46,8 +46,8 @@ const coreViewModel = new CoreViewModel(
); );
const storageViewModel = new StorageViewModel(coreViewModel); const storageViewModel = new StorageViewModel(coreViewModel);
const settingsViewModel = new SettingsViewModel(coreViewModel, settingsModel);
const contactListViewModel = new ContactListViewModel(contactListModel); const contactListViewModel = new ContactListViewModel(contactListModel);
const settingsViewModel = new SettingsViewModel(coreViewModel, settingsModel);
const connectionViewModel = new ConnectionViewModel(coreViewModel); const connectionViewModel = new ConnectionViewModel(coreViewModel);
const chatListViewModel = new ChatListViewModel( const chatListViewModel = new ChatListViewModel(
coreViewModel, coreViewModel,