Commit f1ef057b authored by chenqikuai's avatar chenqikuai

fix: 修复删除消息时的bug

parent 58343dae
import { DisplayMessage, messageStore } from '@/store/messagesStore'
import { getTargetIdFromDisplayMsg } from '@/utils/chatutils'
import { MyAppDatabase } from './index'
export default class ChatMessageDB extends MyAppDatabase {
......@@ -30,9 +31,7 @@ export default class ChatMessageDB extends MyAppDatabase {
async deleteMsg({ uuid, logid }: { uuid?: string; logid?: string }) {
const updateChatList = async (masterId: string, target: string) => {
const latestedMsg = await this.chatMessage
.filter((i) => i.masterId === masterId && i.target == target)
.last()
const latestedMsg = await this.getLatestedMessage(masterId, target)
if (latestedMsg) {
/* 如果和target还有聊天消息 */
......@@ -49,16 +48,13 @@ export default class ChatMessageDB extends MyAppDatabase {
}
if (uuid) {
// console.log(uuid, 'uuid')
const item = await this.chatMessage.where('uuid').equals(uuid).first()
// console.log(item, 'delted msg')
await this.chatMessage.where('uuid').equals(uuid).delete()
item && updateChatList(item?.masterId, item?.target as string)
item && updateChatList(item?.masterId, getTargetIdFromDisplayMsg(item))
} else if (logid) {
// console.log(logid, 'logid')
const item = await this.chatMessage.where('logid').equals(logid).first()
await this.chatMessage.where('logid').equals(logid).delete()
item && updateChatList(item?.masterId, item?.target as string)
item && updateChatList(item?.masterId, getTargetIdFromDisplayMsg(item))
} else {
throw new Error('没有uuid或者logid')
}
......@@ -89,6 +85,30 @@ export default class ChatMessageDB extends MyAppDatabase {
.toArray()
}
/* wo获取和ta之间最新的消息 */
async getLatestedMessage(from: string, target: string) {
const ret = await this.chatMessage
.filter((item) => {
return (
item.masterId === from &&
((item.state === null && target === item.from) ||
(item.state !== null && target === item.target))
)
})
.count()
console.log(ret, 'show count')
return this.chatMessage
.filter((item) => {
return (
item.masterId === from &&
((item.state === null && target === item.from) ||
(item.state !== null && target === item.target))
)
})
.last()
}
deleteMsgGroup(masterId: string, targetId: string) {
this.chatMessage
.filter((item) => {
......
......@@ -12,11 +12,7 @@
<!-- 消息气泡 -->
<div :class="[{ 'flex-row-reverse': fromMyself }]">
<div
:class="{ 'text-right': fromMyself }"
style="font-size: 12px;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #adadad;
"
></div>
<div :class="{ 'text-right': fromMyself }" class="message_"></div>
<div
:class="[{ 'flex-row-reverse': fromMyself }]"
class="flex items-center max-w-chat-msg-bubble"
......@@ -202,3 +198,11 @@ export default defineComponent({
});
</script>
<style scoped>
.message_ {
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
color: #adadad;
font-weight: 400;
}
</style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment