@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 latest = await Message.findOne({ _id: { $in: counted.map((doc) => doc._id) } }, null, { sort: { createdAt: -1 } }).lean();
197
- const unread = counted.filter((doc) => !doc.from_me && doc.read !== true).length;
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 } }] },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.0.23",
3
+ "version": "6.0.24",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",