This commit is contained in:
marlon-erler
2024-07-22 23:33:57 +02:00
parent ba27c61a29
commit 852acffb7c
10 changed files with 68 additions and 69 deletions
+30 -30
View File
@@ -553,7 +553,7 @@
getTaskReferencePath = (boardId, fileId) => { getTaskReferencePath = (boardId, fileId) => {
return [...this.getTaskContainerPath(boardId), fileId]; return [...this.getTaskContainerPath(boardId), fileId];
}; };
// handler // handlers
handleFileContent = (fileContent) => { handleFileContent = (fileContent) => {
if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) { if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) {
this.handleBoard(fileContent); this.handleBoard(fileContent);
@@ -716,7 +716,7 @@
const filePath = this.getFilePath(fileId); const filePath = this.getFilePath(fileId);
return [...filePath, fileContentId]; return [...filePath, fileContentId];
}; };
// handler // handlers
handleStringifiedFileContent = (stringifiedFileContent) => { handleStringifiedFileContent = (stringifiedFileContent) => {
const fileContent = parseValidObject( const fileContent = parseValidObject(
stringifiedFileContent, stringifiedFileContent,
@@ -916,6 +916,20 @@
getMessagePath = (id) => { getMessagePath = (id) => {
return [...this.getMessageDirPath(), id]; return [...this.getMessageDirPath(), id];
}; };
// handlers
handleMessage = (body) => {
const chatMessage = parseValidObject(
body,
ChatMessageReference
);
if (chatMessage == null) return;
chatMessage.status = "received" /* Received */;
this.addMessage(chatMessage);
};
handleMessageSent = (chatMessage) => {
chatMessage.status = "sent" /* Sent */;
this.addMessage(chatMessage);
};
// sorting // sorting
get index() { get index() {
return this.chatListModel.getIndexOfPrimaryChannel( return this.chatListModel.getIndexOfPrimaryChannel(
@@ -942,6 +956,15 @@
this.storeColor(); this.storeColor();
}; };
// messaging // messaging
addMessage = async (chatMessage) => {
await this.decryptMessage(chatMessage);
if (chatMessage.body != "") {
const messagePath = this.getMessagePath(chatMessage.id);
this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandler(chatMessage);
}
this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile);
};
sendMessage = async (body, fileContent) => { sendMessage = async (body, fileContent) => {
const senderName = this.settingsModel.username; const senderName = this.settingsModel.username;
if (senderName == "") return false; if (senderName == "") return false;
@@ -961,19 +984,6 @@
this.connectionModel.sendMessageOrStore(chatMessage); this.connectionModel.sendMessageOrStore(chatMessage);
return true; return true;
}; };
handleMessage = (body) => {
const chatMessage = parseValidObject(
body,
ChatMessageReference
);
if (chatMessage == null) return;
chatMessage.status = "received" /* Received */;
this.addMessage(chatMessage);
};
handleMessageSent = (chatMessage) => {
chatMessage.status = "sent" /* Sent */;
this.addMessage(chatMessage);
};
decryptMessage = async (chatMessage) => { decryptMessage = async (chatMessage) => {
const decryptedBody = await decryptString( const decryptedBody = await decryptString(
chatMessage.body, chatMessage.body,
@@ -999,15 +1009,6 @@
storeColor = () => { storeColor = () => {
this.storageModel.write(this.getColorPath(), this.color); this.storageModel.write(this.getColorPath(), this.color);
}; };
addMessage = async (chatMessage) => {
await this.decryptMessage(chatMessage);
if (chatMessage.body != "") {
const messagePath = this.getMessagePath(chatMessage.id);
this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandler(chatMessage);
}
this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile);
};
delete = () => { delete = () => {
this.chatListModel.untrackChat(this); this.chatListModel.untrackChat(this);
const dirPath = this.getBasePath(); const dirPath = this.getBasePath();
@@ -1259,7 +1260,6 @@
this.chatMessageViewModels.set(chatMessage.id, chatMessageModel); this.chatMessageViewModels.set(chatMessage.id, chatMessageModel);
} }
}; };
// messaging
sendMessage = () => { sendMessage = () => {
if (this.cannotSendMessage.value == true) return; if (this.cannotSendMessage.value == true) return;
this.sendMessageFromBody(this.composingMessage.value); this.sendMessageFromBody(this.composingMessage.value);
@@ -1357,7 +1357,7 @@
this.chatViewModel.chatListViewModel.loadChats(); this.chatViewModel.chatListViewModel.loadChats();
}; };
// load // load
loadViewRelevantData = () => { loadListRelevantData = () => {
this.primaryChannel.value = this.chatViewModel.chatModel.info.primaryChannel; this.primaryChannel.value = this.chatViewModel.chatModel.info.primaryChannel;
this.color.value = this.chatViewModel.chatModel.color; this.color.value = this.chatViewModel.chatModel.color;
this.cannotSetEncryptionKey = createProxyState( this.cannotSetEncryptionKey = createProxyState(
@@ -1379,7 +1379,7 @@
// init // init
constructor(chatViewModel) { constructor(chatViewModel) {
this.chatViewModel = chatViewModel; this.chatViewModel = chatViewModel;
this.loadViewRelevantData(); this.loadListRelevantData();
} }
}; };
@@ -2426,7 +2426,7 @@
this.connectionModel.removeAddress(address); this.connectionModel.removeAddress(address);
this.updatePreviousAddresses(); this.updatePreviousAddresses();
}; };
// view methods // view
showConnectionModal = () => { showConnectionModal = () => {
this.isShowingConnectionModal.value = true; this.isShowingConnectionModal.value = true;
}; };
@@ -2649,7 +2649,7 @@
[this.usernameInput], [this.usernameInput],
() => this.usernameInput.value == "" || this.usernameInput.value == this.settingsModel.username () => this.usernameInput.value == "" || this.usernameInput.value == this.settingsModel.username
); );
// set // methods
setName = () => { setName = () => {
this.settingsModel.setName(this.usernameInput.value); this.settingsModel.setName(this.usernameInput.value);
this.username.value = this.settingsModel.username; this.username.value = this.settingsModel.username;
@@ -2782,7 +2782,7 @@
this.storageModel.removeRecursively(path); this.storageModel.removeRecursively(path);
this.didMakeChanges.value = true; this.didMakeChanges.value = true;
}; };
// view methods // view
showStorageModal = () => { showStorageModal = () => {
this.isShowingStorageModal.value = true; this.isShowingStorageModal.value = true;
}; };
+31 -30
View File
@@ -57,6 +57,23 @@ export default class ChatModel {
return [...this.getMessageDirPath(), id]; return [...this.getMessageDirPath(), id];
}; };
// handlers
handleMessage = (body: string): void => {
const chatMessage: ChatMessage | null = parseValidObject(
body,
ChatMessageReference
);
if (chatMessage == null) return;
chatMessage.status = ChatMessageStatus.Received;
this.addMessage(chatMessage);
};
handleMessageSent = (chatMessage: ChatMessage): void => {
chatMessage.status = ChatMessageStatus.Sent;
this.addMessage(chatMessage);
};
// sorting // sorting
get index(): number { get index(): number {
return this.chatListModel.getIndexOfPrimaryChannel( return this.chatListModel.getIndexOfPrimaryChannel(
@@ -88,6 +105,20 @@ export default class ChatModel {
}; };
// messaging // messaging
addMessage = async (chatMessage: ChatMessage): Promise<void> => {
await this.decryptMessage(chatMessage);
// message
if (chatMessage.body != "") {
const messagePath: string[] = this.getMessagePath(chatMessage.id);
this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandler(chatMessage);
}
// file
this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile);
};
sendMessage = async ( sendMessage = async (
body: string, body: string,
fileContent?: FileContent<string> fileContent?: FileContent<string>
@@ -115,22 +146,6 @@ export default class ChatModel {
return true; return true;
}; };
handleMessage = (body: string): void => {
const chatMessage: ChatMessage | null = parseValidObject(
body,
ChatMessageReference
);
if (chatMessage == null) return;
chatMessage.status = ChatMessageStatus.Received;
this.addMessage(chatMessage);
};
handleMessageSent = (chatMessage: ChatMessage): void => {
chatMessage.status = ChatMessageStatus.Sent;
this.addMessage(chatMessage);
};
decryptMessage = async (chatMessage: ChatMessage): Promise<void> => { decryptMessage = async (chatMessage: ChatMessage): Promise<void> => {
const decryptedBody: string = await decryptString( const decryptedBody: string = await decryptString(
chatMessage.body, chatMessage.body,
@@ -161,20 +176,6 @@ export default class ChatModel {
this.storageModel.write(this.getColorPath(), this.color); this.storageModel.write(this.getColorPath(), this.color);
}; };
addMessage = async (chatMessage: ChatMessage): Promise<void> => {
await this.decryptMessage(chatMessage);
// message
if (chatMessage.body != "") {
const messagePath: string[] = this.getMessagePath(chatMessage.id);
this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandler(chatMessage);
}
// file
this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile);
};
delete = () => { delete = () => {
// untrack // untrack
this.chatListModel.untrackChat(this); this.chatListModel.untrackChat(this);
+1 -1
View File
@@ -46,7 +46,7 @@ export default class FileModel {
return [...filePath, fileContentId]; return [...filePath, fileContentId];
}; };
// handler // handlers
handleStringifiedFileContent = (stringifiedFileContent: string): void => { handleStringifiedFileContent = (stringifiedFileContent: string): void => {
const fileContent: FileContent<string> | null = parseValidObject( const fileContent: FileContent<string> | null = parseValidObject(
stringifiedFileContent, stringifiedFileContent,
+1 -1
View File
@@ -45,7 +45,7 @@ export default class TaskModel {
return [...this.getTaskContainerPath(boardId), fileId]; return [...this.getTaskContainerPath(boardId), fileId];
}; };
// handler // handlers
handleFileContent = (fileContent: FileContent<string>): void => { handleFileContent = (fileContent: FileContent<string>): void => {
if ( if (
checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
@@ -4,7 +4,6 @@ import * as React from "bloatless-react";
import { ChatMessage, ChatMessageStatus } from "../../Model/Chat/chatModel"; import { ChatMessage, ChatMessageStatus } from "../../Model/Chat/chatModel";
import ChatViewModel from "./chatViewModel";
import MessagePageViewModel from "../Pages/messagePageViewModel"; import MessagePageViewModel from "../Pages/messagePageViewModel";
export default class ChatMessageViewModel { export default class ChatMessageViewModel {
+1 -1
View File
@@ -62,7 +62,7 @@ export default class ConnectionViewModel {
this.updatePreviousAddresses(); this.updatePreviousAddresses();
}; };
// view methods // view
showConnectionModal = (): void => { showConnectionModal = (): void => {
this.isShowingConnectionModal.value = true; this.isShowingConnectionModal.value = true;
}; };
+1 -1
View File
@@ -18,7 +18,7 @@ export default class SettingsViewModel {
this.usernameInput.value == this.settingsModel.username this.usernameInput.value == this.settingsModel.username
); );
// set // methods
setName = (): void => { setName = (): void => {
this.settingsModel.setName(this.usernameInput.value); this.settingsModel.setName(this.usernameInput.value);
this.username.value = this.settingsModel.username; this.username.value = this.settingsModel.username;
+1 -1
View File
@@ -35,7 +35,7 @@ export default class StorageViewModel {
this.didMakeChanges.value = true; this.didMakeChanges.value = true;
}; };
// view methods // view
showStorageModal = (): void => { showStorageModal = (): void => {
this.isShowingStorageModal.value = true; this.isShowingStorageModal.value = true;
}; };
@@ -33,7 +33,6 @@ export default class MessagePageViewModel {
} }
}; };
// messaging
sendMessage = (): void => { sendMessage = (): void => {
if (this.cannotSendMessage.value == true) return; if (this.cannotSendMessage.value == true) return;
+2 -2
View File
@@ -84,7 +84,7 @@ export default class SettingsPageViewModel {
}; };
// load // load
loadViewRelevantData = (): void => { loadListRelevantData = (): void => {
this.primaryChannel.value = this.primaryChannel.value =
this.chatViewModel.chatModel.info.primaryChannel; this.chatViewModel.chatModel.info.primaryChannel;
@@ -119,6 +119,6 @@ export default class SettingsPageViewModel {
// init // init
constructor(chatViewModel: ChatViewModel) { constructor(chatViewModel: ChatViewModel) {
this.chatViewModel = chatViewModel; this.chatViewModel = chatViewModel;
this.loadViewRelevantData(); this.loadListRelevantData();
} }
} }