add navigation for chat page

This commit is contained in:
marlon-erler
2024-07-20 14:16:26 +02:00
parent 6b269719a1
commit c4aa95d427
13 changed files with 260 additions and 57 deletions
+2 -7
View File
@@ -17,18 +17,13 @@ export default class ChatListModel {
createChat = (primaryChannel: string): ChatModel => {
const id: string = v4();
const chatModel = new ChatModel(this.storageModel, id);
const chatModel = new ChatModel(this.storageModel, this, id);
chatModel.setPrimaryChannel(primaryChannel);
this.addChatModel(chatModel);
return chatModel;
};
deleteChat = (chat: ChatModel): void => {
chat.remove();
this.untrackChat(chat);
};
untrackChat = (chat: ChatModel): void => {
this.chatModels.delete(chat.id);
};
@@ -38,7 +33,7 @@ export default class ChatListModel {
const chatDir = storageKeys.chats;
const chatIds = this.storageModel.list(chatDir);
for (const chatId of chatIds) {
const chatModel = new ChatModel(this.storageModel, chatId);
const chatModel = new ChatModel(this.storageModel, this, chatId);
this.addChatModel(chatModel);
}
};
+10 -3
View File
@@ -2,6 +2,7 @@
import StorageModel, { storageKeys } from "./storageModel";
import ChatListModel from "./chatListModel";
import { checkIsValidObject } from "./Utility/typeSafety";
import { createTimestamp } from "./Utility/utility";
import { v4 } from "uuid";
@@ -10,6 +11,7 @@ export class ChatModel {
// data
id: string;
storageModel: StorageModel;
chatListModel: ChatListModel;
info: ChatInfo;
messages = new Set<ChatMessage>();
@@ -71,9 +73,13 @@ export class ChatModel {
this.storageModel.storeStringifiable(objectPath, object);
};
// remove
remove = () => {
// delete
delete = () => {
// untrack
this.unloadData();
this.chatListModel.untrackChat(this);
// delete
const dirPath = [...storageKeys.chats, this.id];
this.storageModel.removeRecursive(dirPath);
};
@@ -128,9 +134,10 @@ export class ChatModel {
};
// init
constructor(storageModel: StorageModel, chatId: string) {
constructor(storageModel: StorageModel, chatListModel: ChatListModel, chatId: string) {
this.id = chatId;
this.storageModel = storageModel;
this.chatListModel = chatListModel;
this.restoreInfo();
}