fix: mention count

This commit is contained in:
zerosoul
2022-04-14 21:34:11 +08:00
parent 36fa83fd88
commit cb3efa78fd
2 changed files with 22 additions and 5 deletions
+6 -1
View File
@@ -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 };
});
+16 -4
View File
@@ -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;