From 63971d66fcb90a4ff2d4ef360ee2e296ebafc544 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Tue, 1 Oct 2024 10:50:19 +0200 Subject: [PATCH] chat history added (backend testing) --- app/backend/ChatHistory.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/backend/ChatHistory.ts diff --git a/app/backend/ChatHistory.ts b/app/backend/ChatHistory.ts new file mode 100644 index 0000000..f050898 --- /dev/null +++ b/app/backend/ChatHistory.ts @@ -0,0 +1,27 @@ +type ChatMessage = { + name: string; + message: any; + timestamp: number; +}; + +let chatHistory: ChatMessage[] = []; + +function addMessage(name: string, message: any): void { + const newMessage: ChatMessage = { + name: name, + message: message, + timestamp: Date.now() + }; + chatHistory.push(newMessage); + console.log(`Added message from ${name}: ${message}`); +} + +function removeMessage(timestamp: number): void { + const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp); + if (index > -1) { + chatHistory.splice(index, 1); + console.log(`Removed message with timestamp: ${timestamp}`); + } else { + console.log(`Message not found with timestamp: ${timestamp}`); + } +}