implement contacts model and vm with chat model
This commit is contained in:
@@ -9,13 +9,9 @@ import StorageModel, {
|
|||||||
} from "../Global/storageModel";
|
} from "../Global/storageModel";
|
||||||
import SettingsModel from "../Global/settingsModel";
|
import SettingsModel from "../Global/settingsModel";
|
||||||
import ConnectionModel from "../Global/connectionModel";
|
import ConnectionModel from "../Global/connectionModel";
|
||||||
|
import ContactListModel from "../Global/contactListModel";
|
||||||
|
|
||||||
export default class ChatListModel {
|
export default class ChatListModel {
|
||||||
// models
|
|
||||||
readonly storageModel: StorageModel;
|
|
||||||
readonly settingsModel: SettingsModel;
|
|
||||||
readonly connectionModel: ConnectionModel;
|
|
||||||
|
|
||||||
// data
|
// data
|
||||||
readonly chatModels = new Set<ChatModel>();
|
readonly chatModels = new Set<ChatModel>();
|
||||||
|
|
||||||
@@ -32,6 +28,7 @@ export default class ChatListModel {
|
|||||||
this.connectionModel,
|
this.connectionModel,
|
||||||
this.settingsModel,
|
this.settingsModel,
|
||||||
this,
|
this,
|
||||||
|
this.contactListModel,
|
||||||
id,
|
id,
|
||||||
);
|
);
|
||||||
chatModel.setName(primaryChannel);
|
chatModel.setName(primaryChannel);
|
||||||
@@ -93,6 +90,7 @@ export default class ChatListModel {
|
|||||||
this.connectionModel,
|
this.connectionModel,
|
||||||
this.settingsModel,
|
this.settingsModel,
|
||||||
this,
|
this,
|
||||||
|
this.contactListModel,
|
||||||
chatId,
|
chatId,
|
||||||
);
|
);
|
||||||
this.addChatModel(chatModel);
|
this.addChatModel(chatModel);
|
||||||
@@ -101,20 +99,18 @@ export default class ChatListModel {
|
|||||||
|
|
||||||
// init
|
// init
|
||||||
constructor(
|
constructor(
|
||||||
storageModel: StorageModel,
|
public storageModel: StorageModel,
|
||||||
settingsModel: SettingsModel,
|
public settingsModel: SettingsModel,
|
||||||
connectionModel: ConnectionModel,
|
public connectionModel: ConnectionModel,
|
||||||
|
public contactListModel: ContactListModel
|
||||||
) {
|
) {
|
||||||
this.storageModel = storageModel;
|
|
||||||
this.settingsModel = settingsModel;
|
|
||||||
this.connectionModel = connectionModel;
|
|
||||||
this.loadChats();
|
this.loadChats();
|
||||||
|
|
||||||
connectionModel.messageHandlerManager.setHandler(
|
this.connectionModel.messageHandlerManager.setHandler(
|
||||||
"chat-list",
|
"chat-list",
|
||||||
this.messageHandler,
|
this.messageHandler,
|
||||||
);
|
);
|
||||||
connectionModel.messageSentHandlerManager.setHandler(
|
this.connectionModel.messageSentHandlerManager.setHandler(
|
||||||
"chat-list",
|
"chat-list",
|
||||||
this.messageSentHandler,
|
this.messageSentHandler,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// cleanup: Phase A
|
|
||||||
|
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
import ChatListModel from "./chatListModel";
|
import ChatListModel from "./chatListModel";
|
||||||
import {
|
import {
|
||||||
@@ -23,13 +21,10 @@ import SettingsModel from "../Global/settingsModel";
|
|||||||
import ConnectionModel from "../Global/connectionModel";
|
import ConnectionModel from "../Global/connectionModel";
|
||||||
import FileModel, { FileContent } from "../Files/fileModel";
|
import FileModel, { FileContent } from "../Files/fileModel";
|
||||||
import { Colors } from "../../colors";
|
import { Colors } from "../../colors";
|
||||||
|
import ContactListModel from "../Global/contactListModel";
|
||||||
|
|
||||||
export default class ChatModel {
|
export default class ChatModel {
|
||||||
// models
|
// models
|
||||||
readonly connectionModel: ConnectionModel;
|
|
||||||
readonly storageModel: StorageModel;
|
|
||||||
readonly settingsModel: SettingsModel;
|
|
||||||
readonly chatListModel: ChatListModel;
|
|
||||||
readonly fileModel: FileModel;
|
readonly fileModel: FileModel;
|
||||||
|
|
||||||
// data
|
// data
|
||||||
@@ -167,6 +162,8 @@ export default class ChatModel {
|
|||||||
readonly addMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
readonly addMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
||||||
await this.decryptMessage(chatMessage);
|
await this.decryptMessage(chatMessage);
|
||||||
|
|
||||||
|
this.contactListModel.storeContact(chatMessage.senderId, chatMessage.senderName);
|
||||||
|
|
||||||
// message
|
// message
|
||||||
if (chatMessage.body != "") {
|
if (chatMessage.body != "") {
|
||||||
const messagePath: string[] = this.getMessagePath(chatMessage.id);
|
const messagePath: string[] = this.getMessagePath(chatMessage.id);
|
||||||
@@ -349,17 +346,14 @@ export default class ChatModel {
|
|||||||
|
|
||||||
// init
|
// init
|
||||||
constructor(
|
constructor(
|
||||||
storageModel: StorageModel,
|
public storageModel: StorageModel,
|
||||||
connectionModel: ConnectionModel,
|
public connectionModel: ConnectionModel,
|
||||||
settingsModel: SettingsModel,
|
public settingsModel: SettingsModel,
|
||||||
chatListModel: ChatListModel,
|
public chatListModel: ChatListModel,
|
||||||
|
public contactListModel: ContactListModel,
|
||||||
chatId: string,
|
chatId: string,
|
||||||
) {
|
) {
|
||||||
this.id = chatId;
|
this.id = chatId;
|
||||||
this.connectionModel = connectionModel;
|
|
||||||
this.settingsModel = settingsModel;
|
|
||||||
this.storageModel = storageModel;
|
|
||||||
this.chatListModel = chatListModel;
|
|
||||||
|
|
||||||
this.loadInfo();
|
this.loadInfo();
|
||||||
this.subscribe();
|
this.subscribe();
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import {HandlerManager} from "../Utility/utility";
|
||||||
import StorageModel, {StorageModelSubPaths} from "./storageModel";
|
import StorageModel, {StorageModelSubPaths} from "./storageModel";
|
||||||
|
|
||||||
export default class ContactListModel {
|
export default class ContactListModel {
|
||||||
|
contactHandlerManager = new HandlerManager<[string, string]>();
|
||||||
|
|
||||||
private getContactPath = (contactId: string): string[] => {
|
private getContactPath = (contactId: string): string[] => {
|
||||||
return [StorageModelSubPaths.ContactsModel, contactId];
|
return [StorageModelSubPaths.ContactsModel, contactId];
|
||||||
}
|
}
|
||||||
@@ -14,6 +17,7 @@ export default class ContactListModel {
|
|||||||
storeContact = (id: string, name: string) => {
|
storeContact = (id: string, name: string) => {
|
||||||
const path = this.getContactPath(id);
|
const path = this.getContactPath(id);
|
||||||
this.storageModel.write(path, name)
|
this.storageModel.write(path, name)
|
||||||
|
this.contactHandlerManager.trigger([id, name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(public storageModel: StorageModel) {}
|
constructor(public storageModel: StorageModel) {}
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ export default class ContactListViewModel {
|
|||||||
}
|
}
|
||||||
const vm = new ContactViewModel(id, name);
|
const vm = new ContactViewModel(id, name);
|
||||||
this.contacts.set(id, vm);
|
this.contacts.set(id, vm);
|
||||||
this.contactListModel.storeContact(id, name);
|
}
|
||||||
|
|
||||||
|
handleContact = (contact: [string, string]): void => {
|
||||||
|
this.updateContact(...contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load
|
// load
|
||||||
@@ -28,6 +31,7 @@ export default class ContactListViewModel {
|
|||||||
// init
|
// init
|
||||||
constructor(public contactListModel: ContactListModel) {
|
constructor(public contactListModel: ContactListModel) {
|
||||||
this.loadData();
|
this.loadData();
|
||||||
|
this.contactListModel.contactHandlerManager.setHandler("contact-list-view-model", this.handleContact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,19 @@ import SettingsModel from "./Model/Global/settingsModel";
|
|||||||
import FileTransferModel from "./Model/Global/fileTransferModel";
|
import FileTransferModel from "./Model/Global/fileTransferModel";
|
||||||
import ConnectionModel from "./Model/Global/connectionModel";
|
import ConnectionModel from "./Model/Global/connectionModel";
|
||||||
import ChatListModel from "./Model/Chat/chatListModel";
|
import ChatListModel from "./Model/Chat/chatListModel";
|
||||||
|
import ContactListModel from "./Model/Global/contactListModel";
|
||||||
|
import ContactListViewModel from "./ViewModel/Global/contactViewModel";
|
||||||
|
|
||||||
// models
|
// models
|
||||||
const storageModel = new StorageModel();
|
const storageModel = new StorageModel();
|
||||||
const settingsModel = new SettingsModel(storageModel);
|
const settingsModel = new SettingsModel(storageModel);
|
||||||
|
const contactListModel = new ContactListModel(storageModel);
|
||||||
const connectionModel = new ConnectionModel(storageModel);
|
const connectionModel = new ConnectionModel(storageModel);
|
||||||
const chatListModel = new ChatListModel(
|
const chatListModel = new ChatListModel(
|
||||||
storageModel,
|
storageModel,
|
||||||
settingsModel,
|
settingsModel,
|
||||||
connectionModel,
|
connectionModel,
|
||||||
|
contactListModel,
|
||||||
);
|
);
|
||||||
const fileTransferModel = new FileTransferModel(storageModel, connectionModel);
|
const fileTransferModel = new FileTransferModel(storageModel, connectionModel);
|
||||||
|
|
||||||
@@ -43,6 +47,7 @@ const coreViewModel = new CoreViewModel(
|
|||||||
|
|
||||||
const storageViewModel = new StorageViewModel(coreViewModel);
|
const storageViewModel = new StorageViewModel(coreViewModel);
|
||||||
const settingsViewModel = new SettingsViewModel(coreViewModel);
|
const settingsViewModel = new SettingsViewModel(coreViewModel);
|
||||||
|
const contactListViewModel = new ContactListViewModel(contactListModel);
|
||||||
const connectionViewModel = new ConnectionViewModel(coreViewModel);
|
const connectionViewModel = new ConnectionViewModel(coreViewModel);
|
||||||
const chatListViewModel = new ChatListViewModel(
|
const chatListViewModel = new ChatListViewModel(
|
||||||
coreViewModel,
|
coreViewModel,
|
||||||
|
|||||||
Reference in New Issue
Block a user