implement contacts model and vm with chat model
This commit is contained in:
@@ -9,13 +9,9 @@ import StorageModel, {
|
||||
} from "../Global/storageModel";
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import ConnectionModel from "../Global/connectionModel";
|
||||
import ContactListModel from "../Global/contactListModel";
|
||||
|
||||
export default class ChatListModel {
|
||||
// models
|
||||
readonly storageModel: StorageModel;
|
||||
readonly settingsModel: SettingsModel;
|
||||
readonly connectionModel: ConnectionModel;
|
||||
|
||||
// data
|
||||
readonly chatModels = new Set<ChatModel>();
|
||||
|
||||
@@ -32,6 +28,7 @@ export default class ChatListModel {
|
||||
this.connectionModel,
|
||||
this.settingsModel,
|
||||
this,
|
||||
this.contactListModel,
|
||||
id,
|
||||
);
|
||||
chatModel.setName(primaryChannel);
|
||||
@@ -93,6 +90,7 @@ export default class ChatListModel {
|
||||
this.connectionModel,
|
||||
this.settingsModel,
|
||||
this,
|
||||
this.contactListModel,
|
||||
chatId,
|
||||
);
|
||||
this.addChatModel(chatModel);
|
||||
@@ -101,20 +99,18 @@ export default class ChatListModel {
|
||||
|
||||
// init
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
settingsModel: SettingsModel,
|
||||
connectionModel: ConnectionModel,
|
||||
public storageModel: StorageModel,
|
||||
public settingsModel: SettingsModel,
|
||||
public connectionModel: ConnectionModel,
|
||||
public contactListModel: ContactListModel
|
||||
) {
|
||||
this.storageModel = storageModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.connectionModel = connectionModel;
|
||||
this.loadChats();
|
||||
|
||||
connectionModel.messageHandlerManager.setHandler(
|
||||
this.connectionModel.messageHandlerManager.setHandler(
|
||||
"chat-list",
|
||||
this.messageHandler,
|
||||
);
|
||||
connectionModel.messageSentHandlerManager.setHandler(
|
||||
this.connectionModel.messageSentHandlerManager.setHandler(
|
||||
"chat-list",
|
||||
this.messageSentHandler,
|
||||
);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// cleanup: Phase A
|
||||
|
||||
import { v4 } from "uuid";
|
||||
import ChatListModel from "./chatListModel";
|
||||
import {
|
||||
@@ -23,13 +21,10 @@ import SettingsModel from "../Global/settingsModel";
|
||||
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
|
||||
readonly connectionModel: ConnectionModel;
|
||||
readonly storageModel: StorageModel;
|
||||
readonly settingsModel: SettingsModel;
|
||||
readonly chatListModel: ChatListModel;
|
||||
readonly fileModel: FileModel;
|
||||
|
||||
// data
|
||||
@@ -167,6 +162,8 @@ export default class ChatModel {
|
||||
readonly addMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
||||
await this.decryptMessage(chatMessage);
|
||||
|
||||
this.contactListModel.storeContact(chatMessage.senderId, chatMessage.senderName);
|
||||
|
||||
// message
|
||||
if (chatMessage.body != "") {
|
||||
const messagePath: string[] = this.getMessagePath(chatMessage.id);
|
||||
@@ -349,17 +346,14 @@ export default class ChatModel {
|
||||
|
||||
// init
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
connectionModel: ConnectionModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatListModel: ChatListModel,
|
||||
public storageModel: StorageModel,
|
||||
public connectionModel: ConnectionModel,
|
||||
public settingsModel: SettingsModel,
|
||||
public chatListModel: ChatListModel,
|
||||
public contactListModel: ContactListModel,
|
||||
chatId: string,
|
||||
) {
|
||||
this.id = chatId;
|
||||
this.connectionModel = connectionModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.storageModel = storageModel;
|
||||
this.chatListModel = chatListModel;
|
||||
|
||||
this.loadInfo();
|
||||
this.subscribe();
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {HandlerManager} from "../Utility/utility";
|
||||
import StorageModel, {StorageModelSubPaths} from "./storageModel";
|
||||
|
||||
export default class ContactListModel {
|
||||
contactHandlerManager = new HandlerManager<[string, string]>();
|
||||
|
||||
private getContactPath = (contactId: string): string[] => {
|
||||
return [StorageModelSubPaths.ContactsModel, contactId];
|
||||
}
|
||||
@@ -14,6 +17,7 @@ export default class ContactListModel {
|
||||
storeContact = (id: string, name: string) => {
|
||||
const path = this.getContactPath(id);
|
||||
this.storageModel.write(path, name)
|
||||
this.contactHandlerManager.trigger([id, name]);
|
||||
}
|
||||
|
||||
constructor(public storageModel: StorageModel) {}
|
||||
|
||||
Reference in New Issue
Block a user