chatgpt-clone icon indicating copy to clipboard operation
chatgpt-clone copied to clipboard

Enable Previous Messages Deletion

Open ahmedosman2001 opened this issue 2 years ago • 1 comments

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.

ahmedosman2001 avatar Jun 09 '23 12:06 ahmedosman2001

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;
};

vossr avatar Jun 11 '23 19:06 vossr