@peopl-health/nexus 6.0.23 → 6.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -193,8 +193,10 @@ async function moveThreads(source, target, state, migrationId) {
|
|
|
193
193
|
async function countMovedMessages(target, messages) {
|
|
194
194
|
const counted = messages.filter((doc) => !INTERNAL_ORIGINS.has(doc.origin));
|
|
195
195
|
if (!counted.length) return;
|
|
196
|
-
const
|
|
197
|
-
const
|
|
196
|
+
const ids = counted.map((doc) => doc._id);
|
|
197
|
+
const latest = await Message.findOne({ _id: { $in: ids } }, null, { sort: { createdAt: -1 } }).lean();
|
|
198
|
+
// Staff can mark the chat read mid-move, so count what is stored now, not the snapshot.
|
|
199
|
+
const unread = await Message.countDocuments({ _id: { $in: ids }, from_me: false, read: { $ne: true } });
|
|
198
200
|
await Thread.updateOne({ code: target }, { $inc: { messageCount: counted.length, unreadCount: unread } });
|
|
199
201
|
await Thread.updateOne(
|
|
200
202
|
{ code: target, $or: [{ lastMessageAt: null }, { lastMessageAt: { $lt: latest.createdAt } }] },
|