Skip to content

Commit

Permalink
feat: store chats for 1 week (rather than 24 hours)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmtslmngcl committed Dec 12, 2024
1 parent f36b352 commit b26ead2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/operations/chatbot/Chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b26ead2

Please sign in to comment.