Commit f1ef057b authored by chenqikuai's avatar chenqikuai

fix: 修复删除消息时的bug

parent 58343dae
import { DisplayMessage, messageStore } from '@/store/messagesStore' import { DisplayMessage, messageStore } from '@/store/messagesStore'
import { getTargetIdFromDisplayMsg } from '@/utils/chatutils'
import { MyAppDatabase } from './index' import { MyAppDatabase } from './index'
export default class ChatMessageDB extends MyAppDatabase { export default class ChatMessageDB extends MyAppDatabase {
...@@ -30,9 +31,7 @@ export default class ChatMessageDB extends MyAppDatabase { ...@@ -30,9 +31,7 @@ export default class ChatMessageDB extends MyAppDatabase {
async deleteMsg({ uuid, logid }: { uuid?: string; logid?: string }) { async deleteMsg({ uuid, logid }: { uuid?: string; logid?: string }) {
const updateChatList = async (masterId: string, target: string) => { const updateChatList = async (masterId: string, target: string) => {
const latestedMsg = await this.chatMessage const latestedMsg = await this.getLatestedMessage(masterId, target)
.filter((i) => i.masterId === masterId && i.target == target)
.last()
if (latestedMsg) { if (latestedMsg) {
/* 如果和target还有聊天消息 */ /* 如果和target还有聊天消息 */
...@@ -49,16 +48,13 @@ export default class ChatMessageDB extends MyAppDatabase { ...@@ -49,16 +48,13 @@ export default class ChatMessageDB extends MyAppDatabase {
} }
if (uuid) { if (uuid) {
// console.log(uuid, 'uuid')
const item = await this.chatMessage.where('uuid').equals(uuid).first() const item = await this.chatMessage.where('uuid').equals(uuid).first()
// console.log(item, 'delted msg')
await this.chatMessage.where('uuid').equals(uuid).delete() 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) { } else if (logid) {
// console.log(logid, 'logid')
const item = await this.chatMessage.where('logid').equals(logid).first() const item = await this.chatMessage.where('logid').equals(logid).first()
await this.chatMessage.where('logid').equals(logid).delete() await this.chatMessage.where('logid').equals(logid).delete()
item && updateChatList(item?.masterId, item?.target as string) item && updateChatList(item?.masterId, getTargetIdFromDisplayMsg(item))
} else { } else {
throw new Error('没有uuid或者logid') throw new Error('没有uuid或者logid')
} }
...@@ -89,6 +85,30 @@ export default class ChatMessageDB extends MyAppDatabase { ...@@ -89,6 +85,30 @@ export default class ChatMessageDB extends MyAppDatabase {
.toArray() .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) { deleteMsgGroup(masterId: string, targetId: string) {
this.chatMessage this.chatMessage
.filter((item) => { .filter((item) => {
......
...@@ -12,11 +12,7 @@ ...@@ -12,11 +12,7 @@
<!-- 消息气泡 --> <!-- 消息气泡 -->
<div :class="[{ 'flex-row-reverse': fromMyself }]"> <div :class="[{ 'flex-row-reverse': fromMyself }]">
<div <div :class="{ 'text-right': fromMyself }" class="message_"></div>
:class="{ 'text-right': fromMyself }"
style="font-size: 12px;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #adadad;
"
></div>
<div <div
:class="[{ 'flex-row-reverse': fromMyself }]" :class="[{ 'flex-row-reverse': fromMyself }]"
class="flex items-center max-w-chat-msg-bubble" class="flex items-center max-w-chat-msg-bubble"
...@@ -202,3 +198,11 @@ export default defineComponent({ ...@@ -202,3 +198,11 @@ export default defineComponent({
}); });
</script> </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