implement contacts with messaging
This commit is contained in:
@@ -3,22 +3,30 @@ import * as React from "../../react";
|
||||
|
||||
export default class ContactListViewModel {
|
||||
// state
|
||||
contacts: React.MapState<ContactViewModel> = new React.MapState();
|
||||
contacts: Map<string, ContactViewModel> = new Map();
|
||||
|
||||
// main
|
||||
updateContact = (id: string, name: string): void => {
|
||||
if (this.contacts.value.has(id)) {
|
||||
this.contacts.value.get(id)!.name.value = name;
|
||||
return;
|
||||
updateContact = (id: string, name: string): ContactViewModel => {
|
||||
const match = this.contacts.get(id);
|
||||
if (match) {
|
||||
match.name.value = name;
|
||||
return match;
|
||||
}
|
||||
const vm = new ContactViewModel(id, name);
|
||||
this.contacts.set(id, vm);
|
||||
return vm;
|
||||
}
|
||||
|
||||
handleContact = (contact: [string, string]): void => {
|
||||
this.updateContact(...contact);
|
||||
}
|
||||
|
||||
unwrapContact = (id: string, knownName: string): ContactViewModel => {
|
||||
if (this.contacts.has(id))
|
||||
return this.contacts.get(id)!
|
||||
return this.updateContact(id, knownName);
|
||||
}
|
||||
|
||||
// load
|
||||
loadData = (): void => {
|
||||
const contacts: [string, string][] = this.contactListModel.loadContacts();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import CoreViewModel, { Context } from "./coreViewModel";
|
||||
import * as React from "../../react";
|
||||
import { CommonKeys } from "../../View/keystrokes";
|
||||
import { Languages, ThemeSettings } from "../../Model/Global/settingsModel";
|
||||
import SettingsModel, { Languages, ThemeSettings } from "../../Model/Global/settingsModel";
|
||||
|
||||
export default class SettingsViewModel extends Context {
|
||||
// state
|
||||
@@ -126,7 +126,7 @@ export default class SettingsViewModel extends Context {
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(public readonly coreViewModel: CoreViewModel) {
|
||||
constructor(public readonly coreViewModel: CoreViewModel, public readonly settingsModel: SettingsModel) {
|
||||
super("settings");
|
||||
|
||||
this.username.value = coreViewModel.settingsModel.username;
|
||||
|
||||
Reference in New Issue
Block a user