improve centralization of models

This commit is contained in:
marlon-erler
2024-07-20 20:42:43 +02:00
parent bdbd2ac8b6
commit 995f82f3ef
11 changed files with 240 additions and 125 deletions
+23 -2
View File
@@ -4,21 +4,33 @@ import StorageModel, { storageKeys } from "./storageModel";
import ChatListModel from "./chatListModel";
import { Color } from "../ViewModel/colors";
import ConnectionModel from "./connectionModel";
import SettingsModel from "./settingsModel";
import { checkIsValidObject } from "./Utility/typeSafety";
import { createTimestamp } from "./Utility/utility";
import { v4 } from "uuid";
export class ChatModel {
connectionModel: ConnectionModel;
storageModel: StorageModel;
settingsModel: SettingsModel;
chatListModel: ChatListModel;
// data
id: string;
storageModel: StorageModel;
chatListModel: ChatListModel;
info: ChatInfo;
color: Color;
messages = new Set<ChatMessage>();
objects = new Map<string, ChatObject>();
// sorting
get index(): number {
return this.chatListModel.getIndexOfPrimaryChannel(
this.info.primaryChannel
);
}
// paths
get infoPath(): string[] {
return storageKeys.chatInfo(this.id);
@@ -148,6 +160,11 @@ export class ChatModel {
}
};
// messaging
sendMessage = (body: string): void => {
//TODO
};
// memory
loadData = (): void => {
this.restoreMessages();
@@ -162,10 +179,14 @@ export class ChatModel {
// init
constructor(
storageModel: StorageModel,
connectionModel: ConnectionModel,
settingsModel: SettingsModel,
chatListModel: ChatListModel,
chatId: string
) {
this.id = chatId;
this.connectionModel = connectionModel;
this.settingsModel = settingsModel;
this.storageModel = storageModel;
this.chatListModel = chatListModel;