xtekky / chatgpt-clone

ChatGPT interface with better UI
https://g4f.ai
GNU General Public License v3.0
3.43k stars 1.03k forks source link

Enable Previous Messages Deletion #106

Open ahmedosman2001 opened 1 year ago

ahmedosman2001 commented 1 year ago

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.

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