From cb3efa78fde615f3c0e72dbdf6a30000a2138bc9 Mon Sep 17 00:00:00 2001 From: zerosoul Date: Thu, 14 Apr 2022 21:34:11 +0800 Subject: [PATCH] fix: mention count --- src/routes/chat/DMList/index.js | 7 ++++++- src/routes/chat/utils.js | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/routes/chat/DMList/index.js b/src/routes/chat/DMList/index.js index d72fe4de..7f6ddf23 100644 --- a/src/routes/chat/DMList/index.js +++ b/src/routes/chat/DMList/index.js @@ -23,7 +23,12 @@ export default function DMList({ uids, setDropFiles }) { } const lastMid = [...mids].pop(); const readIndex = readUsers[uid]; - const unreads = getUnreadCount({ mids, readIndex, messageData, loginUid }); + const { unreads = 0 } = getUnreadCount({ + mids, + readIndex, + messageData, + loginUid, + }); return { lastMid, unreads, uid }; }); diff --git a/src/routes/chat/utils.js b/src/routes/chat/utils.js index 09c5a427..e88f0889 100644 --- a/src/routes/chat/utils.js +++ b/src/routes/chat/utils.js @@ -28,13 +28,25 @@ export function getUnreadCount({ const { from_uid = 0 } = messageData[mid] || {}; return messageData[mid] && from_uid != loginUid; }); - if (others.length == 0) return 0; - if (readIndex == 0) return others.length; - // 再过滤掉大于read-index, + if (others.length == 0) return { unreads: 0 }; + if (readIndex == 0) return { unreads: others.length }; + // 再过滤掉小于read-index, const final = others.filter((mid) => { return mid > readIndex; }); - return final.length; + // 拿at数量 + const tmps = []; + final.forEach((mid) => { + const msg = messageData[mid]; + const { mentions = [] } = msg.properties || {}; + mentions.forEach((id) => { + if (id == loginUid) { + tmps.push(mid); + } + }); + }); + console.log("unreads", final.length, tmps); + return { unreads: final.length, mentions: tmps }; } export const renderPreviewMessage = (message = null) => { if (!message) return null;