From d668b7236d1f94bafe469dcfcc1c87f89b8f962e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Sat, 21 Oct 2023 19:16:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8DID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat.js | 7 +++++-- src/main.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chat.js b/src/chat.js index 3c160d9..0aaf93d 100644 --- a/src/chat.js +++ b/src/chat.js @@ -208,8 +208,11 @@ export default class Chat { ] })) } - 存储消息(data) { - set(data.id, data, this.store) + async 存储消息(data) { + // 检查id是否已经存在 + const item = await get(data.id, this.store) + if (item) return; + await set(data.id, data, this.store) } 发送消息(text) { const name = '我' diff --git a/src/main.js b/src/main.js index ad89dbb..4e39f6e 100644 --- a/src/main.js +++ b/src/main.js @@ -175,7 +175,7 @@ clientList.setChannel('chat', { } if (data.type === 'list') { console.log(client.name, `同步来 ${data.list.length} 条消息`) - chat.合并消息列表(data.list) + await chat.合并消息列表(data.list) return } console.log('未知类型:', data.type)