implement contacts with messaging

This commit is contained in:
marlon-erler
2026-09-27 03:01:43 +02:00
parent c5d61a5790
commit a9fba4646d
8 changed files with 118 additions and 98 deletions
+13 -5
View File
@@ -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();