Delete and Update History

This commit is contained in:
n4ze3m
2024-02-24 00:39:50 +05:30
parent 1c980c4059
commit f87953ba5c
7 changed files with 172 additions and 17 deletions

View File

@@ -87,6 +87,10 @@ export class PageAssitDatabase {
}
this.db.remove("chatHistories")
}
async deleteMessage(history_id: string) {
await this.db.remove(history_id)
}
}
const generateID = () => {
@@ -145,3 +149,22 @@ export const formatToMessage = (messages: MessageHistory): MessageType[] => {
}
})
}
export const deleteByHistoryId = async (history_id: string) => {
const db = new PageAssitDatabase()
await db.deleteMessage(history_id)
await db.removeChatHistory(history_id)
return history_id
}
export const updateHistory = async (id: string, title: string) => {
const db = new PageAssitDatabase()
const chatHistories = await db.getChatHistories()
const newChatHistories = chatHistories.map((history) => {
if (history.id === id) {
history.title = title
}
return history
})
db.db.set({ chatHistories: newChatHistories })
}