move name to settings modal

This commit is contained in:
marlon-erler
2026-09-28 15:21:50 +02:00
parent 0afbfc2d0b
commit 22acf7f7d8
22 changed files with 743 additions and 589 deletions
+4 -4
View File
@@ -8,8 +8,8 @@ import StorageModel, {
filePaths,
} from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel";
import ConnectionModel from "../Global/connectionModel";
import ContactListModel from "../Global/contactListModel";
import ConnectionModel from "../Global/connectionModel";
export default class ChatListModel {
// data
@@ -28,7 +28,7 @@ export default class ChatListModel {
this.connectionModel,
this.settingsModel,
this,
this.contactListModel,
this.contactListModel,
id,
);
chatModel.setName(primaryChannel);
@@ -90,7 +90,7 @@ export default class ChatListModel {
this.connectionModel,
this.settingsModel,
this,
this.contactListModel,
this.contactListModel,
chatId,
);
this.addChatModel(chatModel);
@@ -102,7 +102,7 @@ export default class ChatListModel {
public storageModel: StorageModel,
public settingsModel: SettingsModel,
public connectionModel: ConnectionModel,
public contactListModel: ContactListModel
public contactListModel: ContactListModel,
) {
this.loadChats();
+15 -11
View File
@@ -18,10 +18,10 @@ import StorageModel, {
filePaths,
} from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel";
import ContactListModel from "../Global/contactListModel";
import ConnectionModel from "../Global/connectionModel";
import FileModel, { FileContent } from "../Files/fileModel";
import { Colors } from "../../colors";
import ContactListModel from "../Global/contactListModel";
export default class ChatModel {
// models
@@ -162,11 +162,16 @@ export default class ChatModel {
readonly addMessage = async (chatMessage: ChatMessage): Promise<void> => {
await this.decryptMessage(chatMessage);
this.contactListModel.storeContact(chatMessage.senderId, chatMessage.senderName);
this.contactListModel.storeContact(
chatMessage.senderId,
chatMessage.senderName,
);
// message
if (chatMessage.body != "") {
const messagePath: string[] = this.getMessagePath(chatMessage.fileId);
const messagePath: string[] = this.getMessagePath(
chatMessage.fileId,
);
this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandlerManager.trigger(chatMessage);
}
@@ -238,7 +243,7 @@ export default class ChatModel {
const reaction = ChatModel.createMessageReaction(
messageId,
senderId,
senderName,
senderName,
content,
isDeleting,
);
@@ -350,7 +355,7 @@ export default class ChatModel {
public connectionModel: ConnectionModel,
public settingsModel: SettingsModel,
public chatListModel: ChatListModel,
public contactListModel: ContactListModel,
public contactListModel: ContactListModel,
chatId: string,
) {
this.id = chatId;
@@ -397,10 +402,10 @@ export default class ChatModel {
inlineReplyId?: string,
fileContent?: FileContent<string>,
): Promise<ChatMessage> => {
const messageFileContent = FileModel.createFileContent(v4(), "message");
const messageFileContent = FileModel.createFileContent(v4(), "message");
const chatMessage: ChatMessage = {
...messageFileContent,
...messageFileContent,
channel,
senderName,
@@ -446,7 +451,7 @@ export default class ChatModel {
messageId,
senderId,
senderName,
senderName,
content,
isDeleting,
};
@@ -501,8 +506,7 @@ export interface ChatMessage extends FileContent<"message"> {
stringifiedFile: string;
}
export interface ChatMessageReaction
extends FileContent<"reaction"> {
export interface ChatMessageReaction extends FileContent<"reaction"> {
readonly messageId: string;
readonly senderId: string;
readonly senderName: string;
@@ -531,7 +535,7 @@ export const ChatInfoReference: ChatInfoFileContent = {
export const ChatMessageReference: ChatMessage = {
dataVersion: DATA_VERSION,
fileId: "",
fileContentId: "",
creationDate: "",
+8 -2
View File
@@ -149,12 +149,18 @@ export default class ConnectionModel {
};
readonly addToOutbox = (chatMessage: ChatMessage): void => {
const messagePath: string[] = [...this.getOutboxPath(), chatMessage.fileId];
const messagePath: string[] = [
...this.getOutboxPath(),
chatMessage.fileId,
];
this.storageModel.writeStringifiable(messagePath, chatMessage);
};
readonly removeFromOutbox = (chatMessage: ChatMessage): void => {
const messagePath: string[] = [...this.getOutboxPath(), chatMessage.fileId];
const messagePath: string[] = [
...this.getOutboxPath(),
chatMessage.fileId,
];
this.storageModel.remove(messagePath);
};
+25 -15
View File
@@ -1,28 +1,38 @@
import {HandlerManager} from "../Utility/utility";
import StorageModel, { StorageModelSubPaths } from "./storageModel";
import SettingsModel from "./settingsModel";
import StorageModel, {StorageModelSubPaths} from "./storageModel";
import { HandlerManager } from "../Utility/utility";
export default class ContactListModel {
contactHandlerManager = new HandlerManager<[string, string]>();
private getContactPath = (contactId: string): string[] => {
return StorageModel.getPath(StorageModelSubPaths.ContactsModel, [contactId]);
}
return StorageModel.getPath(StorageModelSubPaths.ContactsModel, [
contactId,
]);
};
loadContacts = (): [string, string][] => {
const contactIds: string[] = this.storageModel.list([StorageModelSubPaths.ContactsModel]);
const contacts: [string, string][] = contactIds.map(id => [id, this.storageModel.read(this.getContactPath(id)) ?? "?"]);
contacts.push([this.settingsModel.userid, this.settingsModel.username]);
return contacts;
}
const contactIds: string[] = this.storageModel.list([
StorageModelSubPaths.ContactsModel,
]);
const contacts: [string, string][] = contactIds.map((id) => [
id,
this.storageModel.read(this.getContactPath(id)) ?? "?",
]);
contacts.push([this.settingsModel.userid, this.settingsModel.username]);
return contacts;
};
storeContact = (id: string, name: string) => {
this.contactHandlerManager.trigger([id, name]);
this.contactHandlerManager.trigger([id, name]);
if (id == this.settingsModel.userid) return;
const path = this.getContactPath(id);
this.storageModel.write(path, name)
}
if (id == this.settingsModel.userid) return;
const path = this.getContactPath(id);
this.storageModel.write(path, name);
};
constructor(public storageModel: StorageModel, public settingsModel: SettingsModel) {}
constructor(
public storageModel: StorageModel,
public settingsModel: SettingsModel,
) {}
}
+44 -44
View File
@@ -28,93 +28,93 @@ export default class SettingsModel {
readonly setName = (newValue: string): void => {
this.username = newValue;
this.storeSetting("username", newValue);
this.storeSetting("username", newValue);
};
readonly setFirstDayOfWeek = (newValue: string): void => {
this.firstDayOfWeek = newValue;
this.storeSetting("firstDayOfWeek", newValue);
this.firstDayOfWeek = newValue;
this.storeSetting("firstDayOfWeek", newValue);
};
readonly setLanguage = (newValue: string): void => {
this.language = newValue;
this.storeSetting("language", newValue);
this.language = newValue;
this.storeSetting("language", newValue);
};
readonly setTheme = (newValue: string): void => {
this.theme = newValue;
this.storeSetting("theme", newValue);
this.theme = newValue;
this.storeSetting("theme", newValue);
};
// load
private readonly readSetting = (
pathName: keyof typeof filePaths.settingsModel,
pathName: keyof typeof filePaths.settingsModel,
): string | null => {
const path = StorageModel.getPath(
StorageModelSubPaths.SettingsModel,
filePaths.settingsModel[pathName],
);
return this.storageModel.read(path);
const path = StorageModel.getPath(
StorageModelSubPaths.SettingsModel,
filePaths.settingsModel[pathName],
);
return this.storageModel.read(path);
};
readonly loadId = (): void => {
const content: string | null = this.readSetting("userid");
const id = content ?? UUID();
if (content) this.userid = content;
else this.setId(id);
const content: string | null = this.readSetting("userid");
const id = content ?? UUID();
if (content) this.userid = content;
else this.setId(id);
};
readonly loadUsername = (): void => {
const content: string | null = this.readSetting("username");
this.username = content ?? "";
const content: string | null = this.readSetting("username");
this.username = content ?? "";
};
readonly loadFirstDayofWeek = (): void => {
const content: string | null = this.readSetting("firstDayOfWeek");
this.firstDayOfWeek = content ?? "0";
const content: string | null = this.readSetting("firstDayOfWeek");
this.firstDayOfWeek = content ?? "0";
};
readonly loadLanguage = (): void => {
const content: string | null = this.readSetting("language");
this.language = content ?? SettingsModel.getSystemLanguage();
const content: string | null = this.readSetting("language");
this.language = content ?? SettingsModel.getSystemLanguage();
};
readonly loadTheme = (): void => {
const content: string | null = this.readSetting("theme");
this.theme = content ?? ThemeSettings.System;
const content: string | null = this.readSetting("theme");
this.theme = content ?? ThemeSettings.System;
};
// init
constructor(public storageModel: StorageModel) {
this.loadId();
this.loadUsername();
this.loadFirstDayofWeek();
this.loadLanguage();
this.loadTheme();
this.loadId();
this.loadUsername();
this.loadFirstDayofWeek();
this.loadLanguage();
this.loadTheme();
}
static getSystemLanguage(): Languages {
switch (navigator.language.substring(0, 2)) {
case "de":
return Languages.German;
case "es":
return Languages.Spanish;
default:
return Languages.English;
}
switch (navigator.language.substring(0, 2)) {
case "de":
return Languages.German;
case "es":
return Languages.Spanish;
default:
return Languages.English;
}
}
}
export enum Languages {
English = "en",
German = "de",
Spanish = "es",
German = "de",
Spanish = "es",
}
export enum ThemeSettings {
Dark = "dark",
Light = "light",
System = "system",
Dynamic = "dynamic",
Black = "black",
Light = "light",
System = "system",
Dynamic = "dynamic",
Black = "black",
}
+55 -55
View File
@@ -216,52 +216,52 @@ export default class StorageModel {
return stringify(this.storageEntryTree);
};
// upgrade
// upgrade
readonly upgrade = (): void => {
// function used to upgrade data versions
}
// function used to upgrade data versions
};
// init
constructor() {
this.initializeTree();
this.upgrade();
this.initializeTree();
this.upgrade();
}
// utility
static getFileName = (pathComponents: string[]): string => {
return pathComponents[pathComponents.length - 1] || "\\";
return pathComponents[pathComponents.length - 1] || "\\";
};
static getFileNameFromString = (pathString: string): string => {
const pathComponents: string[] =
this.stringToPathComponents(pathString);
return pathComponents[pathComponents.length - 1] || "\\";
const pathComponents: string[] =
this.stringToPathComponents(pathString);
return pathComponents[pathComponents.length - 1] || "\\";
};
static pathComponentsToString = (...pathComponents: string[]): string => {
return pathComponents
.filter((x) => x != "")
.join(PATH_COMPONENT_SEPARATOR);
return pathComponents
.filter((x) => x != "")
.join(PATH_COMPONENT_SEPARATOR);
};
static stringToPathComponents = (string: string): string[] => {
return string.split(PATH_COMPONENT_SEPARATOR).filter((x) => x != "");
return string.split(PATH_COMPONENT_SEPARATOR).filter((x) => x != "");
};
static join = (...items: string[]): string => {
let allComponents: string[] = [];
for (const item of items) {
const parts = this.stringToPathComponents(item);
allComponents.push(...parts);
}
return StorageModel.pathComponentsToString(...allComponents);
let allComponents: string[] = [];
for (const item of items) {
const parts = this.stringToPathComponents(item);
allComponents.push(...parts);
}
return StorageModel.pathComponentsToString(...allComponents);
};
static getPath(
locationName: StorageModelSubPaths,
filePath: string[],
locationName: StorageModelSubPaths,
filePath: string[],
): string[] {
return [DATA_VERSION, locationName, ...filePath];
return [DATA_VERSION, locationName, ...filePath];
}
}
@@ -272,52 +272,52 @@ export type StorageEntry = { [key: string]: StorageEntry };
export enum StorageModelSubPaths {
Chat = "chat",
ConnectionModel = "connection",
NotificationModel = "notifications",
SettingsModel = "settings",
ContactsModel = "contacts",
ConnectionModel = "connection",
NotificationModel = "notifications",
SettingsModel = "settings",
ContactsModel = "contacts",
}
export const filePaths = {
connectionModel: {
socketAddress: ["socket-address"],
reconnectAddress: ["reconnect-address"],
outbox: ["outbox"],
mailboxes: ["mailboxes"],
socketAddress: ["socket-address"],
reconnectAddress: ["reconnect-address"],
outbox: ["outbox"],
mailboxes: ["mailboxes"],
previousAddresses: ["previous-addresses"],
previousAddresses: ["previous-addresses"],
},
chat: {
base: [],
chatBase: (id: string) => [id],
info: (id: string) => [...filePaths.chat.chatBase(id), "info"],
color: (id: string) => [...filePaths.chat.chatBase(id), "color"],
messages: (id: string) => [...filePaths.chat.chatBase(id), "messages"],
reactions: (id: string) => [
...filePaths.chat.chatBase(id),
"reactions",
],
previousFilter: (id: string) => [
...filePaths.chat.chatBase(id),
"previous-filter",
],
lastUsedPage: (id: string) => [
...filePaths.chat.chatBase(id),
"last-used-page",
],
files: (id: string) => [...filePaths.chat.chatBase(id), "files"],
base: [],
chatBase: (id: string) => [id],
info: (id: string) => [...filePaths.chat.chatBase(id), "info"],
color: (id: string) => [...filePaths.chat.chatBase(id), "color"],
messages: (id: string) => [...filePaths.chat.chatBase(id), "messages"],
reactions: (id: string) => [
...filePaths.chat.chatBase(id),
"reactions",
],
previousFilter: (id: string) => [
...filePaths.chat.chatBase(id),
"previous-filter",
],
lastUsedPage: (id: string) => [
...filePaths.chat.chatBase(id),
"last-used-page",
],
files: (id: string) => [...filePaths.chat.chatBase(id), "files"],
},
notificationModel: {
base: [],
base: [],
},
settingsModel: {
username: ["user-name"],
userid: ["user-id"],
firstDayOfWeek: ["first-day-of-week"],
language: ["language"],
theme: ["theme"],
username: ["user-name"],
userid: ["user-id"],
firstDayOfWeek: ["first-day-of-week"],
language: ["language"],
theme: ["theme"],
},
};