finish chat so far

This commit is contained in:
marlon-erler
2024-07-09 17:23:29 +02:00
parent dae32fa6e7
commit 1f482dd35d
12 changed files with 657 additions and 548 deletions
+17 -3
View File
@@ -1,6 +1,6 @@
import * as React from "bloatless-react";
import { Chat, chats, createChatWithName } from "./chatModel";
import { Chat, createChatWithName } from "./chatModel";
import UDNFrontend from "udn-frontend";
@@ -59,6 +59,10 @@ export function resetAddressInput(): void {
// listeners
UDN.onconnect = () => {
isConnected.value = true;
chats.value.forEach((chat) => {
UDN.subscribe(chat.primaryChannel.value);
});
};
UDN.onmessage = (data) => {
@@ -114,9 +118,13 @@ UDN.onmailboxdelete = () => {
};
// MISC
export const isEncryptionUnavailable = window.crypto.subtle == undefined;
export const isEncryptionAvailable = window.crypto.subtle != undefined;
export const senderName = React.restoreState("sender-name", "");
// CHAT
export const chats = new React.ListState<Chat>();
export const chatIds = React.restoreListState<string>("chat-ids");
export const selectedChat = new React.State<Chat | undefined>(undefined);
export const newChatName = new React.State("");
@@ -127,7 +135,7 @@ export const cannotCreateChat = React.createProxyState(
export function createChat() {
if (cannotCreateChat.value == true) return;
createChatWithName(newChatName.value);
newChatName.value = "";
}
@@ -137,6 +145,12 @@ export function closeChatView() {
document.getElementById("settings-tab")?.scrollIntoView();
}
export function selectChat(chat: Chat) {
selectedChat.value = chat;
}
chatIds.value.forEach((id) => chats.add(new Chat(id)));
// INIT
if (serverAddressInput.value != "" && didRequestConnection.value == true) {
connect();