Open ahmedosman2001 opened 1 year ago
const get_conversation = async (conversation_id) => {
let conversation = await JSON.parse(
localStorage.getItem(`conversation:${conversation_id}`)
);
conversation.items = conversation.items.map(message => {
const { token, ...messageWithoutToken } = message;
return messageWithoutToken;
});
return conversation.items;
};
This allows users to delete previous messages from the UI and local storage. The function takes a message's token as an argument, identifies the corresponding message elements in the UI, and removes them. It also updates the conversation object in local storage by filtering out the deleted message. If there are no messages left, the conversation is deleted from the sidebar. All this happen without user refreshing the page.