From b26ead2578d004a79d48d9b17f46d3bca99839fe Mon Sep 17 00:00:00 2001 From: ahmetselman Date: Thu, 12 Dec 2024 15:17:25 +0100 Subject: [PATCH] feat: store chats for 1 week (rather than 24 hours) --- src/operations/chatbot/Chatbot.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/operations/chatbot/Chatbot.ts b/src/operations/chatbot/Chatbot.ts index 28a3751c..c988ef58 100644 --- a/src/operations/chatbot/Chatbot.ts +++ b/src/operations/chatbot/Chatbot.ts @@ -23,14 +23,14 @@ export default class ChatbotOperations { if (storedData) { const parsedData = JSON.parse(storedData); const currentTime = Date.now(); - const oneDayAgo = currentTime - 24 * 60 * 60 * 1000; // Filter set for 24 hours + const oneWeekAgo = currentTime - 7 * 24 * 60 * 60 * 1000; // Filter set for 1 week - // Filter out chats older than 24 hours + // Filter out chats older than 1 Week const recentChats = parsedData.filter( - (chat: IChat & { timestamp?: number }) => !chat.timestamp || chat.timestamp > oneDayAgo + (chat: IChat & { timestamp?: number }) => !chat.timestamp || chat.timestamp > oneWeekAgo ); - // Clean up localStorage by saving only the chats that are not older than 24 hours + // Clean up localStorage by saving only the chats that are not older than 1 Week localStorage.setItem('chatbotChatsWithTimestamp', JSON.stringify(recentChats)); // If no recent chats, return default chat